in src/visual.ts [569:623]
public update(options: VisualUpdateOptions): void {
if (!options
|| !options.dataViews
|| !options.dataViews[0]
) {
return;
}
this.data = ForceGraph.converter(
options.dataViews[0],
this.colorPalette,
this.colorHelper,
this.host
);
if (!this.data) {
this.reset();
return;
}
this.viewport = options.viewport;
let k: number = Math.sqrt(Object.keys(this.data.nodes).length /
(this.viewport.width * this.viewport.height));
this.reset();
this.forceLayout
.gravity(ForceGraph.GravityFactor * k)
.links(this.data.links)
.size([this.viewport.width, this.viewport.height])
.linkDistance(ForceGraph.LinkDistance)
.charge(this.settings.size.charge / k);
this.updateNodes();
let nodesNum: number = Object.keys(this.data.nodes).length;
const theta: number = 1.4;
if (this.settings.animation.show && nodesNum <= ForceGraph.NoAnimationLimit) {
this.forceLayout.on("tick", this.getForceTick());
this.forceLayout.theta(theta).start();
this.setVisualData(this.container, this.colorPalette, this.colorHelper);
} else {
this.forceLayout.theta(theta).start();
for (let i = 0; i < nodesNum; ++i) {
this.forceLayout.tick();
}
this.forceLayout.stop();
this.setVisualData(this.container, this.colorPalette, this.colorHelper);
this.forceLayout.on("tick", this.getForceTick());
}
}