in showcases/graph/graph-layer/layout/layout-d3.js [19:85]
update(data, layoutProps) {
const {alphaOnDataChange, alphaOnDrag} = this.props;
if (this._simulation && data) {
// If new data are passed, update the simulation with the new data
this._simulation
.nodes(data.nodes)
.force(
'link',
forceLink(data.links)
.id(n => n.id)
.strength(this.props.linkStrength)
.distance(this.props.linkDistance)
)
.alpha(alphaOnDataChange);
} else if (!this._simulation) {
if (data) {
// Instantiate the simulation with the passed data
const {nBodyStrength, nBodyDistanceMin, nBodyDistanceMax} = this.props;
this._simulation = forceSimulation(data.nodes)
.force(
'link',
forceLink(data.links)
.id(n => n.id)
.strength(this.props.linkStrength)
.distance(this.props.linkDistance)
)
.force(
'charge',
forceManyBody()
.strength(nBodyStrength)
.distanceMin(nBodyDistanceMin)
.distanceMax(nBodyDistanceMax)
)
.force('center', forceCenter())
.stop();
} else {
// No data passed and simulation has not yet been instantiated,
// so return empty object.
return {
nodes: [],
isUpdating: false
};
}
}
const {fixedNodes, unfixedNodes} = layoutProps;
if (fixedNodes) {
fixedNodes.forEach(n => {
n.node.fx = n.x;
n.node.fy = n.y;
});
this._reheat(alphaOnDrag);
}
if (unfixedNodes) {
unfixedNodes.forEach(n => {
n.node.fx = null;
n.node.fy = null;
});
}
// Process one simulation tick and return results.
this._simulation.tick();
return {
nodes: this._simulation.nodes(),
isUpdating: this.isUpdating()
};
}