Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | ONOS GUI -- Topology Links Module. |
| 19 | Module that holds the links for a region |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
Steven Burrows | c515e60 | 2017-04-13 11:17:40 -0700 | [diff] [blame] | 25 | var $log, Collection, Model, ts, sus, t2zs, t2vs, t2lps, fn, ps, t2mss; |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 26 | |
| 27 | var linkLabelOffset = '0.35em'; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 28 | |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 29 | var widthRatio = 1.4, |
| 30 | linkScale = d3.scale.linear() |
| 31 | .domain([1, 12]) |
| 32 | .range([widthRatio, 12 * widthRatio]) |
| 33 | .clamp(true), |
Steven Burrows | a3fca81 | 2016-10-14 15:11:04 -0500 | [diff] [blame] | 34 | labelDim = 30; |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 35 | |
| 36 | // configuration |
| 37 | var linkConfig = { |
| 38 | light: { |
| 39 | baseColor: '#939598', |
| 40 | inColor: '#66f', |
| 41 | outColor: '#f00' |
| 42 | }, |
| 43 | dark: { |
| 44 | // TODO : theme |
| 45 | baseColor: '#939598', |
| 46 | inColor: '#66f', |
| 47 | outColor: '#f00' |
| 48 | }, |
| 49 | inWidth: 12, |
| 50 | outWidth: 10 |
| 51 | }; |
| 52 | |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 53 | function createLink() { |
| 54 | |
| 55 | var linkPoints = this.linkEndPoints(this.get('epA'), this.get('epB')); |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 56 | |
| 57 | var attrs = angular.extend({}, linkPoints, { |
| 58 | key: this.get('id'), |
| 59 | class: 'link', |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 60 | position: { |
| 61 | x1: 0, |
| 62 | y1: 0, |
| 63 | x2: 0, |
| 64 | y2: 0 |
| 65 | } |
| 66 | // functions to aggregate dual link state |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 67 | // extra: link.extra |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 68 | }); |
| 69 | |
| 70 | this.set(attrs); |
| 71 | } |
| 72 | |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 73 | function rectAroundText(el) { |
| 74 | var text = el.select('text'), |
| 75 | box = text.node().getBBox(); |
| 76 | |
| 77 | // translate the bbox so that it is centered on [x,y] |
| 78 | box.x = -box.width / 2; |
| 79 | box.y = -box.height / 2; |
| 80 | |
| 81 | // add padding |
| 82 | box.x -= 4; |
| 83 | box.width += 8; |
| 84 | return box; |
| 85 | } |
| 86 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 87 | function isLinkOnline(node) { |
| 88 | return (node.get('nodeType') === 'region') ? true : node.get('online'); |
| 89 | } |
| 90 | |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 91 | function linkEndPoints(srcId, dstId) { |
| 92 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 93 | var findNodeById = this.region.model.findNodeById.bind(this.region), |
| 94 | allNodes = this.region.model.nodes(), |
| 95 | sourceNode = findNodeById(this, srcId), |
| 96 | targetNode = findNodeById(this, dstId); |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 97 | |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame] | 98 | if (!sourceNode || !targetNode) { |
Steven Burrows | 8f45ce2 | 2016-10-27 20:04:14 -0500 | [diff] [blame] | 99 | $log.error('Node(s) not on map for link:' + srcId + '~' + dstId); |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 100 | // logicError('Node(s) not on map for link:\n' + sMiss + dMiss); |
Steven Burrows | 6deb4ce | 2016-08-26 16:06:23 +0100 | [diff] [blame] | 101 | return null; |
| 102 | } |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 103 | |
Steven Burrows | a3fca81 | 2016-10-14 15:11:04 -0500 | [diff] [blame] | 104 | this.source = allNodes.indexOf(sourceNode); |
| 105 | this.target = allNodes.indexOf(targetNode); |
| 106 | this.sourceNode = sourceNode; |
| 107 | this.targetNode = targetNode; |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 108 | |
| 109 | return { |
| 110 | source: sourceNode, |
| 111 | target: targetNode |
| 112 | }; |
| 113 | } |
| 114 | |
| 115 | function createLinkCollection(data, _region) { |
| 116 | |
| 117 | var LinkModel = Model.extend({ |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 118 | initialize: function () { |
| 119 | this.super = this.constructor.__super__; |
| 120 | this.super.initialize.apply(this, arguments); |
| 121 | this.createLink(); |
| 122 | }, |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 123 | region: _region, |
| 124 | createLink: createLink, |
| 125 | linkEndPoints: linkEndPoints, |
| 126 | type: function () { |
| 127 | return this.get('type'); |
| 128 | }, |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 129 | svgClassName: function () { |
| 130 | return fn.classNames('link', |
| 131 | this.nodeType, |
| 132 | this.get('type'), |
| 133 | { |
| 134 | enhanced: this.get('enhanced'), |
Steven Burrows | c515e60 | 2017-04-13 11:17:40 -0700 | [diff] [blame] | 135 | selected: this.get('selected'), |
| 136 | suppressedmax: this.get('mastership') |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 137 | } |
| 138 | ); |
| 139 | }, |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 140 | expected: function () { |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 141 | // TODO: original code is: (s && s.expected) && (t && t.expected); |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 142 | return true; |
| 143 | }, |
| 144 | online: function () { |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 145 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 146 | var source = this.get('source'), |
| 147 | target = this.get('target'), |
| 148 | sourceOnline = isLinkOnline(source), |
| 149 | targetOnline = isLinkOnline(target); |
| 150 | |
| 151 | return (sourceOnline) && (targetOnline); |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 152 | }, |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 153 | onChange: function () { |
| 154 | // Update class names when the model changes |
| 155 | if (this.el) { |
| 156 | this.el.attr('class', this.svgClassName()); |
| 157 | } |
| 158 | }, |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 159 | enhance: function () { |
| 160 | var data = [], |
| 161 | point; |
| 162 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 163 | if (showPort()) { |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 164 | this.set('enhanced', true); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 165 | point = this.locatePortLabel(); |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 166 | angular.extend(point, { |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 167 | id: 'topo2-port-tgt', |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 168 | num: this.get('portB') |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 169 | }); |
| 170 | data.push(point); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 171 | |
| 172 | if (this.get('portA')) { |
| 173 | point = this.locatePortLabel(1); |
| 174 | angular.extend(point, { |
Simon Hunt | 95f4b42 | 2017-03-03 13:49:05 -0800 | [diff] [blame] | 175 | id: 'topo2-port-src', |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 176 | num: this.get('portA') |
| 177 | }); |
| 178 | data.push(point); |
| 179 | } |
| 180 | |
Steven Burrows | bd40284 | 2017-03-08 21:30:38 +0000 | [diff] [blame] | 181 | var entering = d3.select('.topo2-portLabels') |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 182 | .selectAll('.portLabel') |
Steven Burrows | a3fca81 | 2016-10-14 15:11:04 -0500 | [diff] [blame] | 183 | .data(data) |
| 184 | .enter().append('g') |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 185 | .classed('portLabel', true) |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 186 | .attr('id', function (d) { return d.id; }); |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 187 | |
| 188 | entering.each(function (d) { |
| 189 | var el = d3.select(this), |
| 190 | rect = el.append('rect'), |
| 191 | text = el.append('text').text(d.num); |
| 192 | |
| 193 | var rectSize = rectAroundText(el); |
| 194 | |
| 195 | rect.attr(rectSize) |
| 196 | .attr('rx', 2) |
| 197 | .attr('ry', 2); |
| 198 | |
| 199 | text.attr('dy', linkLabelOffset) |
| 200 | .attr('text-anchor', 'middle'); |
| 201 | |
| 202 | el.attr('transform', sus.translate(d.x, d.y)); |
Steven Burrows | a3fca81 | 2016-10-14 15:11:04 -0500 | [diff] [blame] | 203 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 204 | }); |
Steven Burrows | a3fca81 | 2016-10-14 15:11:04 -0500 | [diff] [blame] | 205 | |
| 206 | this.setScale(); |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 207 | } |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 208 | }, |
| 209 | unenhance: function () { |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 210 | this.set('enhanced', false); |
Steven Burrows | bd40284 | 2017-03-08 21:30:38 +0000 | [diff] [blame] | 211 | d3.select('.topo2-portLabels').selectAll('.portLabel').remove(); |
Steven Burrows | 0bc6665 | 2017-04-20 13:04:10 -0400 | [diff] [blame] | 212 | this.setScale(); |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 213 | }, |
Steven Burrows | 32ce1d9 | 2017-04-13 13:18:44 -0700 | [diff] [blame] | 214 | amt: function (numLinks, index) { |
Steven Burrows | 9ce0e40 | 2017-04-20 16:39:17 -0400 | [diff] [blame] | 215 | var bbox = this.get('source').el.node().getBBox(), |
| 216 | gap = bbox.width / 4; |
Steven Burrows | 32ce1d9 | 2017-04-13 13:18:44 -0700 | [diff] [blame] | 217 | return (index - ((numLinks - 1) / 2)) * gap; |
| 218 | }, |
| 219 | defaultPosition: function () { |
| 220 | return { |
| 221 | x1: this.get('source').x, |
| 222 | y1: this.get('source').y, |
| 223 | x2: this.get('target').x, |
| 224 | y2: this.get('target').y |
| 225 | } |
| 226 | }, |
| 227 | calcMovement: function (amt, flipped) { |
| 228 | var pos = this.defaultPosition(), |
| 229 | mult = flipped ? -amt : amt, |
| 230 | dx = pos.x2 - pos.x1, |
| 231 | dy = pos.y2 - pos.y1, |
| 232 | length = Math.sqrt((dx * dx) + (dy * dy)); |
| 233 | |
| 234 | return { |
| 235 | x1: pos.x1 + (mult * dy / length), |
| 236 | y1: pos.y1 + (mult * -dx / length), |
| 237 | x2: pos.x2 + (mult * dy / length), |
| 238 | y2: pos.y2 + (mult * -dx / length) |
| 239 | }; |
| 240 | }, |
Steven Burrows | a31c5b0 | 2017-04-12 10:45:08 -0700 | [diff] [blame] | 241 | setPosition: function () { |
Steven Burrows | 32ce1d9 | 2017-04-13 13:18:44 -0700 | [diff] [blame] | 242 | |
| 243 | var multiline = this.get('multiline'); |
| 244 | if (multiline) { |
| 245 | var offsetAmt = this.amt(multiline.deviceLinks, multiline.index); |
| 246 | this.set('position', this.calcMovement(offsetAmt)); |
| 247 | } else { |
| 248 | this.set('position', this.defaultPosition()); |
| 249 | } |
Steven Burrows | a31c5b0 | 2017-04-12 10:45:08 -0700 | [diff] [blame] | 250 | |
| 251 | if (this.get('enhanced')) { |
| 252 | this.updatePortPosition(); |
| 253 | } |
Steven Burrows | 9ce0e40 | 2017-04-20 16:39:17 -0400 | [diff] [blame] | 254 | |
| 255 | if (this.el) { |
| 256 | this.el.attr(this.get('position')); |
| 257 | } |
| 258 | |
Steven Burrows | a31c5b0 | 2017-04-12 10:45:08 -0700 | [diff] [blame] | 259 | }, |
| 260 | updatePortPosition: function () { |
| 261 | var sourcePos = this.locatePortLabel(1), |
| 262 | targetPos = this.locatePortLabel(); |
| 263 | d3.select('#topo2-port-src') |
| 264 | .attr('transform', sus.translate(sourcePos.x, sourcePos.y)); |
| 265 | d3.select('#topo2-port-tgt') |
| 266 | .attr('transform', sus.translate(targetPos.x, targetPos.y)); |
| 267 | }, |
Steven Burrows | 1aa4f58 | 2016-12-13 15:05:41 -0500 | [diff] [blame] | 268 | getSelected: function () { |
| 269 | return this.collection.filter(function (m) { |
| 270 | return m.get('selected'); |
| 271 | }); |
| 272 | }, |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 273 | select: function () { |
Steven Burrows | 5fa057e | 2017-03-15 17:07:56 +0000 | [diff] [blame] | 274 | this.set({ 'selected': true }); |
Steven Burrows | 1aa4f58 | 2016-12-13 15:05:41 -0500 | [diff] [blame] | 275 | return this.getSelected(); |
| 276 | }, |
| 277 | deselect: function () { |
Steven Burrows | 5fa057e | 2017-03-15 17:07:56 +0000 | [diff] [blame] | 278 | this.set({ |
| 279 | 'selected': false, |
| 280 | 'enhanced': false |
| 281 | }); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 282 | }, |
| 283 | showDetails: function () { |
Steven Burrows | 1aa4f58 | 2016-12-13 15:05:41 -0500 | [diff] [blame] | 284 | var selected = this.getSelected(); |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 285 | |
| 286 | if (selected) { |
| 287 | t2lps.displayLink(this); |
| 288 | } else { |
| 289 | t2lps.hide(); |
| 290 | } |
| 291 | }, |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 292 | locatePortLabel: function (src) { |
Steven Burrows | a3fca81 | 2016-10-14 15:11:04 -0500 | [diff] [blame] | 293 | var offset = 32 / (labelDim * t2zs.scale()), |
| 294 | sourceX = this.get('position').x1, |
| 295 | sourceY = this.get('position').y1, |
| 296 | targetX = this.get('position').x2, |
| 297 | targetY = this.get('position').y2, |
| 298 | nearX = src ? sourceX : targetX, |
| 299 | nearY = src ? sourceY : targetY, |
| 300 | farX = src ? targetX : sourceX, |
| 301 | farY = src ? targetY : sourceY; |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 302 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 303 | function dist(x, y) { |
| 304 | return Math.sqrt(x * x + y * y); |
| 305 | } |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 306 | |
| 307 | var dx = farX - nearX, |
| 308 | dy = farY - nearY, |
Steven Burrows | 0bc6665 | 2017-04-20 13:04:10 -0400 | [diff] [blame] | 309 | k = (32 * offset) / dist(dx, dy); |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 310 | |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 311 | return { x: k * dx + nearX, y: k * dy + nearY }; |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 312 | }, |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 313 | onEnter: function (el) { |
Steven Burrows | 448468c | 2017-04-13 16:09:30 -0700 | [diff] [blame] | 314 | var link = d3.select(el), |
| 315 | th = ts.theme(), |
| 316 | delay = 1000; |
Steven Burrows | 9edc7e0 | 2016-08-29 11:52:07 +0100 | [diff] [blame] | 317 | |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 318 | this.el = link; |
Steven Burrows | 448468c | 2017-04-13 16:09:30 -0700 | [diff] [blame] | 319 | |
| 320 | link.transition() |
| 321 | .duration(delay) |
| 322 | .attr('stroke', linkConfig[th].baseColor); |
| 323 | |
Steven Burrows | aea509d | 2017-04-12 14:17:47 -0700 | [diff] [blame] | 324 | this.setVisibility(); |
Steven Burrows | 448468c | 2017-04-13 16:09:30 -0700 | [diff] [blame] | 325 | this.setScale(); |
Steven Burrows | 0616e80 | 2016-10-06 21:45:07 -0500 | [diff] [blame] | 326 | }, |
| 327 | setScale: function () { |
Steven Burrows | e8a455a | 2017-03-16 16:58:59 +0000 | [diff] [blame] | 328 | |
| 329 | if (!this.el) return; |
| 330 | |
Steven Burrows | 0bc6665 | 2017-04-20 13:04:10 -0400 | [diff] [blame] | 331 | var linkWidthRatio = this.get('enhanced') ? 3.5 : widthRatio; |
| 332 | |
| 333 | var width = linkScale(linkWidthRatio) / t2zs.scale(); |
Steven Burrows | 448468c | 2017-04-13 16:09:30 -0700 | [diff] [blame] | 334 | this.el.attr('stroke-width', width + 'px'); |
Steven Burrows | a3fca81 | 2016-10-14 15:11:04 -0500 | [diff] [blame] | 335 | |
| 336 | var labelScale = labelDim / (labelDim * t2zs.scale()); |
| 337 | |
Steven Burrows | 8909c5c | 2017-04-10 09:56:52 -0700 | [diff] [blame] | 338 | d3.select('.topo2-portLabels') |
Steven Burrows | a3fca81 | 2016-10-14 15:11:04 -0500 | [diff] [blame] | 339 | .selectAll('.portLabel') |
| 340 | .selectAll('*') |
| 341 | .style('transform', 'scale(' + labelScale + ')'); |
| 342 | |
Steven Burrows | 9ce0e40 | 2017-04-20 16:39:17 -0400 | [diff] [blame] | 343 | this.setPosition(); |
| 344 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 345 | }, |
| 346 | update: function () { |
Steven Burrows | 86af435 | 2016-11-16 18:19:12 -0600 | [diff] [blame] | 347 | if (this.get('enhanced')) { |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 348 | this.enhance(); |
| 349 | } |
Steven Burrows | b15a394 | 2017-01-17 17:25:04 +0000 | [diff] [blame] | 350 | }, |
Steven Burrows | aea509d | 2017-04-12 14:17:47 -0700 | [diff] [blame] | 351 | setVisibility: function () { |
| 352 | |
| 353 | if (this.get('type') !== 'UiEdgeLink') { |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | var visible = ps.getPrefs('topo2_prefs')['hosts']; |
| 358 | this.el.style('visibility', visible ? 'visible' : 'hidden'); |
| 359 | }, |
Steven Burrows | c515e60 | 2017-04-13 11:17:40 -0700 | [diff] [blame] | 360 | displayMastership: function () { |
| 361 | this.set({ mastership: t2mss.mastership() !== null}); |
| 362 | }, |
Steven Burrows | b15a394 | 2017-01-17 17:25:04 +0000 | [diff] [blame] | 363 | remove: function () { |
| 364 | |
| 365 | var width = linkScale(widthRatio) / t2zs.scale(); |
| 366 | |
| 367 | this.el.transition() |
| 368 | .duration(300) |
| 369 | .attr('stroke', '#ff0000') |
| 370 | .style('stroke-width', width * 4) |
| 371 | .transition() |
| 372 | .delay(1000) |
| 373 | .style('opacity', 0); |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 374 | } |
| 375 | }); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 376 | |
| 377 | var LinkCollection = Collection.extend({ |
Steven Burrows | dfa52b0 | 2016-09-02 13:50:43 +0100 | [diff] [blame] | 378 | model: LinkModel |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 379 | }); |
| 380 | |
| 381 | return new LinkCollection(data); |
| 382 | } |
| 383 | |
Steven Burrows | 1c5c861 | 2016-10-05 13:45:13 -0500 | [diff] [blame] | 384 | function showPort() { |
| 385 | return t2vs.getPortHighlighting(); |
| 386 | } |
| 387 | |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 388 | angular.module('ovTopo2') |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 389 | .factory('Topo2LinkService', [ |
| 390 | '$log', 'Topo2Collection', 'Topo2Model', |
Steven Burrows | 0616e80 | 2016-10-06 21:45:07 -0500 | [diff] [blame] | 391 | 'ThemeService', 'SvgUtilService', 'Topo2ZoomService', |
Steven Burrows | aea509d | 2017-04-12 14:17:47 -0700 | [diff] [blame] | 392 | 'Topo2ViewService', 'Topo2LinkPanelService', 'FnService', 'PrefsService', |
Steven Burrows | c515e60 | 2017-04-13 11:17:40 -0700 | [diff] [blame] | 393 | 'Topo2MastershipService', |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 394 | function (_$log_, _c_, _Model_, _ts_, _sus_, |
Steven Burrows | c515e60 | 2017-04-13 11:17:40 -0700 | [diff] [blame] | 395 | _t2zs_, _t2vs_, _t2lps_, _fn_, _ps_, _t2mss_) { |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 396 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 397 | $log = _$log_; |
| 398 | ts = _ts_; |
| 399 | sus = _sus_; |
| 400 | t2zs = _t2zs_; |
| 401 | t2vs = _t2vs_; |
| 402 | Collection = _c_; |
| 403 | Model = _Model_; |
| 404 | t2lps = _t2lps_; |
| 405 | fn = _fn_; |
Steven Burrows | aea509d | 2017-04-12 14:17:47 -0700 | [diff] [blame] | 406 | ps = _ps_; |
Steven Burrows | c515e60 | 2017-04-13 11:17:40 -0700 | [diff] [blame] | 407 | t2mss = _t2mss_; |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 408 | |
Steven Burrows | af96a21 | 2016-12-28 12:57:02 +0000 | [diff] [blame] | 409 | return { |
| 410 | createLinkCollection: createLinkCollection |
| 411 | }; |
| 412 | } |
| 413 | ]); |
Steven Burrows | 57e24e9 | 2016-08-04 18:38:24 +0100 | [diff] [blame] | 414 | })(); |