Skip to content

Commit

Permalink
remove manual tick (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
princiya authored and jonathanKingston committed Feb 17, 2018
1 parent ec81ff8 commit f24de1c
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/js/viz.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const viz = {
chargeStrength: -100,
tickCount: 100,
canvasColor: 'white',
alphaStart: 1,
alphaTargetStart: 0.1,
alphaTargetStop: 0,

Expand Down Expand Up @@ -47,28 +48,33 @@ const viz = {
this.registerSimulationForces();
} else {
this.simulation.nodes(this.nodes);
this.resetAlpha();
}
this.registerLinkForce();
this.manualTick();
},

manualTick() {
this.simulation.alphaTarget(this.alphaTargetStart);
for (let i = 0; i < this.tickCount; i++) {
this.simulation.tick();
resetAlpha() {
const alpha = this.simulation.alpha();
const alphaRounded = Math.round((1 - alpha) * 100);
if (alphaRounded === 100) {
this.simulation.alpha(this.alphaStart);
this.restartSimulation();
}
this.stopSimulation();
},

restartSimulation() {
resetAlphaTarget() {
this.simulation.alphaTarget(this.alphaTargetStart);
this.simulation.restart();
this.restartSimulation();
},

stopSimulation() {
stopAlphaTarget() {
this.simulation.alphaTarget(this.alphaTargetStop);
},

restartSimulation() {
this.simulation.restart();
},

registerLinkForce() {
const linkForce = d3.forceLink(this.links);
linkForce.id((d) => {
Expand Down Expand Up @@ -403,7 +409,7 @@ const viz = {

dragStart() {
if (!d3.event.active) {
this.restartSimulation();
this.resetAlphaTarget();
}
d3.event.subject.shadow = true;
d3.event.subject.fx = d3.event.subject.x;
Expand All @@ -419,7 +425,7 @@ const viz = {

dragEnd() {
if (!d3.event.active) {
this.stopSimulation();
this.stopAlphaTarget();
}
d3.event.subject.x = d3.event.subject.fx;
d3.event.subject.y = d3.event.subject.fy;
Expand Down

0 comments on commit f24de1c

Please sign in to comment.