This commit is contained in:
crusader 2018-09-12 16:08:48 +09:00
parent 57258305cb
commit b9df48a54c

View File

@ -178,43 +178,62 @@ export class HomePageComponent implements OnInit, OnDestroy {
; ;
} }
simulationRestart() { simulationRestart(attachEvent: boolean = false) {
// Update and restart the simulation. // Update and restart the simulation.
if (attachEvent) {
const __this = this; const __this = this;
function started(node: Node) { // function started(node: Node) {
/** Preventing propagation of dragstart to parent elements */ // /** Preventing propagation of dragstart to parent elements */
d3.event.sourceEvent.stopPropagation(); // d3.event.sourceEvent.stopPropagation();
if (!d3.event.active) { // if (!d3.event.active) {
__this.simulation.alphaTarget(0.3).restart(); // __this.simulation.alphaTarget(0.3).restart();
} // }
d3.event.on('drag', dragged).on('end', ended); // d3.event.on('drag', dragged).on('end', ended);
function dragged() { // function dragged() {
if (undefined === node) { // if (undefined === node) {
return; // return;
} // }
node.fx = d3.event.x; // node.fx = d3.event.x;
node.fy = d3.event.y; // node.fy = d3.event.y;
} // }
function ended() { // function ended() {
if (!d3.event.active) { // if (!d3.event.active) {
__this.simulation.alphaTarget(0); // __this.simulation.alphaTarget(0);
} // }
if (undefined === node) { // if (undefined === node) {
return; // return;
} // }
node.fx = null; // node.fx = null;
node.fy = null; // node.fy = null;
} // }
} // }
d3.select(this.discoveryTargetRef.nativeElement).selectAll('.node-container').call(d3.drag().on('start', started)); // d3.select(this.discoveryTargetRef.nativeElement).selectAll('.node-container').call(d3.drag().on('start', started));
// d3.drag()
// .on('dragstart', (node: Node, i: number) => {
// __this.simulation.stop();
// })
// .on('drag', (node: Node, i: number) => {
// node.fx += d3.event.dx;
// node.fy += d3.event.dy;
// node.x += d3.event.dx;
// node.y += d3.event.dy;
// })
// .on('dragend', (node: Node, i: number) => {
// __this.simulation.stop();
// })
// ;
}
this.simulation this.simulation
.nodes(this.nodes) .nodes(this.nodes)
@ -270,6 +289,7 @@ export class HomePageComponent implements OnInit, OnDestroy {
public DiscoveryStop(stopDate: Date) { public DiscoveryStop(stopDate: Date) {
console.log('DiscoveryStop', stopDate); console.log('DiscoveryStop', stopDate);
this.discoveryConfigService.setStarted(false); this.discoveryConfigService.setStarted(false);
this.simulationRestart(true);
// this.simulation.stop(); // this.simulation.stop();
} }