I'm trying to create a graph with the ngx-graph library(I'm new with it).I'm trying to create nodes and edges in a dynamic way. I get the info from a service and I push these data into two separate array(Nodes and Edges). Thw problem is the data are pushed properly but my graphic create nodes and edges in the same position.(x=0 and y=0). I tried also to force the position but don't change.
<ngx-graph *ngIf="nodes.length > 0 && links.length > 0 && !loading"
layout="dagre"
[view]="[800,500]"
[links]="links"
[nodes]="nodes">
</ngx-graph>
And in my .ts component I add the nodes and edge:
createGraph() {
this.nodes = [];
this.links = [];
if (this.items) {
this.nodes.push({
id: this.items.id,
label: this.items.description
});
if (this.items.motivations) {
let i = 0;
for (let motivation of this.items.motivations) {
++i;
this.nodes.push({
id: motivation .id,
label: motivation .description
});
this.links.push({
id: motivation .id,
source: this.nodes[0].id,
target: motivation .id
});
}
}
this.loading = false;
}
}
And at the end I always this error in console
ERROR TypeError: Cannot read property 'dimension' of undefined at swimlane-ngx-graph.js:2016 at Array.map () at QueryList.push../node_modules/@angular/core/fesm5/core.js.QueryList.map (core.js:5412) at GraphComponent.push../node_modules/@swimlane/ngx-graph/fesm5/swimlane-ngx-graph.js.GraphComponent.applyNodeDimensions (swimlane-ngx-graph.js:1988) at GraphComponent.push../node_modules/@swimlane/ngx-graph/fesm5/swimlane-ngx-graph.js.GraphComponent.draw (swimlane-ngx-graph.js:1796) at swimlane-ngx-graph.js:1768 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:4053) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)