2 * Created by onvelocity on 2/15/16.
5 import math
from './math'
6 import PathBuilder
from './PathBuilder'
7 import ColorGroups
from '../ColorGroups'
8 import DescriptorModelFactory
from '../model/DescriptorModelFactory'
12 * This class draws the paths between the VLD and the Connection Point it references.
16 const line
= d3
.svg
.line()
24 export default class GraphVirtualLinkPaths
{
26 constructor(graph
, props
) {
29 this.maps
= new WeakMap();
30 this.maps
.set(this, {vld
: {}, containers
: new Set()});
33 findVldForInternalConnectionPoint(icp
) {
34 const id
= icp
.vldRef
;
35 return this.maps
.get(this).vld
[id
];
39 this.maps
.get(this).vld
[vl
.id
] = vl
;
42 get containersList() {
43 return Array
.from(this.maps
.get(this).containers
);
46 addContainer(container
) {
47 this.maps
.get(this).containers
.add(container
);
50 addContainers(containers
) {
51 containers
.filter(container
=> {
52 if (DescriptorModelFactory
.isInternalConnectionPoint(container
)) {
53 this.addContainer(container
);
54 } else if (DescriptorModelFactory
.isInternalVirtualLink(container
)) {
55 this.mapVld(container
);
60 renderPath(icp
, ivld
) {
61 const path
= line
.interpolate('basis');
62 const srcPoint
= icp
.position
.centerPoint();
63 const dstPoint
= ivld
.position
.centerPoint();
64 const srcIsTopMounted
= /top/.test(icp
.location
);
67 y
: (srcIsTopMounted
? icp
.position
.top
- 15 : icp
.position
.bottom
+ 15)
71 y
: (srcIsTopMounted
? icp
.position
.top
- 15 : icp
.position
.bottom
+ 15)
73 return path([srcPoint
, srcSpline1
, srcSpline2
, dstPoint
]);
78 const paths
= this.graph
.paths
.selectAll('.' + this.props
.selector
.join('.')).data(this.containersList
, DescriptorModelFactory
.containerIdentity
);
80 paths
.enter().append('path');
87 return 'connection between-' + d
.parent
.type
+ '-and-' + d
.type
;
90 stroke
: ColorGroups
.vld
.primary
,
93 return this.renderPath(d
, this.findVldForInternalConnectionPoint(d
));
97 paths
.exit().remove();