|
|
@ -2,12 +2,12 @@ |
|
|
|
* Created by Alex on 2/23/2015. |
|
|
|
*/ |
|
|
|
|
|
|
|
import BarnesHutSolver from "./components/physics/BarnesHutSolver"; |
|
|
|
import Repulsion from "./components/physics/RepulsionSolver"; |
|
|
|
import HierarchicalRepulsion from "./components/physics/HierarchicalRepulsionSolver"; |
|
|
|
import SpringSolver from "./components/physics/SpringSolver"; |
|
|
|
import HierarchicalSpringSolver from "./components/physics/HierarchicalSpringSolver"; |
|
|
|
import CentralGravitySolver from "./components/physics/CentralGravitySolver"; |
|
|
|
import BarnesHutSolver from './components/physics/BarnesHutSolver'; |
|
|
|
import Repulsion from './components/physics/RepulsionSolver'; |
|
|
|
import HierarchicalRepulsion from './components/physics/HierarchicalRepulsionSolver'; |
|
|
|
import SpringSolver from './components/physics/SpringSolver'; |
|
|
|
import HierarchicalSpringSolver from './components/physics/HierarchicalSpringSolver'; |
|
|
|
import CentralGravitySolver from './components/physics/CentralGravitySolver'; |
|
|
|
|
|
|
|
var util = require('../../util'); |
|
|
|
|
|
|
@ -67,23 +67,23 @@ class PhysicsEngine { |
|
|
|
} |
|
|
|
util.extend(this.options, this.defaultOptions); |
|
|
|
|
|
|
|
this.body.emitter.on("initPhysics", () => {this.initPhysics();}); |
|
|
|
this.body.emitter.on("resetPhysics", () => {this.stopSimulation(); this.ready = false;}); |
|
|
|
this.body.emitter.on("disablePhysics", () => {this.physicsEnabled = false; this.stopSimulation();}); |
|
|
|
this.body.emitter.on("restorePhysics", () => { |
|
|
|
this.body.emitter.on('initPhysics', () => {this.initPhysics();}); |
|
|
|
this.body.emitter.on('resetPhysics', () => {this.stopSimulation(); this.ready = false;}); |
|
|
|
this.body.emitter.on('disablePhysics', () => {this.physicsEnabled = false; this.stopSimulation();}); |
|
|
|
this.body.emitter.on('restorePhysics', () => { |
|
|
|
this.setOptions(this.options); |
|
|
|
if (this.ready === true) { |
|
|
|
this.stabilized = false; |
|
|
|
this.runSimulation(); |
|
|
|
} |
|
|
|
}); |
|
|
|
this.body.emitter.on("startSimulation", () => { |
|
|
|
this.body.emitter.on('startSimulation', () => { |
|
|
|
if (this.ready === true) { |
|
|
|
this.stabilized = false; |
|
|
|
this.runSimulation(); |
|
|
|
} |
|
|
|
}) |
|
|
|
this.body.emitter.on("stopSimulation", () => {this.stopSimulation();}); |
|
|
|
this.body.emitter.on('stopSimulation', () => {this.stopSimulation();}); |
|
|
|
} |
|
|
|
|
|
|
|
setOptions(options) { |
|
|
@ -104,12 +104,12 @@ class PhysicsEngine { |
|
|
|
|
|
|
|
init() { |
|
|
|
var options; |
|
|
|
if (this.options.solver === "repulsion") { |
|
|
|
if (this.options.solver === 'repulsion') { |
|
|
|
options = this.options.repulsion; |
|
|
|
this.nodesSolver = new Repulsion(this.body, this.physicsBody, options); |
|
|
|
this.edgesSolver = new SpringSolver(this.body, this.physicsBody, options); |
|
|
|
} |
|
|
|
else if (this.options.solver === "hierarchicalRepulsion") { |
|
|
|
else if (this.options.solver === 'hierarchicalRepulsion') { |
|
|
|
options = this.options.hierarchicalRepulsion; |
|
|
|
this.nodesSolver = new HierarchicalRepulsion(this.body, this.physicsBody, options); |
|
|
|
this.edgesSolver = new HierarchicalSpringSolver(this.body, this.physicsBody, options); |
|
|
@ -128,26 +128,27 @@ class PhysicsEngine { |
|
|
|
if (this.physicsEnabled === true) { |
|
|
|
this.stabilized = false; |
|
|
|
if (this.options.stabilization.enabled === true) { |
|
|
|
this.body.emitter.emit('_blockRedrawRequests'); |
|
|
|
this.stabilize(); |
|
|
|
} |
|
|
|
else { |
|
|
|
this.ready = true; |
|
|
|
this.body.emitter.emit("zoomExtent", {duration: 0}, true) |
|
|
|
this.body.emitter.emit('zoomExtent', {duration: 0}, true) |
|
|
|
this.runSimulation(); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
this.ready = true; |
|
|
|
this.body.emitter.emit("_redraw"); |
|
|
|
this.body.emitter.emit('_redraw'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
stopSimulation() { |
|
|
|
this.stabilized = true; |
|
|
|
if (this.viewFunction !== undefined) { |
|
|
|
this.body.emitter.off("initRedraw", this.viewFunction); |
|
|
|
this.body.emitter.off('initRedraw', this.viewFunction); |
|
|
|
this.viewFunction = undefined; |
|
|
|
this.body.emitter.emit("_stopRendering"); |
|
|
|
this.body.emitter.emit('_stopRendering'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -155,12 +156,12 @@ class PhysicsEngine { |
|
|
|
if (this.physicsEnabled === true) { |
|
|
|
if (this.viewFunction === undefined) { |
|
|
|
this.viewFunction = this.simulationStep.bind(this); |
|
|
|
this.body.emitter.on("initRedraw", this.viewFunction); |
|
|
|
this.body.emitter.emit("_startRendering"); |
|
|
|
this.body.emitter.on('initRedraw', this.viewFunction); |
|
|
|
this.body.emitter.emit('_startRendering'); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
this.body.emitter.emit("_redraw"); |
|
|
|
this.body.emitter.emit('_redraw'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -180,7 +181,7 @@ class PhysicsEngine { |
|
|
|
|
|
|
|
if (this.stabilized === true) { |
|
|
|
if (this.stabilizationIterations > 1) { |
|
|
|
// trigger the "stabilized" event.
|
|
|
|
// trigger the 'stabilized' event.
|
|
|
|
// The event is triggered on the next tick, to prevent the case that
|
|
|
|
// it is fired while initializing the Network, in which case you would not
|
|
|
|
// be able to catch it
|
|
|
@ -191,7 +192,7 @@ class PhysicsEngine { |
|
|
|
this.stabilizationIterations = 0; |
|
|
|
this.startedStabilization = false; |
|
|
|
setTimeout(function () { |
|
|
|
me.body.emitter.emit("stabilized", params); |
|
|
|
me.body.emitter.emit('stabilized', params); |
|
|
|
}, 0); |
|
|
|
} |
|
|
|
else { |
|
|
@ -202,7 +203,7 @@ class PhysicsEngine { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* A single simulation step (or "tick") in the physics simulation |
|
|
|
* A single simulation step (or 'tick') in the physics simulation |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
@ -218,7 +219,7 @@ class PhysicsEngine { |
|
|
|
else { |
|
|
|
// this is here to ensure that there is no start event when the network is already stable.
|
|
|
|
if (this.startedStabilization === false) { |
|
|
|
this.body.emitter.emit("startStabilizing"); |
|
|
|
this.body.emitter.emit('startStabilizing'); |
|
|
|
this.startedStabilization = true; |
|
|
|
} |
|
|
|
} |
|
|
@ -432,7 +433,7 @@ class PhysicsEngine { |
|
|
|
} |
|
|
|
|
|
|
|
if (this.stabilized === false && this.stabilizationSteps < this.options.stabilization.iterations) { |
|
|
|
this.body.emitter.emit("stabilizationProgress", {steps: this.stabilizationSteps, total: this.options.stabilization.iterations}); |
|
|
|
this.body.emitter.emit('stabilizationProgress', {steps: this.stabilizationSteps, total: this.options.stabilization.iterations}); |
|
|
|
setTimeout(this._stabilizationBatch.bind(this),0); |
|
|
|
} |
|
|
|
else { |
|
|
@ -441,16 +442,17 @@ class PhysicsEngine { |
|
|
|
} |
|
|
|
|
|
|
|
_finalizeStabilization() { |
|
|
|
this.body.emitter.emit('_allowRedrawRequests'); |
|
|
|
if (this.options.stabilization.zoomExtent === true) { |
|
|
|
this.body.emitter.emit("zoomExtent", {duration:0}); |
|
|
|
this.body.emitter.emit('zoomExtent', {duration:0}); |
|
|
|
} |
|
|
|
|
|
|
|
if (this.options.stabilization.onlyDynamicEdges === true) { |
|
|
|
this._restoreFrozenNodes(); |
|
|
|
} |
|
|
|
|
|
|
|
this.body.emitter.emit("stabilizationIterationsDone"); |
|
|
|
this.body.emitter.emit("_requestRedraw"); |
|
|
|
this.body.emitter.emit('stabilizationIterationsDone'); |
|
|
|
this.body.emitter.emit('_requestRedraw'); |
|
|
|
|
|
|
|
this.ready = true; |
|
|
|
} |
|
|
|