Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 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 Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 19 | 'use strict'; |
| 20 | |
| 21 | angular.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 Scandolo | aa3cc50 | 2016-03-09 17:58:51 -0800 | [diff] [blame] | 46 | // fabric.append('text') |
| 47 | // .text('Fabric') |
| 48 | // .attr({ |
| 49 | // 'text-anchor': 'middle', |
| 50 | // x: ((hStep + 50) / 2), |
| 51 | // y: -10 |
| 52 | // }); |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 53 | |
| 54 | isFabricDrawed = true; |
| 55 | }; |
| 56 | |
| 57 | this.drawBbus = (nodes) => { |
| 58 | |
Matteo Scandolo | e223b53 | 2016-03-04 08:31:20 -0800 | [diff] [blame] | 59 | 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 Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 75 | nodes |
| 76 | .append('path') |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 77 | .attr({ |
Matteo Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 78 | class: d => `${d.type} antenna`, |
| 79 | opacity: 0, |
| 80 | d: () => TopologyElements.icons.bbu, |
Matteo Scandolo | e223b53 | 2016-03-04 08:31:20 -0800 | [diff] [blame] | 81 | transform: `translate(-18, -18)` |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 82 | }) |
| 83 | .transition() |
| 84 | .duration(duration) |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 85 | .attr({ |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 86 | opacity: 1 |
| 87 | }); |
| 88 | |
| 89 | nodes.append('text') |
| 90 | .attr({ |
| 91 | 'text-anchor': 'start', |
Matteo Scandolo | e223b53 | 2016-03-04 08:31:20 -0800 | [diff] [blame] | 92 | y: 25, |
Matteo Scandolo | d20e18f | 2016-03-03 11:35:26 -0800 | [diff] [blame] | 93 | x: 5, |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 94 | 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 Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 116 | r: 40, |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 117 | opacity: 1 |
| 118 | }); |
Matteo Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 119 | |
| 120 | nodes |
| 121 | .append('path') |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 122 | .attr({ |
Matteo Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 123 | class: d => `${d.type} antenna`, |
| 124 | opacity: 0, |
| 125 | d: () => TopologyElements.icons.rru, |
Matteo Scandolo | e223b53 | 2016-03-04 08:31:20 -0800 | [diff] [blame] | 126 | transform: `translate(-18, -18)` |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 127 | }) |
| 128 | .transition() |
| 129 | .duration(duration) |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 130 | .attr({ |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 131 | opacity: 1 |
| 132 | }); |
Matteo Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 133 | |
| 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 Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 147 | }; |
| 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 Scandolo | e223b53 | 2016-03-04 08:31:20 -0800 | [diff] [blame] | 176 | 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 Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 192 | nodes |
| 193 | .append('path') |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 194 | .attr({ |
Matteo Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 195 | class: d => `${d.type} antenna`, |
| 196 | opacity: 0, |
| 197 | d: () => TopologyElements.icons.bbu, |
Matteo Scandolo | e223b53 | 2016-03-04 08:31:20 -0800 | [diff] [blame] | 198 | transform: `translate(-18, -18)` |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 199 | }) |
| 200 | .transition() |
| 201 | .duration(duration) |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 202 | .attr({ |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 203 | opacity: 1 |
| 204 | }); |
| 205 | |
| 206 | nodes.append('text') |
| 207 | .attr({ |
| 208 | 'text-anchor': 'start', |
Matteo Scandolo | e223b53 | 2016-03-04 08:31:20 -0800 | [diff] [blame] | 209 | y: 25, |
| 210 | x: -12, |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 211 | opacity: 0 |
| 212 | }) |
Matteo Scandolo | 89667d3 | 2016-03-07 13:34:05 -0800 | [diff] [blame] | 213 | .text(d => d.name.toUpperCase()) |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 214 | .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 | }); |