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