blob: 5394da41c3c15a4a28dbce59d6b7d3ada99d53a6 [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandolodf35ca92016-02-25 09:19:41 -080019'use strict';
20
21angular.module('xos.mcordTopology')
22.service('NodeDrawer', function(TopologyElements){
23
24 const duration = 500;
25
26 let isFabricDrawed = false;
27
28 this.drawFabricBox = (svg, hStep, vStep) => {
29
30 if(isFabricDrawed){
31 return;
32 }
33
34 let fabric = svg.append('g')
35 .attr({
36 transform: `translate(${hStep - 25}, ${vStep - 25})`
37 });
38
39 fabric.append('rect')
40 .attr({
41 width: hStep + 50,
42 height: vStep + 50,
43 class: 'fabric-container'
44 });
45
Matteo Scandoloaa3cc502016-03-09 17:58:51 -080046 // fabric.append('text')
47 // .text('Fabric')
48 // .attr({
49 // 'text-anchor': 'middle',
50 // x: ((hStep + 50) / 2),
51 // y: -10
52 // });
Matteo Scandolodf35ca92016-02-25 09:19:41 -080053
54 isFabricDrawed = true;
55 };
56
57 this.drawBbus = (nodes) => {
58
Matteo Scandoloe223b532016-03-04 08:31:20 -080059 nodes.append('rect')
60 .attr({
61 class: d => d.type,
62 width: 30,
63 height: 30,
64 x: -15,
65 y: -15,
66 opacity: 0
67 })
68 .transition()
69 .duration(duration)
70 .attr({
71 r: 15,
72 opacity: 1
73 });
74
Matteo Scandolodaae6702016-02-26 13:42:50 -080075 nodes
76 .append('path')
Matteo Scandolodf35ca92016-02-25 09:19:41 -080077 .attr({
Matteo Scandolodaae6702016-02-26 13:42:50 -080078 class: d => `${d.type} antenna`,
79 opacity: 0,
80 d: () => TopologyElements.icons.bbu,
Matteo Scandoloe223b532016-03-04 08:31:20 -080081 transform: `translate(-18, -18)`
Matteo Scandolodf35ca92016-02-25 09:19:41 -080082 })
83 .transition()
84 .duration(duration)
Matteo Scandolodf35ca92016-02-25 09:19:41 -080085 .attr({
Matteo Scandolodf35ca92016-02-25 09:19:41 -080086 opacity: 1
87 });
88
89 nodes.append('text')
90 .attr({
91 'text-anchor': 'start',
Matteo Scandoloe223b532016-03-04 08:31:20 -080092 y: 25,
Matteo Scandolod20e18f2016-03-03 11:35:26 -080093 x: 5,
Matteo Scandolodf35ca92016-02-25 09:19:41 -080094 opacity: 0
95 })
96 .text(d => `BBU ${d.name.substr(d.name.length - 1, 1)}`)
97 .transition()
98 .duration(duration * 2)
99 .attr({
100 opacity: 1
101 });
102 };
103
104 this.drawRrus = (nodes) => {
105
106 nodes.append('circle')
107 .attr({
108 class: d => `${d.type}-shadow`,
109 r: 0,
110 opacity: 0
111 })
112 .transition()
113 .duration(duration * 2)
114 // .delay((d, i) => i * (duration / 2))
115 .attr({
Matteo Scandolodaae6702016-02-26 13:42:50 -0800116 r: 40,
Matteo Scandolodf35ca92016-02-25 09:19:41 -0800117 opacity: 1
118 });
Matteo Scandolodaae6702016-02-26 13:42:50 -0800119
120 nodes
121 .append('path')
Matteo Scandolodf35ca92016-02-25 09:19:41 -0800122 .attr({
Matteo Scandolodaae6702016-02-26 13:42:50 -0800123 class: d => `${d.type} antenna`,
124 opacity: 0,
125 d: () => TopologyElements.icons.rru,
Matteo Scandoloe223b532016-03-04 08:31:20 -0800126 transform: `translate(-18, -18)`
Matteo Scandolodf35ca92016-02-25 09:19:41 -0800127 })
128 .transition()
129 .duration(duration)
Matteo Scandolodf35ca92016-02-25 09:19:41 -0800130 .attr({
Matteo Scandolodf35ca92016-02-25 09:19:41 -0800131 opacity: 1
132 });
Matteo Scandolodaae6702016-02-26 13:42:50 -0800133
134 // nodes.append('circle')
135 // .attr({
136 // class: d => d.type,
137 // r: 0,
138 // opacity: 0
139 // })
140 // .transition()
141 // .duration(duration)
142 // // .delay((d, i) => i * (duration / 2))
143 // .attr({
144 // r: 10,
145 // opacity: 1
146 // });
Matteo Scandolodf35ca92016-02-25 09:19:41 -0800147 };
148
149 this.drawFabric = (nodes) => {
150 nodes
151 .append('rect')
152 .attr({
153 width: 30,
154 height: 30,
155 x: -15,
156 y: -15
157 });
158
159 nodes
160 .append('path')
161 .attr({
162 class: d => d.type,
163 opacity: 0,
164 d: () => TopologyElements.icons.switch,
165 transform: `translate(-22, -22), scale(0.4)`
166 })
167 .transition()
168 .duration(duration)
169 // .delay((d, i) => i * (duration / 2))
170 .attr({
171 opacity: 1
172 });
173 };
174
175 this.drawOthers = (nodes) => {
Matteo Scandoloe223b532016-03-04 08:31:20 -0800176 nodes.append('rect')
177 .attr({
178 class: d => d.type,
179 width: 30,
180 height: 30,
181 x: -15,
182 y: -15,
183 opacity: 0
184 })
185 .transition()
186 .duration(duration)
187 .attr({
188 r: 15,
189 opacity: 1
190 });
191
Matteo Scandolodaae6702016-02-26 13:42:50 -0800192 nodes
193 .append('path')
Matteo Scandolodf35ca92016-02-25 09:19:41 -0800194 .attr({
Matteo Scandolodaae6702016-02-26 13:42:50 -0800195 class: d => `${d.type} antenna`,
196 opacity: 0,
197 d: () => TopologyElements.icons.bbu,
Matteo Scandoloe223b532016-03-04 08:31:20 -0800198 transform: `translate(-18, -18)`
Matteo Scandolodf35ca92016-02-25 09:19:41 -0800199 })
200 .transition()
201 .duration(duration)
Matteo Scandolodf35ca92016-02-25 09:19:41 -0800202 .attr({
Matteo Scandolodf35ca92016-02-25 09:19:41 -0800203 opacity: 1
204 });
205
206 nodes.append('text')
207 .attr({
208 'text-anchor': 'start',
Matteo Scandoloe223b532016-03-04 08:31:20 -0800209 y: 25,
210 x: -12,
Matteo Scandolodf35ca92016-02-25 09:19:41 -0800211 opacity: 0
212 })
Matteo Scandolo89667d32016-03-07 13:34:05 -0800213 .text(d => d.name.toUpperCase())
Matteo Scandolodf35ca92016-02-25 09:19:41 -0800214 .transition()
215 .duration(duration * 2)
216 .attr({
217 opacity: 1
218 });
219
220 };
221
222 this.removeElements = (nodes) => {
223 nodes
224 .transition()
225 .duration(duration)
226 .attr({
227 opacity: 0
228 })
229 .remove();
230 };
231});