20 |
20 |
const canvasSize = ((data.vertices.length * 75) / Math.round(Math.sqrt(data.vertices.length))) + 1000;
|
21 |
21 |
|
22 |
22 |
// store archetypes
|
23 |
|
app.archetype.vertex = data.vertexArchetypes;
|
24 |
|
app.archetype.edge = data.edgeArchetypes;
|
|
23 |
app.archetype.vertex = Utils.isDefined(data.vertexArchetypes) ? data.vertexArchetypes : [];
|
|
24 |
app.archetype.edge = Utils.isDefined(data.edgeArchetypes) ? data.edgeArchetypes : [];
|
25 |
25 |
|
26 |
|
app.attributeTypeList = data.attributeTypes;
|
27 |
|
app.possibleEnumValues = data.possibleEnumValues;
|
|
26 |
app.attributeTypeList = Utils.isDefined(data.attributeTypes) ? data.attributeTypes : [];
|
|
27 |
app.possibleEnumValues = Utils.isDefined(data.possibleEnumValues) ? data.possibleEnumValues : {};
|
28 |
28 |
|
29 |
29 |
app.archetype.vertex.filter(vertexArchetype => {
|
30 |
30 |
return Utils.isDefined(vertexArchetype.icon);
|
... | ... | |
49 |
49 |
highlightedEdgeId = parseInt(data.highlightedEdge, 10);
|
50 |
50 |
}
|
51 |
51 |
|
52 |
|
let highlightedNode = undefined;
|
53 |
|
let highlightedEdge = undefined;
|
|
52 |
let highlightedNode;
|
|
53 |
let highlightedEdge;
|
54 |
54 |
|
55 |
55 |
// construct vertices
|
56 |
56 |
let vertexMap = new Map;
|
... | ... | |
121 |
121 |
});
|
122 |
122 |
|
123 |
123 |
// construct groups
|
124 |
|
data.groups.forEach(component => {
|
125 |
|
let group = new Group(component);
|
|
124 |
if (Utils.isDefined(data.groups)) {
|
|
125 |
data.groups.forEach(component => {
|
|
126 |
let group = new Group(component);
|
126 |
127 |
|
127 |
|
if (highlightedNodeType === 'group' && highlightedNodeId === group.id) {
|
128 |
|
highlightedNode = group;
|
129 |
|
}
|
|
128 |
if (highlightedNodeType === 'group' && highlightedNodeId === group.id) {
|
|
129 |
highlightedNode = group;
|
|
130 |
}
|
130 |
131 |
|
131 |
|
// position
|
132 |
|
if (component.position === null || Utils.isUndefined(component.position)) {
|
133 |
|
// set random
|
134 |
|
group.position = new Coordinates(
|
135 |
|
Math.floor(Math.random() * canvasSize),
|
136 |
|
Math.floor(Math.random() * canvasSize),
|
137 |
|
);
|
138 |
|
} else {
|
139 |
|
group.position = new Coordinates(component.position.x, component.position.y);
|
140 |
|
}
|
|
132 |
// position
|
|
133 |
if (component.position === null || Utils.isUndefined(component.position)) {
|
|
134 |
// set random
|
|
135 |
group.position = new Coordinates(
|
|
136 |
Math.floor(Math.random() * canvasSize),
|
|
137 |
Math.floor(Math.random() * canvasSize),
|
|
138 |
);
|
|
139 |
} else {
|
|
140 |
group.position = new Coordinates(component.position.x, component.position.y);
|
|
141 |
}
|
141 |
142 |
|
142 |
|
// vertices
|
143 |
|
app.vertexList.filter(vertex => {
|
144 |
|
return component.verticesId.indexOf(vertex.id) > -1;
|
145 |
|
}).forEach(vertex => {
|
146 |
|
group.addVertex(vertex);
|
147 |
|
});
|
|
143 |
// vertices
|
|
144 |
app.vertexList.filter(vertex => {
|
|
145 |
return component.verticesId.indexOf(vertex.id) > -1;
|
|
146 |
}).forEach(vertex => {
|
|
147 |
group.addVertex(vertex);
|
|
148 |
});
|
148 |
149 |
|
149 |
|
app.nodeList.push(group);
|
150 |
|
app.groupList.push(group);
|
|
150 |
app.nodeList.push(group);
|
|
151 |
app.groupList.push(group);
|
151 |
152 |
|
152 |
|
app.viewportComponent.addNode(group);
|
153 |
|
});
|
|
153 |
app.viewportComponent.addNode(group);
|
|
154 |
});
|
|
155 |
}
|
154 |
156 |
|
155 |
157 |
// exclude nodes
|
156 |
|
data.sideBar.forEach(excludedNode => {
|
157 |
|
if (typeof excludedNode.id !== 'string' && !(excludedNode.id instanceof String)) return;
|
|
158 |
if (Utils.isDefined(data.sideBar)) {
|
|
159 |
data.sideBar.forEach(excludedNode => {
|
|
160 |
if (typeof excludedNode.id !== 'string' && !(excludedNode.id instanceof String)) return;
|
158 |
161 |
|
159 |
|
let idArr = excludedNode.id.split('-');
|
160 |
|
if (idArr.length !== 2) return;
|
|
162 |
let idArr = excludedNode.id.split('-');
|
|
163 |
if (idArr.length !== 2) return;
|
161 |
164 |
|
162 |
|
idArr[1] = parseInt(idArr[1], 10);
|
|
165 |
idArr[1] = parseInt(idArr[1], 10);
|
163 |
166 |
|
164 |
|
let node = app.nodeList.find(node => {
|
165 |
|
let prefix = '';
|
166 |
|
if (node instanceof Vertex) {
|
167 |
|
prefix = 'vertex';
|
168 |
|
} else if (node instanceof Group) {
|
169 |
|
prefix = 'group';
|
170 |
|
}
|
|
167 |
let node = app.nodeList.find(node => {
|
|
168 |
let prefix = '';
|
|
169 |
if (node instanceof Vertex) {
|
|
170 |
prefix = 'vertex';
|
|
171 |
} else if (node instanceof Group) {
|
|
172 |
prefix = 'group';
|
|
173 |
}
|
171 |
174 |
|
172 |
|
return idArr[0] === prefix && node.id === idArr[1];
|
173 |
|
});
|
|
175 |
return idArr[0] === prefix && node.id === idArr[1];
|
|
176 |
});
|
174 |
177 |
|
175 |
|
if (Utils.isDefined(node)) {
|
176 |
|
node.exclude();
|
|
178 |
if (Utils.isDefined(node)) {
|
|
179 |
node.exclude();
|
177 |
180 |
|
178 |
|
app.sidebarComponent.excludedNodeListComponent.addNode(node);
|
179 |
|
}
|
180 |
|
});
|
|
181 |
app.sidebarComponent.excludedNodeListComponent.addNode(node);
|
|
182 |
}
|
|
183 |
});
|
|
184 |
}
|
181 |
185 |
|
182 |
186 |
// center viewport
|
183 |
187 |
app.viewportComponent.center();
|
re #10: only "vertices" and "edges" arrays are required in input data