Revert "BUG-410 -- update RIFT platform"
[osm/UI.git] / skyquake / plugins / composer / src / src / libraries / graph / GraphInternalVirtualLinkPaths.js
1 /**
2 * Created by onvelocity on 2/15/16.
3 */
4
5 import math from './math'
6 import PathBuilder from './PathBuilder'
7 import ColorGroups from '../ColorGroups'
8 import DescriptorModelFactory from '../model/DescriptorModelFactory'
9
10 /**
11 *
12 * This class draws the paths between the VLD and the Connection Point it references.
13 *
14 */
15
16 const line = d3.svg.line()
17 .x(d => {
18 return d.x;
19 })
20 .y(d => {
21 return d.y;
22 });
23
24 export default class GraphVirtualLinkPaths {
25
26 constructor(graph, props) {
27 this.graph = graph;
28 this.props = props;
29 this.maps = new WeakMap();
30 this.maps.set(this, {vld: {}, containers: new Set()});
31 }
32
33 findVldForInternalConnectionPoint(icp) {
34 const id = icp.vldRef;
35 return this.maps.get(this).vld[id];
36 }
37
38 mapVld(vl) {
39 this.maps.get(this).vld[vl.id] = vl;
40 }
41
42 get containersList() {
43 return Array.from(this.maps.get(this).containers);
44 }
45
46 addContainer(container) {
47 this.maps.get(this).containers.add(container);
48 }
49
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);
56 }
57 });
58 }
59
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);
65 const srcSpline1 = {
66 x: srcPoint.x,
67 y: (srcIsTopMounted ? icp.position.top - 15 : icp.position.bottom + 15)
68 };
69 const srcSpline2 = {
70 x: srcPoint.x,
71 y: (srcIsTopMounted ? icp.position.top - 15 : icp.position.bottom + 15)
72 };
73 return path([srcPoint, srcSpline1, srcSpline2, dstPoint]);
74 }
75
76 render() {
77
78 const paths = this.graph.paths.selectAll('.' + this.props.selector.join('.')).data(this.containersList, DescriptorModelFactory.containerIdentity);
79
80 paths.enter().append('path');
81
82 paths.attr({
83 'data-uid': d => {
84 return d.uid;
85 },
86 'class': d => {
87 return 'connection between-' + d.parent.type + '-and-' + d.type;
88 },
89 'stroke-width': 5,
90 stroke: ColorGroups.vld.primary,
91 fill: 'transparent',
92 d: d => {
93 return this.renderPath(d, this.findVldForInternalConnectionPoint(d));
94 }
95 });
96
97 paths.exit().remove();
98
99 }
100
101 }