New items can be added programmatically to the diagram by calling the constructors of the item's class, such as ShapeNode or DiagramLink, and adding the new instance via the addItem method. A shortcut to creating new items is provided by the methods of the Factory class. An instance of that class is returned by the factory property of Diagram. Factory methods such as createShapeNode and createDiagramLink accept respectively node position or link's origin and destination arguments, create an instance of the class and add it to the diagram. The Factory class can create instances of JsDiagram predefined item types, while addItem can be used to add instances of custom types as well.
JavaScript Copy Code |
---|
var ShapeNode = MindFusion.Diagramming.ShapeNode; |
If an existing item should be removed from the diagram, call the removeItem method. If a node is removed, any links connected to the node are removed too.