🌿 ng2-branchy
https://github.com/valor-software/ng2-tree and got new name: ng2-tree
. Thanks and see you there :)
Hello guys! This project has moved to ng2-branchy is a simple Angular 2 component for visualizing data that can be naturally represented as a tree.
🎬 Usage
Ok, let's start with an installation - all you need to do is:
npm install --save ng2-branchy
Now when you have branchy installed you need to add it to your component's template and to the list of its directives:
// 1 - import required classes and interfaces;
As soon as the previous step is done we need to give branchy a model to render - this can be accomplished by populating its [tree]
attribute with an object that confirms to TreeModel
interface (see API):
// 1 - import required classes and interfaces;
Apart from that I suppose you'd want to listen for branchy's events (for a full list of supported events look at API). No problem, this is also easy to do - for example let's add a listener for node was selected
events:
// 1 - import required classes and interfaces;
Voila! That's pretty much it - enjoy 😊
👀 Demo
Feel free to examine the demo and its sources to find out how things are wired.
🔧 API
Here is the fully stuffed branchy tag that you can use in your templates:
Let's go through every element of this structure one by one.
branchy
branchy
is the selector for BranchyComponent
which you can import like shown below:
;
[tree]
branchy
has [tree]
attribute which need to be populated with an object implementing TreeModel
interface. You can import this interface as following
;
Here is the definition of TreeModel interface:
As you can see it is recursive and can be represented as the following object:
Property value
can be of type string
or RenamableNode
.
RenamableNode
gives you additional control over the way node is renamed and rendered (by rendered I mean its text representation). Here is the definition of RenamableNode
interface:
Here is an example of such a node in the TreeModel
object:
;
events (nodeMoved, nodeSelected, nodeRenamed, nodeRemoved, nodeCreated)
Here is the diagram that shows branchy events' hierarchy
NodeEvent
is the root of branchy events' hierarchy. It defines property node
that contains a receiver of the event's action (node
confirms to TreeModel
).
NodeDestructiveEvent
is the parent for all events that cause changes to a structure of the tree or to a node value.
It defines property 'parent' that contains an object implementing 'TreeModel' interface and gives context to the event's action.
NodeSelectedEvent
You can subscribe to NodeSelectedEvent
by attaching listener to (nodeSelected)
attribute
NodeSelectedEvent
has just one property node
which contains TreeModel
object of a selected node.
NodeSelectedEvent
inherits its property directly from NodeEvent
.
NodeMovedEvent
You can subscribe to NodeMovedEvent
by attaching listener to (nodeMoved)
attribute
NodeMovedEvent
has two properties node
and parent
both of which contain TreeModel
objects.
node
contains moved node.
parent
contains new parent of the moved node.
NodeMovedEvent
inherits its properties from NodeDestructiveEvent
.
NodeRemovedEvent
You can subscribe to NodeRemovedEvent
by attaching listener to (nodeRemoved)
attribute
NodeRemovedEvent
has two properties node
and parent
both of which contain TreeModel
objects.
node
contains removed node.
parent
contains parent of the removed node.
NodeRemovedEvent
inherits its properties from NodeDestructiveEvent
.
NodeCreatedEvent
You can subscribe to NodeCreatedEvent
by attaching listener to (nodeCreated)
attribute
NodeCreatedEvent
has two properties node
and parent
both of which contain TreeModel
objects.
node
contains created node.
parent
contains parent of the newly created node.
NodeCreatedEvent
inherits its properties from NodeDestructiveEvent
.
NodeRenamedEvent
You can subscribe to NodeRenamedEvent
by attaching listener to (nodeRenamed)
attribute
NodeRenamedEvent
has four properties:
node
contains node that was renamed (implementsTreeModel
).parent
contains parent (implementsTreeModel
) for the renamed node.oldValue
contains value node used to have (it might bestring
orRenamableNode
)newValue
contains new value of the node (it might bestring
orRenamableNode
)
NodeRenamedEvent
inherits its node
and parent
properties from NodeDestructiveEvent
.
👎 Bad parts
Currently I feel really bad because of two things:
- branchy doesn't have tests (yet), so I wouldn't recommend you to use this in a production environment
- branchy doesn't have proper mechanism for customizing its look
👍 Good parts
I really want to deminish all the Bad parts and extend branchy with a new stuff
💡 Want to help?
I am very appreciate for your ideas, proposals and found bugs which you can leave in github issues. Thanks in advance!
P.S. If you find it hard going through documentation, please, let me know which parts of it was difficult to grasp and I will improve them.