Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heavy Flickering and Shifting with d3-Simulation #154

Open
Gykonik opened this issue Jun 15, 2023 · 0 comments
Open

Heavy Flickering and Shifting with d3-Simulation #154

Gykonik opened this issue Jun 15, 2023 · 0 comments

Comments

@Gykonik
Copy link

Gykonik commented Jun 15, 2023

O have included a d3-simulation in my NetV-Chart. The graph is relatively large (4k nodes, 50k edges) and the simulation runs 130 times. However, I have optimized it to only re-rendered after every 5th run.

However, there is still quite a lot of flickering and the position regularly shifts to the top left corner - instead of the center.
Do you happen to know what the reason for this is?

In the following you can see an excerpt of how I create it and apply the force simulation.

const container: any = document.getElementById('graph-container');
const width = container.scrollWidth;
const height = container.scrollHeight || 500;

this.graph = new NetV({
  container: container,
  width: width,
  height: height,
  node: {},
  link: {},
  nodeLimit: 5000,
  linkLimit: 50000
})

this.graph.data(this.inputGraph);
this.graph.draw();

this.graph.on('zoom', () => {})
this.graph.on('pan', () => {})

this.simulation = forceSimulation(this.inputGraph.nodes)
  .alpha(1)
  .alphaMin(0.05)
  .velocityDecay(0.5)
  .force("link", forceLink(this.inputGraph.links))
  .force("charge", forceManyBody().strength(-0.5))
  .force("center", forceCenter().strength(2));

this.simulation.on("tick", () => {
  console.log("tick");
  this.iteration++;
  this.inputGraph.nodes.forEach((n: any) => {
	const node = this.graph.getNodeById(n.id)
	node.x(n.x)
	node.y(n.y)
  })
  if (this.iteration % this.STEP_SIZE == 0) {
	this.graph.draw()
  }
});

this.simulation.on("end", () => {
  console.log("finished");
  // this.graph.draw()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant