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