blob: 14bdf99c100afeb789a85fcf7a07d14136f9f75e [file] [log] [blame]
Matteo Scandolo9e9db122016-02-18 15:28:48 -08001'use strict';
2
3angular.module('xos.mcordTopology')
Matteo Scandolo05b27442016-02-23 10:02:01 -08004.service('NodeDrawer', function(TopologyElements){
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) => {
Matteo Scandolo05b27442016-02-23 10:02:01 -0800102 nodes
103 .append('rect')
104 .attr({
105 width: 30,
106 height: 30,
107 x: -15,
108 y: -15
109 });
110
111 nodes
112 .append('path')
Matteo Scandolo9e9db122016-02-18 15:28:48 -0800113 .attr({
114 class: d => d.type,
Matteo Scandolo05b27442016-02-23 10:02:01 -0800115 opacity: 0,
116 d: () => TopologyElements.icons.switch,
117 transform: `translate(-22, -22), scale(0.4)`
Matteo Scandoloe5d38702016-02-18 16:33:49 -0800118 })
119 .transition()
120 .duration(duration)
121 // .delay((d, i) => i * (duration / 2))
122 .attr({
Matteo Scandoloe5d38702016-02-18 16:33:49 -0800123 opacity: 1
Matteo Scandolo9e9db122016-02-18 15:28:48 -0800124 });
125 };
126
127 this.drawOthers = (nodes) => {
128 nodes.append('circle')
129 .attr({
130 class: d => d.type,
Matteo Scandoloe5d38702016-02-18 16:33:49 -0800131 r: 0,
132 opacity: 0
133 })
134 .transition()
135 .duration(duration)
136 // .delay((d, i) => i * (duration / 2))
137 .attr({
138 r: 15,
139 opacity: 1
Matteo Scandolo9e9db122016-02-18 15:28:48 -0800140 });
141
142 nodes.append('text')
143 .attr({
Matteo Scandolo8b9d8312016-02-18 17:01:06 -0800144 'text-anchor': 'start',
145 y: 17,
146 x: 17,
Matteo Scandoloe5d38702016-02-18 16:33:49 -0800147 opacity: 0
Matteo Scandolo9e9db122016-02-18 15:28:48 -0800148 })
149 .text(d => d.type)
Matteo Scandoloe5d38702016-02-18 16:33:49 -0800150 .transition()
151 .duration(duration * 2)
152 .attr({
153 opacity: 1
154 });
155
156 };
Matteo Scandolo8b9d8312016-02-18 17:01:06 -0800157
Matteo Scandoloe5d38702016-02-18 16:33:49 -0800158 this.removeElements = (nodes) => {
159 nodes
160 .transition()
161 .duration(duration)
162 .attr({
163 opacity: 0
164 })
165 .remove();
Matteo Scandolo9e9db122016-02-18 15:28:48 -0800166 };
167});