Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 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 Link Module. |
| 19 | Functions for highlighting/selecting links |
| 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
| 25 | // injected refs |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame] | 26 | var $log, fs, flash, tss; |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 27 | |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 28 | // internal state |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 29 | var api, |
Simon Hunt | 1a5301e | 2015-02-25 15:31:25 -0800 | [diff] [blame] | 30 | td3, |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 31 | network, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 32 | showPorts = true, // enable port highlighting by default |
| 33 | enhancedLink = null, // the link over which the mouse is hovering |
| 34 | selectedLinks = {}; // the links which are already selected |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 35 | |
| 36 | // SVG elements; |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 37 | var svg; |
| 38 | |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 39 | // function to be replaced by the localization bundle function |
| 40 | var topoLion = function (x) { |
| 41 | return '#tlink#' + x + '#'; |
| 42 | }; |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 43 | |
| 44 | // ======== ALGORITHM TO FIND LINK CLOSEST TO MOUSE ======== |
| 45 | |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 46 | function getLogicalMousePosition(container) { |
| 47 | var m = d3.mouse(container), |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 48 | sc = api.zoomer.scale(), |
| 49 | tr = api.zoomer.translate(), |
| 50 | mx = (m[0] - tr[0]) / sc, |
| 51 | my = (m[1] - tr[1]) / sc; |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 52 | return { x: mx, y: my }; |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Simon Hunt | 5aac2fc | 2015-06-09 12:34:07 -0700 | [diff] [blame] | 55 | |
| 56 | function sq(x) { return x * x; } |
| 57 | |
| 58 | function mdist(p, m) { |
| 59 | return Math.sqrt(sq(p.x - m.x) + sq(p.y - m.y)); |
| 60 | } |
| 61 | |
| 62 | function prox(dist) { |
| 63 | return dist / api.zoomer.scale(); |
| 64 | } |
| 65 | |
| 66 | function computeNearestNode(mouse) { |
| 67 | var proximity = prox(30), |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 68 | nearest = null, |
| 69 | minDist; |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 70 | |
Simon Hunt | 5aac2fc | 2015-06-09 12:34:07 -0700 | [diff] [blame] | 71 | if (network.nodes.length) { |
| 72 | minDist = proximity * 2; |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 73 | |
Simon Hunt | 5aac2fc | 2015-06-09 12:34:07 -0700 | [diff] [blame] | 74 | network.nodes.forEach(function (d) { |
| 75 | var dist; |
| 76 | |
| 77 | if (!api.showHosts() && d.class === 'host') { |
| 78 | return; // skip hidden hosts |
| 79 | } |
| 80 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 81 | dist = mdist({ x: d.x, y: d.y }, mouse); |
Simon Hunt | 5aac2fc | 2015-06-09 12:34:07 -0700 | [diff] [blame] | 82 | if (dist < minDist && dist < proximity) { |
| 83 | minDist = dist; |
| 84 | nearest = d; |
| 85 | } |
| 86 | }); |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 87 | } |
Simon Hunt | 5aac2fc | 2015-06-09 12:34:07 -0700 | [diff] [blame] | 88 | return nearest; |
| 89 | } |
| 90 | |
| 91 | |
| 92 | function computeNearestLink(mouse) { |
| 93 | var proximity = prox(30), |
| 94 | nearest = null, |
| 95 | minDist; |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 96 | |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 97 | function pdrop(line, mouse) { |
| 98 | var x1 = line.x1, |
| 99 | y1 = line.y1, |
| 100 | x2 = line.x2, |
| 101 | y2 = line.y2, |
| 102 | x3 = mouse.x, |
| 103 | y3 = mouse.y, |
| 104 | k = ((y2-y1) * (x3-x1) - (x2-x1) * (y3-y1)) / |
| 105 | (sq(y2-y1) + sq(x2-x1)), |
| 106 | x4 = x3 - k * (y2-y1), |
| 107 | y4 = y3 + k * (x2-x1); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 108 | return { x: x4, y: y4 }; |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 111 | function lineHit(line, p, m) { |
| 112 | if (p.x < line.x1 && p.x < line.x2) return false; |
| 113 | if (p.x > line.x1 && p.x > line.x2) return false; |
| 114 | if (p.y < line.y1 && p.y < line.y2) return false; |
| 115 | if (p.y > line.y1 && p.y > line.y2) return false; |
Simon Hunt | 5f36108 | 2015-02-25 11:36:38 -0800 | [diff] [blame] | 116 | // line intersects, but are we close enough? |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 117 | return mdist(p, m) <= proximity; |
| 118 | } |
| 119 | |
| 120 | if (network.links.length) { |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 121 | minDist = proximity * 2; |
| 122 | |
| 123 | network.links.forEach(function (d) { |
Simon Hunt | f976145 | 2016-11-19 09:06:17 -0800 | [diff] [blame] | 124 | var line = d.position, |
| 125 | point, |
| 126 | hit, |
| 127 | dist; |
| 128 | |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 129 | if (!api.showHosts() && d.type() === 'hostLink') { |
| 130 | return; // skip hidden host links |
| 131 | } |
| 132 | |
Simon Hunt | f976145 | 2016-11-19 09:06:17 -0800 | [diff] [blame] | 133 | if (line) { |
| 134 | point = pdrop(line, mouse); |
| 135 | hit = lineHit(line, point, mouse); |
| 136 | if (hit) { |
| 137 | dist = mdist(point, mouse); |
| 138 | if (dist < minDist) { |
| 139 | minDist = dist; |
| 140 | nearest = d; |
| 141 | } |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 142 | } |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 143 | } |
| 144 | }); |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 145 | } |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 146 | return nearest; |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 149 | function enhanceLink(ldata) { |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 150 | // if the new link is same as old link, do nothing |
| 151 | if (enhancedLink && ldata && enhancedLink.key === ldata.key) return; |
| 152 | |
| 153 | // first, unenhance the currently enhanced link |
| 154 | if (enhancedLink) { |
| 155 | unenhance(enhancedLink); |
| 156 | } |
| 157 | enhancedLink = ldata; |
| 158 | if (enhancedLink) { |
| 159 | enhance(enhancedLink); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | function unenhance(d) { |
Simon Hunt | 969b3c9 | 2015-02-25 18:11:31 -0800 | [diff] [blame] | 164 | // guard against link element not set |
| 165 | if (d.el) { |
| 166 | d.el.classed('enhanced', false); |
| 167 | } |
Simon Hunt | 1a5301e | 2015-02-25 15:31:25 -0800 | [diff] [blame] | 168 | api.portLabelG().selectAll('.portLabel').remove(); |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | function enhance(d) { |
Simon Hunt | 969b3c9 | 2015-02-25 18:11:31 -0800 | [diff] [blame] | 172 | var data = [], |
| 173 | point; |
| 174 | |
| 175 | // guard against link element not set |
| 176 | if (!d.el) return; |
| 177 | |
Simon Hunt | d526412 | 2015-02-25 10:17:43 -0800 | [diff] [blame] | 178 | d.el.classed('enhanced', true); |
Simon Hunt | 1a5301e | 2015-02-25 15:31:25 -0800 | [diff] [blame] | 179 | |
Simon Hunt | 8ae474b | 2015-02-25 15:39:14 -0800 | [diff] [blame] | 180 | // Define port label data objects. |
| 181 | // NOTE: src port is absent in the case of host-links. |
| 182 | |
Simon Hunt | 969b3c9 | 2015-02-25 18:11:31 -0800 | [diff] [blame] | 183 | point = locatePortLabel(d); |
| 184 | angular.extend(point, { |
Simon Hunt | 8ae474b | 2015-02-25 15:39:14 -0800 | [diff] [blame] | 185 | id: 'topo-port-tgt', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 186 | num: d.tgtPort, |
Simon Hunt | 969b3c9 | 2015-02-25 18:11:31 -0800 | [diff] [blame] | 187 | }); |
| 188 | data.push(point); |
Simon Hunt | 8ae474b | 2015-02-25 15:39:14 -0800 | [diff] [blame] | 189 | |
| 190 | if (d.srcPort) { |
Simon Hunt | 969b3c9 | 2015-02-25 18:11:31 -0800 | [diff] [blame] | 191 | point = locatePortLabel(d, 1); |
| 192 | angular.extend(point, { |
Simon Hunt | 1a5301e | 2015-02-25 15:31:25 -0800 | [diff] [blame] | 193 | id: 'topo-port-src', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 194 | num: d.srcPort, |
Simon Hunt | 8ae474b | 2015-02-25 15:39:14 -0800 | [diff] [blame] | 195 | }); |
Simon Hunt | 969b3c9 | 2015-02-25 18:11:31 -0800 | [diff] [blame] | 196 | data.push(point); |
Simon Hunt | 8ae474b | 2015-02-25 15:39:14 -0800 | [diff] [blame] | 197 | } |
Simon Hunt | 1a5301e | 2015-02-25 15:31:25 -0800 | [diff] [blame] | 198 | |
| 199 | td3.applyPortLabels(data, api.portLabelG()); |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Simon Hunt | 969b3c9 | 2015-02-25 18:11:31 -0800 | [diff] [blame] | 202 | function locatePortLabel(link, src) { |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 203 | var offset = 32, |
| 204 | pos = link.position, |
| 205 | nearX = src ? pos.x1 : pos.x2, |
Steven Burrows | aefd586 | 2016-10-19 14:20:46 -0500 | [diff] [blame] | 206 | nearY = src ? pos.y1 : pos.y2, |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 207 | farX = src ? pos.x2 : pos.x1, |
Steven Burrows | aefd586 | 2016-10-19 14:20:46 -0500 | [diff] [blame] | 208 | farY = src ? pos.y2 : pos.y1; |
Simon Hunt | 969b3c9 | 2015-02-25 18:11:31 -0800 | [diff] [blame] | 209 | |
| 210 | function dist(x, y) { return Math.sqrt(x*x + y*y); } |
| 211 | |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 212 | var dx = farX - nearX, |
| 213 | dy = farY - nearY, |
Simon Hunt | 969b3c9 | 2015-02-25 18:11:31 -0800 | [diff] [blame] | 214 | k = offset / dist(dx, dy); |
| 215 | |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 216 | return { x: k * dx + nearX, y: k * dy + nearY }; |
Simon Hunt | 969b3c9 | 2015-02-25 18:11:31 -0800 | [diff] [blame] | 217 | } |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 218 | |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 219 | function selectLink(ldata) { |
| 220 | // if the new link is same as old link, do nothing |
Prince Pereira | 46c82d4 | 2016-09-19 13:30:50 +0530 | [diff] [blame] | 221 | if (d3.event.shiftKey && ldata.el.classed('selected')) { |
| 222 | unselLink(ldata); |
| 223 | return; |
| 224 | } |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 225 | |
Prince Pereira | 46c82d4 | 2016-09-19 13:30:50 +0530 | [diff] [blame] | 226 | if (d3.event.shiftKey && !ldata.el.classed('selected')) { |
| 227 | selLink(ldata); |
| 228 | return; |
| 229 | } |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 230 | |
Prince Pereira | 46c82d4 | 2016-09-19 13:30:50 +0530 | [diff] [blame] | 231 | tss.deselectAll(); |
| 232 | |
Simon Hunt | f976145 | 2016-11-19 09:06:17 -0800 | [diff] [blame] | 233 | if (ldata) { |
Kavitha Alagesan | 21314f0 | 2016-11-17 11:59:11 +0530 | [diff] [blame] | 234 | if (ldata.el.classed('selected')) { |
| 235 | unselLink(ldata); |
Simon Hunt | f976145 | 2016-11-19 09:06:17 -0800 | [diff] [blame] | 236 | } else { |
| 237 | selLink(ldata); |
Kavitha Alagesan | 21314f0 | 2016-11-17 11:59:11 +0530 | [diff] [blame] | 238 | } |
Prince Pereira | 46c82d4 | 2016-09-19 13:30:50 +0530 | [diff] [blame] | 239 | } |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | function unselLink(d) { |
| 243 | // guard against link element not set |
| 244 | if (d.el) { |
| 245 | d.el.classed('selected', false); |
Prince Pereira | 46c82d4 | 2016-09-19 13:30:50 +0530 | [diff] [blame] | 246 | delete selectedLinks[d.key]; |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
| 250 | function selLink(d) { |
| 251 | // guard against link element not set |
| 252 | if (!d.el) return; |
| 253 | |
| 254 | d.el.classed('selected', true); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 255 | selectedLinks[d.key] = { key: d }; |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 256 | |
Simon Hunt | a58d894 | 2017-08-11 12:51:14 -0700 | [diff] [blame] | 257 | // TODO: deprecate tov.hooks.modifyLinkData |
| 258 | // tps.displayLink(d, tov.hooks.modifyLinkData); |
| 259 | // tps.displaySomething(); |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | // ====== MOUSE EVENT HANDLERS ====== |
| 263 | |
| 264 | function mouseMoveHandler() { |
| 265 | var mp = getLogicalMousePosition(this), |
| 266 | link = computeNearestLink(mp); |
| 267 | enhanceLink(link); |
| 268 | } |
| 269 | |
| 270 | function mouseClickHandler() { |
Simon Hunt | 5aac2fc | 2015-06-09 12:34:07 -0700 | [diff] [blame] | 271 | var mp, link, node; |
Prince Pereira | 46c82d4 | 2016-09-19 13:30:50 +0530 | [diff] [blame] | 272 | if (!d3.event.shiftKey) { |
| 273 | deselectAllLinks(); |
| 274 | } |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 275 | |
| 276 | if (!tss.clickConsumed()) { |
| 277 | mp = getLogicalMousePosition(this); |
Simon Hunt | 5aac2fc | 2015-06-09 12:34:07 -0700 | [diff] [blame] | 278 | node = computeNearestNode(mp); |
| 279 | if (node) { |
| 280 | $log.debug('found nearest node:', node.labels[1]); |
| 281 | tss.selectObject(node); |
| 282 | } else { |
| 283 | link = computeNearestLink(mp); |
| 284 | selectLink(link); |
Prince Pereira | 46c82d4 | 2016-09-19 13:30:50 +0530 | [diff] [blame] | 285 | tss.selectObject(link); |
Simon Hunt | 5aac2fc | 2015-06-09 12:34:07 -0700 | [diff] [blame] | 286 | } |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
| 290 | |
| 291 | // ====================== |
| 292 | |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 293 | function togglePorts(x) { |
| 294 | var kev = (x === 'keyev'), |
| 295 | on = kev ? !showPorts : !!x, |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 296 | what = on ? topoLion('enable') : topoLion('disable'), |
| 297 | philite = topoLion('fl_port_highlighting'), |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 298 | handler = on ? mouseMoveHandler : null; |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 299 | |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 300 | showPorts = on; |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 301 | |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 302 | if (!on) { |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 303 | enhanceLink(null); |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 304 | } |
| 305 | svg.on('mousemove', handler); |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 306 | flash.flash(what + ' ' + philite); |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 307 | return on; |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 308 | } |
| 309 | |
Prince Pereira | 46c82d4 | 2016-09-19 13:30:50 +0530 | [diff] [blame] | 310 | function deselectAllLinks() { |
| 311 | |
| 312 | if (Object.keys(selectedLinks).length > 0) { |
| 313 | network.links.forEach(function (d) { |
| 314 | if (selectedLinks[d.key]) { |
| 315 | unselLink(d); |
| 316 | } |
| 317 | }); |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 318 | } |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 321 | // invoked after the localization bundle has been received from the server |
| 322 | function setLionBundle(bundle) { |
| 323 | topoLion = bundle; |
| 324 | } |
| 325 | |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 326 | // ========================== |
| 327 | // Module definition |
| 328 | |
| 329 | angular.module('ovTopo') |
| 330 | .factory('TopoLinkService', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 331 | ['$log', 'FnService', 'FlashService', 'TopoSelectService', |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 332 | |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame] | 333 | function (_$log_, _fs_, _flash_, _tss_) { |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 334 | $log = _$log_; |
| 335 | fs = _fs_; |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 336 | flash = _flash_; |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 337 | tss = _tss_; |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 338 | |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 339 | function initLink(_api_, _td3_) { |
| 340 | api = _api_; |
| 341 | td3 = _td3_; |
| 342 | svg = api.svg; |
| 343 | network = api.network; |
Bri Prebilic Cole | d874546 | 2015-06-01 16:08:57 -0700 | [diff] [blame] | 344 | if (showPorts && !fs.isMobile()) { |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 345 | svg.on('mousemove', mouseMoveHandler); |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 346 | } |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 347 | svg.on('click', mouseClickHandler); |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 348 | } |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 349 | |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 350 | function destroyLink() { |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 351 | // unconditionally remove any event handlers |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 352 | svg.on('mousemove', null); |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 353 | svg.on('click', null); |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 354 | } |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 355 | |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 356 | return { |
| 357 | initLink: initLink, |
| 358 | destroyLink: destroyLink, |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 359 | togglePorts: togglePorts, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 360 | deselectAllLinks: deselectAllLinks, |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 361 | setLionBundle: setLionBundle, |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 362 | }; |
| 363 | }]); |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 364 | }()); |