ing
This commit is contained in:
parent
22f879d06d
commit
6ef4cd4134
|
@ -26,7 +26,7 @@
|
||||||
<line class="link" [attr.x1]="link.source.x" [attr.y1]="link.source.y" [attr.x2]="link.target.x" [attr.y2]="link.target.y"></line>
|
<line class="link" [attr.x1]="link.source.x" [attr.y1]="link.source.y" [attr.x2]="link.target.x" [attr.y2]="link.target.y"></line>
|
||||||
</g>
|
</g>
|
||||||
<g *ngFor="let node of nodes">
|
<g *ngFor="let node of nodes">
|
||||||
<g [attr.transform]="'translate(' + node.x + ',' + node.y + ')'" (click)="onTargetClick(node)">
|
<g class="node-container" [attr.transform]="'translate(' + node.x + ',' + node.y + ')'" (click)="onTargetClick(node)">
|
||||||
<circle class="node" cx="0" cy="0" r="33" fill="url(#icon_db_mria)"></circle>
|
<circle class="node" cx="0" cy="0" r="33" fill="url(#icon_db_mria)"></circle>
|
||||||
<text class="textClass" y="2.5em" text-anchor="middle">{{node.id}}</text>
|
<text class="textClass" y="2.5em" text-anchor="middle">{{node.id}}</text>
|
||||||
</g>
|
</g>
|
||||||
|
|
|
@ -165,6 +165,35 @@ export class HomePageComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
simulationRestart() {
|
simulationRestart() {
|
||||||
// Update and restart the simulation.
|
// Update and restart the simulation.
|
||||||
|
const __this = this;
|
||||||
|
|
||||||
|
function started(node: Node) {
|
||||||
|
/** Preventing propagation of dragstart to parent elements */
|
||||||
|
d3.event.sourceEvent.stopPropagation();
|
||||||
|
|
||||||
|
if (!d3.event.active) {
|
||||||
|
__this.simulation.alphaTarget(0.3).restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
d3.event.on('drag', dragged).on('end', ended);
|
||||||
|
|
||||||
|
function dragged() {
|
||||||
|
node.fx = d3.event.x;
|
||||||
|
node.fy = d3.event.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ended() {
|
||||||
|
if (!d3.event.active) {
|
||||||
|
__this.simulation.alphaTarget(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
node.fx = null;
|
||||||
|
node.fy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
d3.select(this.discoveryTargetRef.nativeElement).selectAll('.node-container').call(d3.drag().on('start', started));
|
||||||
|
|
||||||
this.simulation
|
this.simulation
|
||||||
.nodes(this.nodes)
|
.nodes(this.nodes)
|
||||||
.force('link', d3.forceLink(this.links).distance(150))
|
.force('link', d3.forceLink(this.links).distance(150))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user