2 * Created by onvelocity on 2/10/16.
5 import math
from './math'
6 import PathBuilder
from './PathBuilder'
7 import DescriptorModelFactory
from '../model/DescriptorModelFactory'
9 import '../../styles/GraphRecordServicePaths.scss'
11 export default class GraphRecordServicePath
{
13 constructor(graph
, props
) {
17 this.networkMap
= new WeakMap();
18 this.networkMap
.set(this, {networkMap
: {}});
23 return this.networkMap
.get(this).networkMap
[key
];
27 this.networkMap
.get(this).networkMap
[item
.key
+ item
.type
] = item
;
30 addContainers(containers
) {
32 containers
.filter(d
=> {
33 if (DescriptorModelFactory
.isRecordServicePath(d
)) {
36 if (DescriptorModelFactory
.isRspConnectionPointRef(d
)) {
39 if (DescriptorModelFactory
.isConnectionPoint(d
)) {
42 if (DescriptorModelFactory
.isVnfdConnectionPointRef(d
)) {
45 }).forEach(d
=> this.containers
.push(d
));
51 const pathsGroup
= this.graph
.forwardingGraphPaths
;
53 const path
= pathsGroup
.selectAll('.rsp-path').data(this.containers
, DescriptorModelFactory
.containerIdentity
);
55 path
.enter().append('path');
58 'class': 'rsp-path path',
59 'stroke': rsp
=> rsp
.parent
.colors
.primary
,
63 'shape-rendering': 'geometricPrecision',
64 d
: (rsp
, rspIndex
) => {
66 if (!rsp
.uiState
.showPath
) {
70 const cpList
= rsp
.connectionPoints
.filter(d
=> d
);
71 const cpCount
= rsp
.connectionPoints
.length
- 1;
73 const path
= new PathBuilder();
75 const pathOffset
= 20 * rspIndex
;
77 return rsp
.connectionPoints
.reduce((r
, cpRef
, cpRefIndex
) => {
79 const cp
= this.getNetwork(cpRef
.key
+ 'connection-point');
80 const point
= cp
.position
.centerPoint();
81 const vnfdCpRef
= this.getNetwork(cp
.key
+ 'vnfd-connection-point-ref');
83 if (path
.length
=== 0) {
84 path
.M(point
.x
, point
.y
, {container
: cp
});
85 } else if (cpRefIndex
=== 1) {
87 const last
= path
.last();
89 //const previousContainer = path.findPrevious(d => d.info.container);
93 //if (previousContainer) {
94 // distance = math.distanceBetweenPositions(previousContainer.info.container.position, cp.position);
97 if (last
.cmd
=== 'M') {
98 path
.C(last
.x
+ 100 + pathOffset
, last
.y
- 100 - pathOffset
, point
.x
- 100 - pathOffset
, point
.y
- 100 - pathOffset
, point
.x
, point
.y
);
100 path
.S(point
.x
- 100, point
.y
- 100, point
.x
, point
.y
);
105 //const last = path.last();
107 //const previousContainer = path.findPrevious(d => d.info.container);
109 //let distance = 200;
111 //if (previousContainer) {
112 // distance = math.distanceBetweenPositions(previousContainer.info.container.position, cp.position);
115 path
.S(point
.x
- 100 - pathOffset
, point
.y
- 100 - pathOffset
, point
.x
, point
.y
);
120 if (cpRefIndex
< cpCount
&& vnfdCpRef
) {
122 const nextVnfdCpRef
= this.getNetwork(cpList
[cpRefIndex
+ 1].key
+ 'vnfd-connection-point-ref');
126 const cpsOnSameVnfd
= nextVnfdCpRef
&& nextVnfdCpRef
.key
=== vnfdCpRef
.key
;
127 const cpsOnSameVld
= nextVnfdCpRef
.parent
.key
=== vnfdCpRef
.parent
.key
;
131 const vldCenter
= vnfdCpRef
.parent
.position
.centerPoint();
133 const last
= path
.last();
135 if (last
.cmd
=== 'M') {
136 path
.C(last
.x
, last
.y
+ 40 + pathOffset
, vldCenter
.x
, vldCenter
.y
- 40 - pathOffset
, vldCenter
.x
, vldCenter
.y
);
138 path
.S(vldCenter
.x
, vldCenter
.y
- 40 - pathOffset
, vldCenter
.x
, vldCenter
.y
);
141 //const distance = math.distanceBetweenPositions(cp.position, vnfdCpRef.parent.position);
143 } else if (cpsOnSameVnfd
) {
145 const last
= path
.last();
147 const vldCenter
= vnfdCpRef
.parent
.position
.centerPoint();
149 if (last
.cmd
=== 'M') {
150 path
.C(last
.x
, last
.y
+ 40, vldCenter
.x
, vldCenter
.y
- 40, vldCenter
.x
, vldCenter
.y
);
152 path
.S(vldCenter
.x
, vldCenter
.y
- 40, vldCenter
.x
, vldCenter
.y
);
161 return path
.toString();
168 path
.exit().remove();