Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | angular.module('xos.mcordTopology') |
| 4 | .service('NodeDrawer', function(TopologyElements){ |
| 5 | |
| 6 | const duration = 500; |
| 7 | |
| 8 | let isFabricDrawed = false; |
| 9 | |
| 10 | this.drawFabricBox = (svg, hStep, vStep) => { |
| 11 | |
| 12 | if(isFabricDrawed){ |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | 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 | |
Matteo Scandolo | aa3cc50 | 2016-03-09 17:58:51 -0800 | [diff] [blame] | 28 | // fabric.append('text') |
| 29 | // .text('Fabric') |
| 30 | // .attr({ |
| 31 | // 'text-anchor': 'middle', |
| 32 | // x: ((hStep + 50) / 2), |
| 33 | // y: -10 |
| 34 | // }); |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 35 | |
| 36 | isFabricDrawed = true; |
| 37 | }; |
| 38 | |
| 39 | this.drawBbus = (nodes) => { |
| 40 | |
Matteo Scandolo | e223b53 | 2016-03-04 08:31:20 -0800 | [diff] [blame] | 41 | nodes.append('rect') |
| 42 | .attr({ |
| 43 | class: d => d.type, |
| 44 | width: 30, |
| 45 | height: 30, |
| 46 | x: -15, |
| 47 | y: -15, |
| 48 | opacity: 0 |
| 49 | }) |
| 50 | .transition() |
| 51 | .duration(duration) |
| 52 | .attr({ |
| 53 | r: 15, |
| 54 | opacity: 1 |
| 55 | }); |
| 56 | |
Matteo Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 57 | nodes |
| 58 | .append('path') |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 59 | .attr({ |
Matteo Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 60 | class: d => `${d.type} antenna`, |
| 61 | opacity: 0, |
| 62 | d: () => TopologyElements.icons.bbu, |
Matteo Scandolo | e223b53 | 2016-03-04 08:31:20 -0800 | [diff] [blame] | 63 | transform: `translate(-18, -18)` |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 64 | }) |
| 65 | .transition() |
| 66 | .duration(duration) |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 67 | .attr({ |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 68 | opacity: 1 |
| 69 | }); |
| 70 | |
| 71 | nodes.append('text') |
| 72 | .attr({ |
| 73 | 'text-anchor': 'start', |
Matteo Scandolo | e223b53 | 2016-03-04 08:31:20 -0800 | [diff] [blame] | 74 | y: 25, |
Matteo Scandolo | d20e18f | 2016-03-03 11:35:26 -0800 | [diff] [blame] | 75 | x: 5, |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 76 | opacity: 0 |
| 77 | }) |
| 78 | .text(d => `BBU ${d.name.substr(d.name.length - 1, 1)}`) |
| 79 | .transition() |
| 80 | .duration(duration * 2) |
| 81 | .attr({ |
| 82 | opacity: 1 |
| 83 | }); |
| 84 | }; |
| 85 | |
| 86 | this.drawRrus = (nodes) => { |
| 87 | |
| 88 | nodes.append('circle') |
| 89 | .attr({ |
| 90 | class: d => `${d.type}-shadow`, |
| 91 | r: 0, |
| 92 | opacity: 0 |
| 93 | }) |
| 94 | .transition() |
| 95 | .duration(duration * 2) |
| 96 | // .delay((d, i) => i * (duration / 2)) |
| 97 | .attr({ |
Matteo Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 98 | r: 40, |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 99 | opacity: 1 |
| 100 | }); |
Matteo Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 101 | |
| 102 | nodes |
| 103 | .append('path') |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 104 | .attr({ |
Matteo Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 105 | class: d => `${d.type} antenna`, |
| 106 | opacity: 0, |
| 107 | d: () => TopologyElements.icons.rru, |
Matteo Scandolo | e223b53 | 2016-03-04 08:31:20 -0800 | [diff] [blame] | 108 | transform: `translate(-18, -18)` |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 109 | }) |
| 110 | .transition() |
| 111 | .duration(duration) |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 112 | .attr({ |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 113 | opacity: 1 |
| 114 | }); |
Matteo Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 115 | |
| 116 | // nodes.append('circle') |
| 117 | // .attr({ |
| 118 | // class: d => d.type, |
| 119 | // r: 0, |
| 120 | // opacity: 0 |
| 121 | // }) |
| 122 | // .transition() |
| 123 | // .duration(duration) |
| 124 | // // .delay((d, i) => i * (duration / 2)) |
| 125 | // .attr({ |
| 126 | // r: 10, |
| 127 | // opacity: 1 |
| 128 | // }); |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | this.drawFabric = (nodes) => { |
| 132 | nodes |
| 133 | .append('rect') |
| 134 | .attr({ |
| 135 | width: 30, |
| 136 | height: 30, |
| 137 | x: -15, |
| 138 | y: -15 |
| 139 | }); |
| 140 | |
| 141 | nodes |
| 142 | .append('path') |
| 143 | .attr({ |
| 144 | class: d => d.type, |
| 145 | opacity: 0, |
| 146 | d: () => TopologyElements.icons.switch, |
| 147 | transform: `translate(-22, -22), scale(0.4)` |
| 148 | }) |
| 149 | .transition() |
| 150 | .duration(duration) |
| 151 | // .delay((d, i) => i * (duration / 2)) |
| 152 | .attr({ |
| 153 | opacity: 1 |
| 154 | }); |
| 155 | }; |
| 156 | |
| 157 | this.drawOthers = (nodes) => { |
Matteo Scandolo | e223b53 | 2016-03-04 08:31:20 -0800 | [diff] [blame] | 158 | nodes.append('rect') |
| 159 | .attr({ |
| 160 | class: d => d.type, |
| 161 | width: 30, |
| 162 | height: 30, |
| 163 | x: -15, |
| 164 | y: -15, |
| 165 | opacity: 0 |
| 166 | }) |
| 167 | .transition() |
| 168 | .duration(duration) |
| 169 | .attr({ |
| 170 | r: 15, |
| 171 | opacity: 1 |
| 172 | }); |
| 173 | |
Matteo Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 174 | nodes |
| 175 | .append('path') |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 176 | .attr({ |
Matteo Scandolo | daae670 | 2016-02-26 13:42:50 -0800 | [diff] [blame] | 177 | class: d => `${d.type} antenna`, |
| 178 | opacity: 0, |
| 179 | d: () => TopologyElements.icons.bbu, |
Matteo Scandolo | e223b53 | 2016-03-04 08:31:20 -0800 | [diff] [blame] | 180 | transform: `translate(-18, -18)` |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 181 | }) |
| 182 | .transition() |
| 183 | .duration(duration) |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 184 | .attr({ |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 185 | opacity: 1 |
| 186 | }); |
| 187 | |
| 188 | nodes.append('text') |
| 189 | .attr({ |
| 190 | 'text-anchor': 'start', |
Matteo Scandolo | e223b53 | 2016-03-04 08:31:20 -0800 | [diff] [blame] | 191 | y: 25, |
| 192 | x: -12, |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 193 | opacity: 0 |
| 194 | }) |
Matteo Scandolo | 89667d3 | 2016-03-07 13:34:05 -0800 | [diff] [blame] | 195 | .text(d => d.name.toUpperCase()) |
Matteo Scandolo | df35ca9 | 2016-02-25 09:19:41 -0800 | [diff] [blame] | 196 | .transition() |
| 197 | .duration(duration * 2) |
| 198 | .attr({ |
| 199 | opacity: 1 |
| 200 | }); |
| 201 | |
| 202 | }; |
| 203 | |
| 204 | this.removeElements = (nodes) => { |
| 205 | nodes |
| 206 | .transition() |
| 207 | .duration(duration) |
| 208 | .attr({ |
| 209 | opacity: 0 |
| 210 | }) |
| 211 | .remove(); |
| 212 | }; |
| 213 | }); |