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 | |
| 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 | |
| 55 | nodes.append('text') |
| 56 | .attr({ |
| 57 | 'text-anchor': 'start', |
| 58 | y: 17, |
| 59 | x: 17, |
| 60 | opacity: 0 |
| 61 | }) |
| 62 | .text(d => `BBU ${d.name.substr(d.name.length - 1, 1)}`) |
| 63 | .transition() |
| 64 | .duration(duration * 2) |
| 65 | .attr({ |
| 66 | opacity: 1 |
| 67 | }); |
| 68 | }; |
| 69 | |
| 70 | this.drawRrus = (nodes) => { |
| 71 | |
| 72 | nodes.append('circle') |
| 73 | .attr({ |
| 74 | class: d => `${d.type}-shadow`, |
| 75 | 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 |
| 84 | }); |
| 85 | |
| 86 | nodes.append('circle') |
| 87 | .attr({ |
| 88 | class: d => d.type, |
| 89 | 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 |
| 98 | }); |
| 99 | }; |
| 100 | |
| 101 | this.drawFabric = (nodes) => { |
| 102 | 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') |
| 113 | .attr({ |
| 114 | class: d => d.type, |
| 115 | opacity: 0, |
| 116 | d: () => TopologyElements.icons.switch, |
| 117 | transform: `translate(-22, -22), scale(0.4)` |
| 118 | }) |
| 119 | .transition() |
| 120 | .duration(duration) |
| 121 | // .delay((d, i) => i * (duration / 2)) |
| 122 | .attr({ |
| 123 | opacity: 1 |
| 124 | }); |
| 125 | }; |
| 126 | |
| 127 | this.drawOthers = (nodes) => { |
| 128 | nodes.append('circle') |
| 129 | .attr({ |
| 130 | class: d => d.type, |
| 131 | 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 |
| 140 | }); |
| 141 | |
| 142 | nodes.append('text') |
| 143 | .attr({ |
| 144 | 'text-anchor': 'start', |
| 145 | y: 17, |
| 146 | x: 17, |
| 147 | opacity: 0 |
| 148 | }) |
| 149 | .text(d => d.type) |
| 150 | .transition() |
| 151 | .duration(duration * 2) |
| 152 | .attr({ |
| 153 | opacity: 1 |
| 154 | }); |
| 155 | |
| 156 | }; |
| 157 | |
| 158 | this.removeElements = (nodes) => { |
| 159 | nodes |
| 160 | .transition() |
| 161 | .duration(duration) |
| 162 | .attr({ |
| 163 | opacity: 0 |
| 164 | }) |
| 165 | .remove(); |
| 166 | }; |
| 167 | }); |