From b9df48a54cf834a34be759bea341414dcae1e549 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 12 Sep 2018 16:08:48 +0900 Subject: [PATCH] ing --- src/app/pages/home/home-page.component.ts | 76 ++++++++++++++--------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/src/app/pages/home/home-page.component.ts b/src/app/pages/home/home-page.component.ts index b1d70b4..79958d3 100644 --- a/src/app/pages/home/home-page.component.ts +++ b/src/app/pages/home/home-page.component.ts @@ -178,44 +178,63 @@ export class HomePageComponent implements OnInit, OnDestroy { ; } - simulationRestart() { + simulationRestart(attachEvent: boolean = false) { // Update and restart the simulation. - const __this = this; - function started(node: Node) { - /** Preventing propagation of dragstart to parent elements */ - d3.event.sourceEvent.stopPropagation(); + if (attachEvent) { + const __this = this; - if (!d3.event.active) { - __this.simulation.alphaTarget(0.3).restart(); - } + // function started(node: Node) { + // /** Preventing propagation of dragstart to parent elements */ + // d3.event.sourceEvent.stopPropagation(); - d3.event.on('drag', dragged).on('end', ended); + // if (!d3.event.active) { + // __this.simulation.alphaTarget(0.3).restart(); + // } - function dragged() { - if (undefined === node) { - return; - } + // d3.event.on('drag', dragged).on('end', ended); - node.fx = d3.event.x; - node.fy = d3.event.y; - } + // function dragged() { + // if (undefined === node) { + // return; + // } - function ended() { - if (!d3.event.active) { - __this.simulation.alphaTarget(0); - } + // node.fx = d3.event.x; + // node.fy = d3.event.y; + // } + + // function ended() { + // if (!d3.event.active) { + // __this.simulation.alphaTarget(0); + // } + + // if (undefined === node) { + // return; + // } + // node.fx = null; + // node.fy = null; + // } + // } + + // 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(); + // }) + // ; - if (undefined === node) { - return; - } - node.fx = null; - node.fy = null; - } } - d3.select(this.discoveryTargetRef.nativeElement).selectAll('.node-container').call(d3.drag().on('start', started)); - this.simulation .nodes(this.nodes) .force('link', d3.forceLink(this.links).distance(150)) @@ -270,6 +289,7 @@ export class HomePageComponent implements OnInit, OnDestroy { public DiscoveryStop(stopDate: Date) { console.log('DiscoveryStop', stopDate); this.discoveryConfigService.setStarted(false); + this.simulationRestart(true); // this.simulation.stop(); }