blob: 30e9d2f661abdedbde148ab53a6a09466e53a8df [file] [log] [blame]
Matteo Scandolo9e9db122016-02-18 15:28:48 -08001'use strict';
2
3angular.module('xos.mcordTopology')
4.service('NodeDrawer', function(){
Matteo Scandoloe5d38702016-02-18 16:33:49 -08005
6 const duration = 500;
7
Matteo Scandolobc7a1402016-02-18 17:04:07 -08008 let isFabricDrawed = false;
9
Matteo Scandolo8b9d8312016-02-18 17:01:06 -080010 this.drawFabricBox = (svg, hStep, vStep) => {
Matteo Scandolobc7a1402016-02-18 17:04:07 -080011
12 if(isFabricDrawed){
13 return;
14 }
15
Matteo Scandolo8b9d8312016-02-18 17:01:06 -080016 let fabric = svg.append('g')
17 .attr({
18 transform: `translate(${hStep - 25}, ${vStep - 25})`
19 });
20
21 fabric.append('rect')
22 .attr({
23 width: hStep + 50,
24 height: vStep + 50,
25 class: 'fabric-container'
26 });
27
28 fabric.append('text')
29 .text('Fabric')
30 .attr({
31 'text-anchor': 'middle',
32 x: ((hStep + 50) / 2),
33 y: -10
34 });
Matteo Scandolobc7a1402016-02-18 17:04:07 -080035
36 isFabricDrawed = true;
Matteo Scandolo8b9d8312016-02-18 17:01:06 -080037 };
38
Matteo Scandolo9e9db122016-02-18 15:28:48 -080039 this.drawBbus = (nodes) => {
Matteo Scandoloe5d38702016-02-18 16:33:49 -080040
Matteo Scandolo9e9db122016-02-18 15:28:48 -080041 nodes.append('circle')
42 .attr({
43 class: d => d.type,
Matteo Scandoloe5d38702016-02-18 16:33:49 -080044 r: 0,
45 opacity: 0
46 })
47 .transition()
48 .duration(duration)
49 // .delay((d, i) => i * (duration / 2))
50 .attr({
51 r: 15,
52 opacity: 1
Matteo Scandolo9e9db122016-02-18 15:28:48 -080053 });
54
55 nodes.append('text')
56 .attr({
Matteo Scandolo8b9d8312016-02-18 17:01:06 -080057 'text-anchor': 'start',
58 y: 17,
59 x: 17,
Matteo Scandoloe5d38702016-02-18 16:33:49 -080060 opacity: 0
Matteo Scandolo9e9db122016-02-18 15:28:48 -080061 })
Matteo Scandoloe5d38702016-02-18 16:33:49 -080062 .text(d => `BBU ${d.name.substr(d.name.length - 1, 1)}`)
63 .transition()
64 .duration(duration * 2)
65 .attr({
66 opacity: 1
67 });
Matteo Scandolo9e9db122016-02-18 15:28:48 -080068 };
69
70 this.drawRrus = (nodes) => {
71
72 nodes.append('circle')
73 .attr({
74 class: d => `${d.type}-shadow`,
Matteo Scandoloe5d38702016-02-18 16:33:49 -080075 r: 0,
76 opacity: 0
77 })
78 .transition()
79 .duration(duration * 2)
80 // .delay((d, i) => i * (duration / 2))
81 .attr({
82 r: 30,
83 opacity: 1
Matteo Scandolo9e9db122016-02-18 15:28:48 -080084 });
Matteo Scandoloe5d38702016-02-18 16:33:49 -080085
Matteo Scandolo9e9db122016-02-18 15:28:48 -080086 nodes.append('circle')
87 .attr({
88 class: d => d.type,
Matteo Scandoloe5d38702016-02-18 16:33:49 -080089 r: 0,
90 opacity: 0
91 })
92 .transition()
93 .duration(duration)
94 // .delay((d, i) => i * (duration / 2))
95 .attr({
96 r: 10,
97 opacity: 1
Matteo Scandolo9e9db122016-02-18 15:28:48 -080098 });
99 };
100
101 this.drawFabric = (nodes) => {
102 nodes.append('rect')
103 .attr({
104 class: d => d.type,
Matteo Scandoloe5d38702016-02-18 16:33:49 -0800105 width: 0,
106 height: 0,
Matteo Scandolo8b9d8312016-02-18 17:01:06 -0800107 x: -15,
108 y: -15,
Matteo Scandoloe5d38702016-02-18 16:33:49 -0800109 opacity: 0
110 })
111 .transition()
112 .duration(duration)
113 // .delay((d, i) => i * (duration / 2))
114 .attr({
Matteo Scandolo8b9d8312016-02-18 17:01:06 -0800115 width: 30,
116 height: 30,
Matteo Scandoloe5d38702016-02-18 16:33:49 -0800117 opacity: 1
Matteo Scandolo9e9db122016-02-18 15:28:48 -0800118 });
119 };
120
121 this.drawOthers = (nodes) => {
122 nodes.append('circle')
123 .attr({
124 class: d => d.type,
Matteo Scandoloe5d38702016-02-18 16:33:49 -0800125 r: 0,
126 opacity: 0
127 })
128 .transition()
129 .duration(duration)
130 // .delay((d, i) => i * (duration / 2))
131 .attr({
132 r: 15,
133 opacity: 1
Matteo Scandolo9e9db122016-02-18 15:28:48 -0800134 });
135
136 nodes.append('text')
137 .attr({
Matteo Scandolo8b9d8312016-02-18 17:01:06 -0800138 'text-anchor': 'start',
139 y: 17,
140 x: 17,
Matteo Scandoloe5d38702016-02-18 16:33:49 -0800141 opacity: 0
Matteo Scandolo9e9db122016-02-18 15:28:48 -0800142 })
143 .text(d => d.type)
Matteo Scandoloe5d38702016-02-18 16:33:49 -0800144 .transition()
145 .duration(duration * 2)
146 .attr({
147 opacity: 1
148 });
149
150 };
Matteo Scandolo8b9d8312016-02-18 17:01:06 -0800151
Matteo Scandoloe5d38702016-02-18 16:33:49 -0800152 this.removeElements = (nodes) => {
153 nodes
154 .transition()
155 .duration(duration)
156 .attr({
157 opacity: 0
158 })
159 .remove();
Matteo Scandolo9e9db122016-02-18 15:28:48 -0800160 };
161});