Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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