GraphLinksModel class
GraphLinksModels support links between nodes and grouping nodes and links into subgraphs. GraphLinksModels hold node data and link data in separate arrays. Node data is normally represented in a Diagram by instances of Node, but they could be represented by simple Parts or by Groups. Link data should be represented by instances of Link.
Each link data object is assumed to have two values, one referring to the node that the link is coming from and one that the link is going to. The #linkFromKeyProperty property names the property on the link data whose value is the key of the "from" node. The #linkToKeyProperty property names the property on the link data whose value is the key of the "to" node. The default values for these properties are "from" and "to" respectively.
For example, one can define a graph consisting of two nodes with one link connecting them:
model.nodeDataArray = [
{ key: "Alpha" },
{ key: "Beta" }
];
model.linkDataArray = [
{ from: "Alpha", to: "Beta" }
];
If you want to have subgraphs in your diagram, where a group node contains some number of nodes and links, you need to declare that some node data actually represent groups, and you need to provide a reference from a member node data to its containing group node data. The #nodeIsGroupProperty property names the property on a node data that is true if that node data represents a group. The #nodeGroupKeyProperty property names the property on a node data whose value is the key of the containing group's node data. The default values for these properties are "isGroup" and "group" respectively.
For example, one can define a graph consisting of one group containing a subgraph of two nodes connected by a link, with a second link from that group to a third node that is not a member of that group:
model.nodeDataArray = [
{ key: "Group1", isGroup: true},
{ key: "Alpha", group: "Group1" },
{ key: "Beta", group: "Group1" },
{ key: "Gamma" }
];
model.linkDataArray = [
{ from: "Alpha", to: "Beta" },
{ from: "Group1", to: "Gamma" }
];
GraphLinksModels also support distinguishing the "port" element of a node to which a link can connect, at either end of the link. This identification is a string that names the "port" element in the node. However, you need to set the #linkFromPortIdProperty and/or #linkToPortIdProperty properties before the model is able to get the "port id" information from the link data.
For example, one can define a graph consisting of a "subtraction" node and two inputs and one output. The "subtraction" node has two distinct inputs called "subtrahend" and "minuend"; the output is called "difference".
model.linkFromPortIdProperty = "fromPort"; // necessary to remember portIds
model.linkToPortIdProperty = "toPort";
model.nodeDataArray = [
{ key: 1, constant: 5 }, // a constant input node
{ key: 2, constant: 2 }, // another constant node
{ key: 3, operation: "subtract" },
{ key: 4, value: 3 } // the output node
];
model.linkDataArray = [
{ from: 1, to: 3, toPort: "subtrahend" },
{ from: 2, to: 3, toPort: "minuend" },
{ from: 3, to: 4, fromPort: "difference" }
];
In this case links connected to node 3 (which is the subtraction operation) are distinguished by port id. The connections to the other nodes do not have any port identification, presumably because there is only one port on those nodes, representing the node value.
Note that there is no requirement that the link data objects have any kind of unique identifier, unlike for node data. There is no expectation that there be references to link data in the model, so there is no need for such an identifier. When there are multiple links connecting two ports, the only way to distinguish the links in the model is by reference to the particular link data object. This is why there are two methods on the Diagram class for Nodes, Diagram#findNodeForKey and Diagram#findNodeForData, but there is only the one method for Links, Diagram#findLinkForData.
However you may wish to have the model maintain string or number identifiers on the link data just as all models do for node data. To get that behavior, so that you can call #findLinkDataForKey, you need to set #linkKeyProperty to be a non-empty string. Just as with the assignment of node keys, you can customize the assignment of link keys by setting #makeUniqueLinkKeyFunction to a function that returns a unique identifier.
This model does not support the modification of whether a node data object is a group.
This model cannot detect the modification of the #linkDataArray array or the modification of any link data object. If you want to add or remove link data from the #linkDataArray, call the #addLinkData or #removeLinkData methods. If you want to modify the node a link connects to, call the #setFromKeyForLinkData and/or #setToKeyForLinkData methods. If you want to change the membership of a node data in a group, call the #setGroupKeyForNodeData method.
- Implemented types
- Available extensions
- Annotations
-
- @JS()
- @staticInterop
Constructors
- GraphLinksModel.$1()
-
factory
- GraphLinksModel.$2([dynamic init])
-
factory
-
GraphLinksModel.$3([Array<
Object> ? nodedataarray, Array<Object> ? linkdataarray, dynamic init]) -
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited