Simon Hunt | 737c89f | 2015-01-28 12:23:19 -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 | 737c89f | 2015-01-28 12:23:19 -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 | /* |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 18 | ONOS GUI -- Topology Force Module. |
| 19 | Visualization of the topology in an SVG layer, using a D3 Force Layout. |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | (function () { |
| 23 | 'use strict'; |
| 24 | |
| 25 | // injected refs |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 26 | var $log, $timeout, fs, sus, ts, flash, wss, tov, |
Andrea Campanella | 732ea83 | 2017-02-06 09:25:59 -0800 | [diff] [blame] | 27 | tis, tms, td3, tss, tts, tos, fltr, tls, uplink, svg, tpis; |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 28 | |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 29 | // function to be replaced by the localization bundle function |
| 30 | var topoLion = function (x) { |
| 31 | return '#tfs#' + x + '#'; |
| 32 | }; |
| 33 | |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 34 | // configuration |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 35 | var linkConfig = { |
| 36 | light: { |
Simon Hunt | f44d726 | 2016-06-14 14:46:56 -0700 | [diff] [blame] | 37 | baseColor: '#939598', |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 38 | inColor: '#66f', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 39 | outColor: '#f00', |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 40 | }, |
| 41 | dark: { |
Simon Hunt | f44d726 | 2016-06-14 14:46:56 -0700 | [diff] [blame] | 42 | // TODO : theme |
| 43 | baseColor: '#939598', |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 44 | inColor: '#66f', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 45 | outColor: '#f00', |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 46 | }, |
| 47 | inWidth: 12, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 48 | outWidth: 10, |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 49 | }; |
| 50 | |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 51 | // internal state |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 52 | var settings, // merged default settings and options |
| 53 | force, // force layout object |
| 54 | drag, // drag behavior handler |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 55 | network = { |
| 56 | nodes: [], |
| 57 | links: [], |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 58 | linksByDevice: {}, |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 59 | lookup: {}, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 60 | revLinkToKey: {}, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 61 | }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 62 | lu, // shorthand for lookup |
| 63 | rlk, // shorthand for revLinktoKey |
| 64 | showHosts = false, // whether hosts are displayed |
| 65 | showOffline = true, // whether offline devices are displayed |
| 66 | nodeLock = false, // whether nodes can be dragged or not (locked) |
| 67 | fTimer, // timer for delayed force layout |
| 68 | fNodesTimer, // timer for delayed nodes update |
| 69 | fLinksTimer, // timer for delayed links update |
| 70 | dim, // the dimensions of the force layout [w,h] |
| 71 | linkNums = [], // array of link number labels |
| 72 | devIconDim = 36, // node target dimension |
| 73 | devIconDimMin = 20, // node minimum dimension when zoomed out |
| 74 | devIconDimMax = 40, // node maximum dimension when zoomed in |
Steven Burrows | f17f0ab | 2017-04-11 11:03:58 -0700 | [diff] [blame] | 75 | portLabelDim = 30; |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 76 | |
| 77 | // SVG elements; |
Bri Prebilic Cole | 8040176 | 2015-07-16 11:36:18 -0700 | [diff] [blame] | 78 | var linkG, linkLabelG, numLinkLblsG, portLabelG, nodeG; |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 79 | |
| 80 | // D3 selections; |
| 81 | var link, linkLabel, node; |
| 82 | |
| 83 | // default settings for force layout |
| 84 | var defaultSettings = { |
| 85 | gravity: 0.4, |
| 86 | friction: 0.7, |
| 87 | charge: { |
| 88 | // note: key is node.class |
| 89 | device: -8000, |
| 90 | host: -5000, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 91 | _def_: -12000, |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 92 | }, |
| 93 | linkDistance: { |
| 94 | // note: key is link.type |
| 95 | direct: 100, |
| 96 | optical: 120, |
| 97 | hostLink: 3, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 98 | _def_: 50, |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 99 | }, |
| 100 | linkStrength: { |
| 101 | // note: key is link.type |
| 102 | // range: {0.0 ... 1.0} |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 103 | // direct: 1.0, |
| 104 | // optical: 1.0, |
| 105 | // hostLink: 1.0, |
| 106 | _def_: 1.0, |
| 107 | }, |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 111 | // ========================== |
| 112 | // === EVENT HANDLERS |
| 113 | |
| 114 | function addDevice(data) { |
| 115 | var id = data.id, |
| 116 | d; |
| 117 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 118 | uplink.showNoDevs(false); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 119 | |
| 120 | // although this is an add device event, if we already have the |
| 121 | // device, treat it as an update instead.. |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 122 | if (lu[id]) { |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 123 | updateDevice(data); |
| 124 | return; |
| 125 | } |
| 126 | |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 127 | d = tms.createDeviceNode(data); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 128 | network.nodes.push(d); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 129 | lu[id] = d; |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 130 | updateNodes(); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 131 | fStart(); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | function updateDevice(data) { |
| 135 | var id = data.id, |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 136 | d = lu[id], |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 137 | wasOnline; |
| 138 | |
| 139 | if (d) { |
| 140 | wasOnline = d.online; |
| 141 | angular.extend(d, data); |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 142 | if (tms.positionNode(d, true)) { |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 143 | sendUpdateMeta(d); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 144 | } |
| 145 | updateNodes(); |
| 146 | if (wasOnline !== d.online) { |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 147 | tms.findAttachedLinks(d.id).forEach(restyleLinkElement); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 148 | updateOfflineVisibility(d); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 149 | } |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 153 | function removeDevice(data) { |
| 154 | var id = data.id, |
| 155 | d = lu[id]; |
| 156 | if (d) { |
| 157 | removeDeviceElement(d); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
| 161 | function addHost(data) { |
| 162 | var id = data.id, |
Simon Hunt | 12c79ed | 2017-09-12 11:58:44 -0700 | [diff] [blame] | 163 | d; |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 164 | |
| 165 | // although this is an add host event, if we already have the |
| 166 | // host, treat it as an update instead.. |
| 167 | if (lu[id]) { |
| 168 | updateHost(data); |
| 169 | return; |
| 170 | } |
| 171 | |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 172 | d = tms.createHostNode(data); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 173 | network.nodes.push(d); |
| 174 | lu[id] = d; |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 175 | updateNodes(); |
| 176 | |
Simon Hunt | 12c79ed | 2017-09-12 11:58:44 -0700 | [diff] [blame] | 177 | // need to handle possible multiple links (multi-homed host) |
Simon Hunt | 7df764f | 2017-09-14 21:26:14 -0700 | [diff] [blame^] | 178 | createHostLinks(data.allCps, d); |
Simon Hunt | 12c79ed | 2017-09-12 11:58:44 -0700 | [diff] [blame] | 179 | |
| 180 | if (d.links.length) { |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 181 | updateLinks(); |
| 182 | } |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 183 | fStart(); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | function updateHost(data) { |
| 187 | var id = data.id, |
| 188 | d = lu[id]; |
| 189 | if (d) { |
| 190 | angular.extend(d, data); |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 191 | if (tms.positionNode(d, true)) { |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 192 | sendUpdateMeta(d); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 193 | } |
| 194 | updateNodes(); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
Simon Hunt | 7df764f | 2017-09-14 21:26:14 -0700 | [diff] [blame^] | 198 | function createHostLinks(cps, model) { |
| 199 | model.links = []; |
| 200 | cps.forEach(function (cp) { |
| 201 | var linkData = { |
| 202 | key: model.id + '/0-' + cp.device + '/' + cp.port, |
| 203 | dst: cp.device, |
| 204 | dstPort: cp.port, |
| 205 | }; |
| 206 | model.links.push(linkData); |
| 207 | |
| 208 | var lnk = tms.createHostLink(model.id, cp.device, cp.port); |
| 209 | if (lnk) { |
| 210 | network.links.push(lnk); |
| 211 | lu[linkData.key] = lnk; |
| 212 | } |
| 213 | }); |
| 214 | } |
| 215 | |
Simon Hunt | 95d56fd | 2015-11-12 11:06:44 -0800 | [diff] [blame] | 216 | function moveHost(data) { |
| 217 | var id = data.id, |
Simon Hunt | 7df764f | 2017-09-14 21:26:14 -0700 | [diff] [blame^] | 218 | d = lu[id]; |
Simon Hunt | 12c79ed | 2017-09-12 11:58:44 -0700 | [diff] [blame] | 219 | |
Simon Hunt | 95d56fd | 2015-11-12 11:06:44 -0800 | [diff] [blame] | 220 | if (d) { |
Simon Hunt | 7df764f | 2017-09-14 21:26:14 -0700 | [diff] [blame^] | 221 | removeAllLinkElements(d.links); |
Simon Hunt | 95d56fd | 2015-11-12 11:06:44 -0800 | [diff] [blame] | 222 | |
| 223 | // merge new data |
| 224 | angular.extend(d, data); |
| 225 | if (tms.positionNode(d, true)) { |
| 226 | sendUpdateMeta(d); |
| 227 | } |
| 228 | |
Simon Hunt | 7df764f | 2017-09-14 21:26:14 -0700 | [diff] [blame^] | 229 | // now create new host link(s) |
| 230 | createHostLinks(data.allCps, d); |
Simon Hunt | 95d56fd | 2015-11-12 11:06:44 -0800 | [diff] [blame] | 231 | |
| 232 | updateNodes(); |
| 233 | updateLinks(); |
| 234 | fResume(); |
| 235 | } |
| 236 | } |
| 237 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 238 | function removeHost(data) { |
| 239 | var id = data.id, |
| 240 | d = lu[id]; |
| 241 | if (d) { |
| 242 | removeHostElement(d, true); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
| 246 | function addLink(data) { |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 247 | var result = tms.findLink(data, 'add'), |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 248 | bad = result.badLogic, |
| 249 | d = result.ldata; |
| 250 | |
| 251 | if (bad) { |
Simon Hunt | eb18f52 | 2016-01-28 19:22:23 -0800 | [diff] [blame] | 252 | $log.debug(bad + ': ' + link.id); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 253 | return; |
| 254 | } |
| 255 | |
| 256 | if (d) { |
| 257 | // we already have a backing store link for src/dst nodes |
| 258 | addLinkUpdate(d, data); |
| 259 | return; |
| 260 | } |
| 261 | |
| 262 | // no backing store link yet |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 263 | d = tms.createLink(data); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 264 | if (d) { |
| 265 | network.links.push(d); |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 266 | aggregateLink(d, data); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 267 | lu[d.key] = d; |
| 268 | updateLinks(); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 269 | fStart(); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
| 273 | function updateLink(data) { |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 274 | var result = tms.findLink(data, 'update'), |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 275 | bad = result.badLogic; |
| 276 | if (bad) { |
Simon Hunt | eb18f52 | 2016-01-28 19:22:23 -0800 | [diff] [blame] | 277 | $log.debug(bad + ': ' + link.id); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 278 | return; |
| 279 | } |
Simon Hunt | eb18f52 | 2016-01-28 19:22:23 -0800 | [diff] [blame] | 280 | result.updateWith(data); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | function removeLink(data) { |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 284 | var result = tms.findLink(data, 'remove'); |
| 285 | |
| 286 | if (!result.badLogic) { |
| 287 | result.removeRawLink(); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 288 | } |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 289 | } |
| 290 | |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 291 | function topoStartDone(data) { |
| 292 | // called when the initial barrage of data has been sent from server |
| 293 | uplink.topoStartDone(); |
| 294 | } |
| 295 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 296 | // ======================== |
| 297 | |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 298 | function nodeById(id) { |
| 299 | return lu[id]; |
| 300 | } |
| 301 | |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 302 | function makeNodeKey(node1, node2) { |
| 303 | return node1 + '-' + node2; |
| 304 | } |
| 305 | |
| 306 | function findNodePair(key, keyRev) { |
| 307 | if (network.linksByDevice[key]) { |
| 308 | return key; |
| 309 | } else if (network.linksByDevice[keyRev]) { |
| 310 | return keyRev; |
| 311 | } else { |
| 312 | return false; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | function aggregateLink(ldata, link) { |
| 317 | var key = makeNodeKey(link.src, link.dst), |
| 318 | keyRev = makeNodeKey(link.dst, link.src), |
| 319 | found = findNodePair(key, keyRev); |
| 320 | |
| 321 | if (found) { |
| 322 | network.linksByDevice[found].push(ldata); |
| 323 | ldata.devicePair = found; |
| 324 | } else { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 325 | network.linksByDevice[key] = [ldata]; |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 326 | ldata.devicePair = key; |
| 327 | } |
| 328 | } |
| 329 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 330 | function addLinkUpdate(ldata, link) { |
| 331 | // add link event, but we already have the reverse link installed |
| 332 | ldata.fromTarget = link; |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 333 | rlk[link.id] = ldata.key; |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 334 | // possible solution to el being undefined in restyleLinkElement: |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 335 | // _updateLinks(); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 336 | restyleLinkElement(ldata); |
| 337 | } |
| 338 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 339 | |
| 340 | var widthRatio = 1.4, |
| 341 | linkScale = d3.scale.linear() |
| 342 | .domain([1, 12]) |
| 343 | .range([widthRatio, 12 * widthRatio]) |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 344 | .clamp(true), |
Ray Milkey | b7f0f64 | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 345 | allLinkTypes = 'direct indirect optical tunnel', |
| 346 | allLinkSubTypes = 'inactive not-permitted'; |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 347 | |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 348 | function restyleLinkElement(ldata, immediate) { |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 349 | // this fn's job is to look at raw links and decide what svg classes |
| 350 | // need to be applied to the line element in the DOM |
| 351 | var th = ts.theme(), |
| 352 | el = ldata.el, |
| 353 | type = ldata.type(), |
| 354 | lw = ldata.linkWidth(), |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 355 | online = ldata.online(), |
Ray Milkey | b7f0f64 | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 356 | modeCls = ldata.expected() ? 'inactive' : 'not-permitted', |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 357 | delay = immediate ? 0 : 1000; |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 358 | |
Simon Hunt | f44d726 | 2016-06-14 14:46:56 -0700 | [diff] [blame] | 359 | // NOTE: understand why el is sometimes undefined on addLink events... |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 360 | // Investigated: |
| 361 | // el is undefined when it's a reverse link that is being added. |
| 362 | // updateLinks (which sets ldata.el) isn't called before this is called. |
| 363 | // Calling _updateLinks in addLinkUpdate fixes it, but there might be |
| 364 | // a more efficient way to fix it. |
| 365 | if (el && !el.empty()) { |
Thomas Vachuska | cb5016f | 2015-05-18 14:11:43 -0700 | [diff] [blame] | 366 | el.classed('link', true); |
Ray Milkey | b7f0f64 | 2016-01-22 16:08:14 -0800 | [diff] [blame] | 367 | el.classed(allLinkSubTypes, false); |
| 368 | el.classed(modeCls, !online); |
Thomas Vachuska | cb5016f | 2015-05-18 14:11:43 -0700 | [diff] [blame] | 369 | el.classed(allLinkTypes, false); |
| 370 | if (type) { |
| 371 | el.classed(type, true); |
| 372 | } |
| 373 | el.transition() |
| 374 | .duration(delay) |
| 375 | .attr('stroke-width', linkScale(lw)) |
| 376 | .attr('stroke', linkConfig[th].baseColor); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 377 | } |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Simon Hunt | 7df764f | 2017-09-14 21:26:14 -0700 | [diff] [blame^] | 380 | function removeAllLinkElements(links) { |
| 381 | links.forEach(function (lnk) { |
| 382 | removeLinkElement(lnk); |
| 383 | }); |
| 384 | } |
| 385 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 386 | function removeLinkElement(d) { |
| 387 | var idx = fs.find(d.key, network.links, 'key'), |
| 388 | removed; |
| 389 | if (idx >=0) { |
| 390 | // remove from links array |
| 391 | removed = network.links.splice(idx, 1); |
| 392 | // remove from lookup cache |
| 393 | delete lu[removed[0].key]; |
| 394 | updateLinks(); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 395 | fResume(); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
| 399 | function removeHostElement(d, upd) { |
| 400 | // first, remove associated hostLink... |
| 401 | removeLinkElement(d.linkData); |
| 402 | |
| 403 | // remove hostLink bindings |
| 404 | delete lu[d.ingress]; |
| 405 | delete lu[d.egress]; |
| 406 | |
| 407 | // remove from lookup cache |
| 408 | delete lu[d.id]; |
| 409 | // remove from nodes array |
| 410 | var idx = fs.find(d.id, network.nodes); |
| 411 | network.nodes.splice(idx, 1); |
| 412 | |
| 413 | // remove from SVG |
| 414 | // NOTE: upd is false if we were called from removeDeviceElement() |
| 415 | if (upd) { |
| 416 | updateNodes(); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 417 | fResume(); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
| 421 | function removeDeviceElement(d) { |
Bri Prebilic Cole | 8d00378 | 2015-07-31 15:33:06 -0700 | [diff] [blame] | 422 | var id = d.id, |
| 423 | idx; |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 424 | // first, remove associated hosts and links.. |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 425 | tms.findAttachedHosts(id).forEach(removeHostElement); |
| 426 | tms.findAttachedLinks(id).forEach(removeLinkElement); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 427 | |
| 428 | // remove from lookup cache |
| 429 | delete lu[id]; |
| 430 | // remove from nodes array |
Bri Prebilic Cole | 8d00378 | 2015-07-31 15:33:06 -0700 | [diff] [blame] | 431 | idx = fs.find(id, network.nodes); |
| 432 | if (idx > -1) { |
| 433 | network.nodes.splice(idx, 1); |
| 434 | } |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 435 | |
| 436 | if (!network.nodes.length) { |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 437 | uplink.showNoDevs(true); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | // remove from SVG |
| 441 | updateNodes(); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 442 | fResume(); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 443 | } |
| 444 | |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 445 | function updateHostVisibility() { |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 446 | sus.visible(nodeG.selectAll('.host'), showHosts); |
| 447 | sus.visible(linkG.selectAll('.hostLink'), showHosts); |
Simon Hunt | 8eb4d3a | 2015-02-23 18:23:29 -0800 | [diff] [blame] | 448 | sus.visible(linkLabelG.selectAll('.hostLinkLabel'), showHosts); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | function updateOfflineVisibility(dev) { |
| 452 | function updDev(d, show) { |
Simon Hunt | 8eb4d3a | 2015-02-23 18:23:29 -0800 | [diff] [blame] | 453 | var b; |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 454 | sus.visible(d.el, show); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 455 | |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 456 | tms.findAttachedLinks(d.id).forEach(function (link) { |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 457 | b = show && ((link.type() !== 'hostLink') || showHosts); |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 458 | sus.visible(link.el, b); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 459 | }); |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 460 | tms.findAttachedHosts(d.id).forEach(function (host) { |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 461 | b = show && showHosts; |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 462 | sus.visible(host.el, b); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 463 | }); |
| 464 | } |
| 465 | |
| 466 | if (dev) { |
| 467 | // updating a specific device that just toggled off/on-line |
| 468 | updDev(dev, dev.online || showOffline); |
| 469 | } else { |
| 470 | // updating all offline devices |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 471 | tms.findDevices(true).forEach(function (d) { |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 472 | updDev(d, showOffline); |
| 473 | }); |
| 474 | } |
| 475 | } |
| 476 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 477 | |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 478 | function sendUpdateMeta(d, clearPos) { |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 479 | var metaUi = {}, |
| 480 | ll; |
| 481 | |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 482 | // if we are not clearing the position data (unpinning), |
Simon Hunt | fd7106c | 2016-02-09 15:05:26 -0800 | [diff] [blame] | 483 | // attach the x, y, (and equivalent longitude, latitude)... |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 484 | if (!clearPos) { |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 485 | ll = tms.lngLatFromCoord([d.x, d.y]); |
Simon Hunt | fd7106c | 2016-02-09 15:05:26 -0800 | [diff] [blame] | 486 | metaUi = { |
| 487 | x: d.x, |
| 488 | y: d.y, |
| 489 | equivLoc: { |
| 490 | lng: ll[0], |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 491 | lat: ll[1], |
| 492 | }, |
Simon Hunt | fd7106c | 2016-02-09 15:05:26 -0800 | [diff] [blame] | 493 | }; |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 494 | } |
| 495 | d.metaUi = metaUi; |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 496 | wss.sendEvent('updateMeta', { |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 497 | id: d.id, |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 498 | class: d.class, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 499 | memento: metaUi, |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 500 | }); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 503 | |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 504 | function mkSvgClass(d) { |
| 505 | return d.fixed ? d.svgClass + ' fixed' : d.svgClass; |
| 506 | } |
| 507 | |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 508 | function vis(b) { |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 509 | return topoLion(b ? 'visible' : 'hidden'); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 510 | } |
| 511 | |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 512 | function toggleHosts(x) { |
| 513 | var kev = (x === 'keyev'), |
| 514 | on = kev ? !showHosts : !!x; |
| 515 | |
| 516 | showHosts = on; |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 517 | updateHostVisibility(); |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 518 | flash.flash(topoLion('hosts') + ' ' + vis(on)); |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 519 | return on; |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 520 | } |
| 521 | |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 522 | function toggleOffline(x) { |
| 523 | var kev = (x === 'keyev'), |
| 524 | on = kev ? !showOffline : !!x; |
| 525 | |
| 526 | showOffline = on; |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 527 | updateOfflineVisibility(); |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 528 | flash.flash(topoLion('fl_offline_devices') + ' ' + vis(on)); |
Simon Hunt | fcbde89 | 2015-04-16 12:05:28 -0700 | [diff] [blame] | 529 | return on; |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | function cycleDeviceLabels() { |
Bri Prebilic Cole | 9cf1a8d | 2015-04-21 13:15:29 -0700 | [diff] [blame] | 533 | flash.flash(td3.incDevLabIndex()); |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 534 | tms.findDevices().forEach(function (d) { |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 535 | td3.updateDeviceLabel(d); |
Simon Hunt | 1c36711 | 2015-02-05 18:02:46 -0800 | [diff] [blame] | 536 | }); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 537 | } |
| 538 | |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 539 | function cycleHostLabels() { |
| 540 | flash.flash(td3.incHostLabIndex()); |
| 541 | tms.findHosts().forEach(function (d) { |
| 542 | td3.updateHostLabel(d); |
| 543 | }); |
| 544 | } |
| 545 | |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 546 | function unpin() { |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 547 | var hov = tss.hovered(); |
| 548 | if (hov) { |
| 549 | sendUpdateMeta(hov, true); |
| 550 | hov.fixed = false; |
| 551 | hov.el.classed('fixed', false); |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 552 | fResume(); |
| 553 | } |
| 554 | } |
| 555 | |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 556 | function showMastership(masterId) { |
| 557 | if (!masterId) { |
| 558 | restoreLayerState(); |
| 559 | } else { |
| 560 | showMastershipFor(masterId); |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | function restoreLayerState() { |
| 565 | // NOTE: this level of indirection required, for when we have |
| 566 | // the layer filter functionality re-implemented |
| 567 | suppressLayers(false); |
| 568 | } |
| 569 | |
| 570 | function showMastershipFor(id) { |
| 571 | suppressLayers(true); |
| 572 | node.each(function (n) { |
| 573 | if (n.master === id) { |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 574 | n.el.classed('suppressedmax', false); |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 575 | } |
| 576 | }); |
| 577 | } |
| 578 | |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 579 | function supAmt(less) { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 580 | return less ? 'suppressed' : 'suppressedmax'; |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | function suppressLayers(b, less) { |
| 584 | var cls = supAmt(less); |
| 585 | node.classed(cls, b); |
| 586 | link.classed(cls, b); |
| 587 | } |
| 588 | |
| 589 | function unsuppressNode(id, less) { |
| 590 | var cls = supAmt(less); |
| 591 | node.each(function (n) { |
| 592 | if (n.id === id) { |
| 593 | n.el.classed(cls, false); |
| 594 | } |
| 595 | }); |
| 596 | } |
| 597 | |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 598 | function unsuppressLink(key, less) { |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 599 | var cls = supAmt(less); |
| 600 | link.each(function (n) { |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 601 | if (n.key === key) { |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 602 | n.el.classed(cls, false); |
| 603 | } |
| 604 | }); |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 605 | } |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 606 | |
Simon Hunt | 86b7c88 | 2015-04-02 23:06:08 -0700 | [diff] [blame] | 607 | function showBadLinks() { |
| 608 | var badLinks = tms.findBadLinks(); |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 609 | flash.flash(topoLion('fl_bad_links') + ': ' + badLinks.length); |
Simon Hunt | 86b7c88 | 2015-04-02 23:06:08 -0700 | [diff] [blame] | 610 | $log.debug('Bad Link List (' + badLinks.length + '):'); |
| 611 | badLinks.forEach(function (d) { |
| 612 | $log.debug('bad link: (' + d.bad + ') ' + d.key, d); |
| 613 | if (d.el) { |
| 614 | d.el.attr('stroke-width', linkScale(2.8)) |
| 615 | .attr('stroke', 'red'); |
| 616 | } |
| 617 | }); |
| 618 | // back to normal after 2 seconds... |
| 619 | $timeout(updateLinks, 2000); |
| 620 | } |
| 621 | |
Steven Burrows | f17f0ab | 2017-04-11 11:03:58 -0700 | [diff] [blame] | 622 | function deviceScale() { |
| 623 | var scale = uplink.zoomer().scale(), |
| 624 | dim = devIconDim, |
| 625 | multiplier = 1; |
| 626 | |
| 627 | if (dim * scale < devIconDimMin) { |
| 628 | multiplier = devIconDimMin / (dim * scale); |
| 629 | } else if (dim * scale > devIconDimMax) { |
| 630 | multiplier = devIconDimMax / (dim * scale); |
| 631 | } |
| 632 | |
| 633 | return multiplier; |
| 634 | } |
| 635 | |
| 636 | function linkWidthScale(scale) { |
| 637 | var scale = uplink.zoomer().scale(); |
| 638 | return linkScale(widthRatio) / scale; |
| 639 | } |
| 640 | |
| 641 | function portLabelScale(scale) { |
| 642 | var scale = uplink.zoomer().scale(); |
| 643 | return portLabelDim / (portLabelDim * scale); |
| 644 | } |
| 645 | |
| 646 | function setNodeScale(scale) { |
| 647 | // Scale the network nodes |
| 648 | _.each(network.nodes, function (node) { |
| 649 | if (node.class === 'host') { |
| 650 | node.el.selectAll('g').style('transform', 'scale(' + deviceScale(scale) + ')'); |
| 651 | node.el.selectAll('text').style('transform', 'scale(' + deviceScale(scale) + ')'); |
| 652 | return; |
| 653 | } |
| 654 | node.el.selectAll('*') |
| 655 | .style('transform', 'scale(' + deviceScale(scale) + ')'); |
| 656 | }); |
| 657 | |
| 658 | // Scale the network links |
| 659 | _.each(network.links, function (link) { |
| 660 | link.el.style('stroke-width', linkWidthScale(scale) + 'px'); |
| 661 | }); |
| 662 | |
| 663 | d3.select('#topo-portLabels') |
| 664 | .selectAll('.portLabel') |
| 665 | .selectAll('*') |
| 666 | .style('transform', 'scale(' + portLabelScale(scale) + ')'); |
| 667 | } |
| 668 | |
Simon Hunt | fd7106c | 2016-02-09 15:05:26 -0800 | [diff] [blame] | 669 | function resetAllLocations() { |
| 670 | tms.resetAllLocations(); |
| 671 | updateNodes(); |
| 672 | tick(); // force nodes to be redrawn in their new locations |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 673 | flash.flash(topoLion('fl_reset_node_locations')); |
Simon Hunt | fd7106c | 2016-02-09 15:05:26 -0800 | [diff] [blame] | 674 | } |
| 675 | |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 676 | // ========================================== |
| 677 | |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 678 | function updateNodes() { |
Thomas Vachuska | 1a989c1 | 2015-06-09 18:29:22 -0700 | [diff] [blame] | 679 | if (fNodesTimer) { |
| 680 | $timeout.cancel(fNodesTimer); |
| 681 | } |
| 682 | fNodesTimer = $timeout(_updateNodes, 150); |
| 683 | } |
| 684 | |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 685 | // IMPLEMENTATION NOTE: _updateNodes() should NOT stop, start, or resume |
| 686 | // the force layout; that needs to be determined and implemented elsewhere |
Thomas Vachuska | 1a989c1 | 2015-06-09 18:29:22 -0700 | [diff] [blame] | 687 | function _updateNodes() { |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 688 | // select all the nodes in the layout: |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 689 | node = nodeG.selectAll('.node') |
| 690 | .data(network.nodes, function (d) { return d.id; }); |
| 691 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 692 | // operate on existing nodes: |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 693 | node.filter('.device').each(td3.deviceExisting); |
| 694 | node.filter('.host').each(td3.hostExisting); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 695 | |
| 696 | // operate on entering nodes: |
| 697 | var entering = node.enter() |
| 698 | .append('g') |
| 699 | .attr({ |
| 700 | id: function (d) { return sus.safeId(d.id); }, |
| 701 | class: mkSvgClass, |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 702 | transform: function (d) { |
| 703 | // Need to guard against NaN here ?? |
| 704 | return sus.translate(d.x, d.y); |
| 705 | }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 706 | opacity: 0, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 707 | }) |
| 708 | .call(drag) |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 709 | .on('mouseover', tss.nodeMouseOver) |
| 710 | .on('mouseout', tss.nodeMouseOut) |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 711 | .transition() |
| 712 | .attr('opacity', 1); |
| 713 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 714 | // augment entering nodes: |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 715 | entering.filter('.device').each(td3.deviceEnter); |
| 716 | entering.filter('.host').each(td3.hostEnter); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 717 | |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 718 | // operate on both existing and new nodes: |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 719 | td3.updateDeviceColors(); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 720 | |
| 721 | // operate on exiting nodes: |
| 722 | // Note that the node is removed after 2 seconds. |
| 723 | // Sub element animations should be shorter than 2 seconds. |
| 724 | var exiting = node.exit() |
| 725 | .transition() |
| 726 | .duration(2000) |
| 727 | .style('opacity', 0) |
| 728 | .remove(); |
| 729 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 730 | // exiting node specifics: |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 731 | exiting.filter('.host').each(td3.hostExit); |
| 732 | exiting.filter('.device').each(td3.deviceExit); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 733 | } |
| 734 | |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 735 | // ========================== |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 736 | |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 737 | function getDefaultPos(link) { |
| 738 | return { |
| 739 | x1: link.source.x, |
| 740 | y1: link.source.y, |
| 741 | x2: link.target.x, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 742 | y2: link.target.y, |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 743 | }; |
| 744 | } |
| 745 | |
| 746 | // returns amount of adjustment along the normal for given link |
| 747 | function amt(numLinks, linkIdx) { |
| 748 | var gap = 6; |
| 749 | return (linkIdx - ((numLinks - 1) / 2)) * gap; |
| 750 | } |
| 751 | |
| 752 | function calcMovement(d, amt, flipped) { |
| 753 | var pos = getDefaultPos(d), |
| 754 | mult = flipped ? -amt : amt, |
| 755 | dx = pos.x2 - pos.x1, |
| 756 | dy = pos.y2 - pos.y1, |
| 757 | length = Math.sqrt((dx * dx) + (dy * dy)); |
| 758 | |
| 759 | return { |
| 760 | x1: pos.x1 + (mult * dy / length), |
| 761 | y1: pos.y1 + (mult * -dx / length), |
| 762 | x2: pos.x2 + (mult * dy / length), |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 763 | y2: pos.y2 + (mult * -dx / length), |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 764 | }; |
| 765 | } |
| 766 | |
| 767 | function calcPosition() { |
| 768 | var lines = this, |
| 769 | linkSrcId; |
Bri Prebilic Cole | 8040176 | 2015-07-16 11:36:18 -0700 | [diff] [blame] | 770 | linkNums = []; |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 771 | lines.each(function (d) { |
| 772 | if (d.type() === 'hostLink') { |
| 773 | d.position = getDefaultPos(d); |
| 774 | } |
| 775 | }); |
| 776 | |
| 777 | function normalizeLinkSrc(link) { |
| 778 | // ensure source device is consistent across set of links |
| 779 | // temporary measure until link modeling is refactored |
| 780 | if (!linkSrcId) { |
| 781 | linkSrcId = link.source.id; |
| 782 | return false; |
| 783 | } |
| 784 | |
| 785 | return link.source.id !== linkSrcId; |
| 786 | } |
| 787 | |
Bri Prebilic Cole | 8040176 | 2015-07-16 11:36:18 -0700 | [diff] [blame] | 788 | angular.forEach(network.linksByDevice, function (linkArr, key) { |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 789 | var numLinks = linkArr.length, |
| 790 | link; |
| 791 | |
| 792 | if (numLinks === 1) { |
| 793 | link = linkArr[0]; |
| 794 | link.position = getDefaultPos(link); |
Bri Prebilic Cole | 8040176 | 2015-07-16 11:36:18 -0700 | [diff] [blame] | 795 | link.position.multiLink = false; |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 796 | } else if (numLinks >= 5) { |
| 797 | // this code is inefficient, in the future the way links |
| 798 | // are modeled will be changed |
| 799 | angular.forEach(linkArr, function (link) { |
| 800 | link.position = getDefaultPos(link); |
| 801 | link.position.multiLink = true; |
| 802 | }); |
Bri Prebilic Cole | 8040176 | 2015-07-16 11:36:18 -0700 | [diff] [blame] | 803 | linkNums.push({ |
| 804 | id: key, |
| 805 | num: numLinks, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 806 | linkCoords: linkArr[0].position, |
Bri Prebilic Cole | 8040176 | 2015-07-16 11:36:18 -0700 | [diff] [blame] | 807 | }); |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 808 | } else { |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 809 | linkSrcId = null; |
| 810 | angular.forEach(linkArr, function (link, index) { |
| 811 | var offsetAmt = amt(numLinks, index), |
| 812 | needToFlip = normalizeLinkSrc(link); |
| 813 | link.position = calcMovement(link, offsetAmt, needToFlip); |
Bri Prebilic Cole | 8040176 | 2015-07-16 11:36:18 -0700 | [diff] [blame] | 814 | link.position.multiLink = false; |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 815 | }); |
| 816 | } |
| 817 | }); |
| 818 | } |
| 819 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 820 | function updateLinks() { |
Thomas Vachuska | 1a989c1 | 2015-06-09 18:29:22 -0700 | [diff] [blame] | 821 | if (fLinksTimer) { |
| 822 | $timeout.cancel(fLinksTimer); |
| 823 | } |
| 824 | fLinksTimer = $timeout(_updateLinks, 150); |
| 825 | } |
| 826 | |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 827 | // IMPLEMENTATION NOTE: _updateLinks() should NOT stop, start, or resume |
| 828 | // the force layout; that needs to be determined and implemented elsewhere |
Thomas Vachuska | 1a989c1 | 2015-06-09 18:29:22 -0700 | [diff] [blame] | 829 | function _updateLinks() { |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 830 | var th = ts.theme(); |
| 831 | |
| 832 | link = linkG.selectAll('.link') |
| 833 | .data(network.links, function (d) { return d.key; }); |
| 834 | |
| 835 | // operate on existing links: |
Simon Hunt | d526412 | 2015-02-25 10:17:43 -0800 | [diff] [blame] | 836 | link.each(function (d) { |
| 837 | // this is supposed to be an existing link, but we have observed |
| 838 | // occasions (where links are deleted and added rapidly?) where |
| 839 | // the DOM element has not been defined. So protect against that... |
| 840 | if (d.el) { |
| 841 | restyleLinkElement(d, true); |
| 842 | } |
| 843 | }); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 844 | |
| 845 | // operate on entering links: |
| 846 | var entering = link.enter() |
| 847 | .append('line') |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 848 | .call(calcPosition) |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 849 | .attr({ |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 850 | x1: function (d) { return d.position.x1; }, |
| 851 | y1: function (d) { return d.position.y1; }, |
| 852 | x2: function (d) { return d.position.x2; }, |
| 853 | y2: function (d) { return d.position.y2; }, |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 854 | stroke: linkConfig[th].inColor, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 855 | 'stroke-width': linkConfig.inWidth, |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 856 | }); |
| 857 | |
| 858 | // augment links |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 859 | entering.each(td3.linkEntering); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 860 | |
| 861 | // operate on both existing and new links: |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 862 | // link.each(...) |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 863 | |
Bri Prebilic Cole | 8040176 | 2015-07-16 11:36:18 -0700 | [diff] [blame] | 864 | // add labels for how many links are in a thick line |
| 865 | td3.applyNumLinkLabels(linkNums, numLinkLblsG); |
| 866 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 867 | // apply or remove labels |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 868 | td3.applyLinkLabels(); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 869 | |
| 870 | // operate on exiting links: |
| 871 | link.exit() |
| 872 | .attr('stroke-dasharray', '3 3') |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 873 | .attr('stroke', linkConfig[th].outColor) |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 874 | .style('opacity', 0.5) |
| 875 | .transition() |
| 876 | .duration(1500) |
| 877 | .attr({ |
| 878 | 'stroke-dasharray': '3 12', |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 879 | 'stroke-width': linkConfig.outWidth, |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 880 | }) |
| 881 | .style('opacity', 0.0) |
| 882 | .remove(); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 883 | } |
| 884 | |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 885 | |
| 886 | // ========================== |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 887 | // force layout tick function |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 888 | |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 889 | function fResume() { |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 890 | if (!tos.isOblique()) { |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 891 | force.resume(); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | function fStart() { |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 896 | if (!tos.isOblique()) { |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 897 | if (fTimer) { |
| 898 | $timeout.cancel(fTimer); |
| 899 | } |
| 900 | fTimer = $timeout(function () { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 901 | $log.debug('Starting force-layout'); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 902 | force.start(); |
| 903 | }, 200); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 904 | } |
| 905 | } |
| 906 | |
| 907 | var tickStuff = { |
| 908 | nodeAttr: { |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 909 | transform: function (d) { |
| 910 | var dx = isNaN(d.x) ? 0 : d.x, |
| 911 | dy = isNaN(d.y) ? 0 : d.y; |
| 912 | return sus.translate(dx, dy); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 913 | }, |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 914 | }, |
| 915 | linkAttr: { |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 916 | x1: function (d) { return d.position.x1; }, |
| 917 | y1: function (d) { return d.position.y1; }, |
| 918 | x2: function (d) { return d.position.x2; }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 919 | y2: function (d) { return d.position.y2; }, |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 920 | }, |
| 921 | linkLabelAttr: { |
| 922 | transform: function (d) { |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 923 | var lnk = tms.findLinkById(d.key); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 924 | if (lnk) { |
Carmelo Cascone | d01eda6 | 2016-08-02 10:19:15 -0700 | [diff] [blame] | 925 | return td3.transformLabel(lnk.position, d.key); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 926 | } |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 927 | }, |
| 928 | }, |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 929 | }; |
| 930 | |
| 931 | function tick() { |
Simon Hunt | 3ab2028 | 2015-02-26 20:32:19 -0800 | [diff] [blame] | 932 | // guard against null (which can happen when our view pages out)... |
Bri Prebilic Cole | 8d00378 | 2015-07-31 15:33:06 -0700 | [diff] [blame] | 933 | if (node && node.size()) { |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 934 | node.attr(tickStuff.nodeAttr); |
| 935 | } |
Bri Prebilic Cole | 8d00378 | 2015-07-31 15:33:06 -0700 | [diff] [blame] | 936 | if (link && link.size()) { |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 937 | link.call(calcPosition) |
| 938 | .attr(tickStuff.linkAttr); |
Bri Prebilic Cole | 8040176 | 2015-07-16 11:36:18 -0700 | [diff] [blame] | 939 | td3.applyNumLinkLabels(linkNums, numLinkLblsG); |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 940 | } |
Bri Prebilic Cole | 8d00378 | 2015-07-31 15:33:06 -0700 | [diff] [blame] | 941 | if (linkLabel && linkLabel.size()) { |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 942 | linkLabel.attr(tickStuff.linkLabelAttr); |
| 943 | } |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 947 | // ========================== |
| 948 | // === MOUSE GESTURE HANDLERS |
| 949 | |
Simon Hunt | 205099e | 2015-02-07 13:12:01 -0800 | [diff] [blame] | 950 | function zoomingOrPanning(ev) { |
| 951 | return ev.metaKey || ev.altKey; |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | function atDragEnd(d) { |
| 955 | // once we've finished moving, pin the node in position |
| 956 | d.fixed = true; |
| 957 | d3.select(this).classed('fixed', true); |
| 958 | sendUpdateMeta(d); |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 959 | tss.clickConsumed(true); |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | // predicate that indicates when dragging is active |
| 963 | function dragEnabled() { |
| 964 | var ev = d3.event.sourceEvent; |
| 965 | // nodeLock means we aren't allowing nodes to be dragged... |
Simon Hunt | 205099e | 2015-02-07 13:12:01 -0800 | [diff] [blame] | 966 | return !nodeLock && !zoomingOrPanning(ev); |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | // predicate that indicates when clicking is active |
| 970 | function clickEnabled() { |
| 971 | return true; |
| 972 | } |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 973 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 974 | // ============================================= |
| 975 | // function entry points for overlay module |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 976 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 977 | // TODO: find an automatic way of tracking via the "showHighlights" events |
Simon Hunt | e50829c | 2015-06-09 08:39:28 -0700 | [diff] [blame] | 978 | var allTrafficClasses = 'primary secondary optical animated ' + |
Simon Hunt | 21281fd | 2017-03-30 22:28:28 -0700 | [diff] [blame] | 979 | 'port-traffic-green port-traffic-yellow port-traffic-orange ' + |
| 980 | 'port-traffic-red'; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 981 | |
| 982 | function clearLinkTrafficStyle() { |
| 983 | link.style('stroke-width', null) |
| 984 | .classed(allTrafficClasses, false); |
| 985 | } |
| 986 | |
| 987 | function removeLinkLabels() { |
| 988 | network.links.forEach(function (d) { |
| 989 | d.label = ''; |
| 990 | }); |
| 991 | } |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 992 | |
Simon Hunt | e9343f3 | 2015-10-21 18:07:46 -0700 | [diff] [blame] | 993 | function clearNodeDeco() { |
| 994 | node.selectAll('g.badge').remove(); |
| 995 | } |
| 996 | |
| 997 | function removeNodeBadges() { |
| 998 | network.nodes.forEach(function (d) { |
| 999 | d.badge = null; |
| 1000 | }); |
| 1001 | } |
| 1002 | |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 1003 | function updateLinkLabelModel() { |
| 1004 | // create the backing data for showing labels.. |
| 1005 | var data = []; |
| 1006 | link.each(function (d) { |
| 1007 | if (d.label) { |
| 1008 | data.push({ |
| 1009 | id: 'lab-' + d.key, |
| 1010 | key: d.key, |
| 1011 | label: d.label, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 1012 | ldata: d, |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 1013 | }); |
| 1014 | } |
| 1015 | }); |
| 1016 | |
| 1017 | linkLabel = linkLabelG.selectAll('.linkLabel') |
| 1018 | .data(data, function (d) { return d.id; }); |
| 1019 | } |
| 1020 | |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1021 | // ========================== |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 1022 | // Module definition |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1023 | |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 1024 | function mkModelApi(uplink) { |
| 1025 | return { |
| 1026 | projection: uplink.projection, |
| 1027 | network: network, |
| 1028 | restyleLinkElement: restyleLinkElement, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 1029 | removeLinkElement: removeLinkElement, |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 1030 | }; |
| 1031 | } |
| 1032 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 1033 | function mkD3Api() { |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 1034 | return { |
| 1035 | node: function () { return node; }, |
| 1036 | link: function () { return link; }, |
| 1037 | linkLabel: function () { return linkLabel; }, |
| 1038 | instVisible: function () { return tis.isVisible(); }, |
| 1039 | posNode: tms.positionNode, |
| 1040 | showHosts: function () { return showHosts; }, |
| 1041 | restyleLinkElement: restyleLinkElement, |
Bri Prebilic Cole | 8040176 | 2015-07-16 11:36:18 -0700 | [diff] [blame] | 1042 | updateLinkLabelModel: updateLinkLabelModel, |
Steven Burrows | f17f0ab | 2017-04-11 11:03:58 -0700 | [diff] [blame] | 1043 | linkConfig: function () { return linkConfig; }, |
| 1044 | deviceScale: deviceScale, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 1045 | linkWidthScale: linkWidthScale, |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 1046 | }; |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 1047 | } |
| 1048 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 1049 | function mkSelectApi() { |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 1050 | return { |
| 1051 | node: function () { return node; }, |
| 1052 | zoomingOrPanning: zoomingOrPanning, |
Simon Hunt | 0c6b2d3 | 2015-03-26 17:46:29 -0700 | [diff] [blame] | 1053 | updateDeviceColors: td3.updateDeviceColors, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 1054 | deselectAllLinks: tls.deselectAllLinks, |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 1055 | }; |
| 1056 | } |
| 1057 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 1058 | function mkTrafficApi() { |
| 1059 | return { |
| 1060 | hovered: tss.hovered, |
| 1061 | somethingSelected: tss.somethingSelected, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 1062 | selectOrder: tss.selectOrder, |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 1063 | }; |
| 1064 | } |
| 1065 | |
| 1066 | function mkOverlayApi() { |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1067 | return { |
Simon Hunt | e9343f3 | 2015-10-21 18:07:46 -0700 | [diff] [blame] | 1068 | clearNodeDeco: clearNodeDeco, |
| 1069 | removeNodeBadges: removeNodeBadges, |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1070 | clearLinkTrafficStyle: clearLinkTrafficStyle, |
| 1071 | removeLinkLabels: removeLinkLabels, |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 1072 | findLinkById: tms.findLinkById, |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 1073 | findNodeById: nodeById, |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1074 | updateLinks: updateLinks, |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 1075 | updateNodes: updateNodes, |
| 1076 | supLayers: suppressLayers, |
| 1077 | unsupNode: unsuppressNode, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 1078 | unsupLink: unsuppressLink, |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 1079 | }; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1080 | } |
| 1081 | |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 1082 | function mkObliqueApi(uplink, fltr) { |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 1083 | return { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 1084 | force: function () { return force; }, |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 1085 | zoomLayer: uplink.zoomLayer, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 1086 | nodeGBBox: function () { return nodeG.node().getBBox(); }, |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 1087 | node: function () { return node; }, |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 1088 | link: function () { return link; }, |
| 1089 | linkLabel: function () { return linkLabel; }, |
| 1090 | nodes: function () { return network.nodes; }, |
| 1091 | tickStuff: tickStuff, |
| 1092 | nodeLock: function (b) { |
| 1093 | var old = nodeLock; |
| 1094 | nodeLock = b; |
| 1095 | return old; |
| 1096 | }, |
| 1097 | opacifyMap: uplink.opacifyMap, |
Bri Prebilic Cole | 038aedd | 2015-07-13 15:25:16 -0700 | [diff] [blame] | 1098 | inLayer: fltr.inLayer, |
Bri Prebilic Cole | 8040176 | 2015-07-16 11:36:18 -0700 | [diff] [blame] | 1099 | calcLinkPos: calcPosition, |
| 1100 | applyNumLinkLabels: function () { |
| 1101 | td3.applyNumLinkLabels(linkNums, numLinkLblsG); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 1102 | }, |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 1103 | }; |
| 1104 | } |
| 1105 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 1106 | function mkFilterApi() { |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 1107 | return { |
| 1108 | node: function () { return node; }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 1109 | link: function () { return link; }, |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 1110 | }; |
| 1111 | } |
| 1112 | |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 1113 | function mkLinkApi(svg, uplink) { |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 1114 | return { |
| 1115 | svg: svg, |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 1116 | zoomer: uplink.zoomer(), |
| 1117 | network: network, |
Simon Hunt | 1a5301e | 2015-02-25 15:31:25 -0800 | [diff] [blame] | 1118 | portLabelG: function () { return portLabelG; }, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 1119 | showHosts: function () { return showHosts; }, |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 1120 | }; |
| 1121 | } |
| 1122 | |
Simon Hunt | f51bf46 | 2016-06-29 16:22:57 -0700 | [diff] [blame] | 1123 | function updateLinksAndNodes() { |
| 1124 | updateLinks(); |
| 1125 | updateNodes(); |
| 1126 | } |
Steven Burrows | ec1f45c | 2016-08-08 16:14:41 +0100 | [diff] [blame] | 1127 | |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 1128 | // invoked after the localization bundle has been received from the server |
| 1129 | function setLionBundle(bundle) { |
| 1130 | topoLion = bundle; |
| 1131 | td3.setLionBundle(bundle); |
| 1132 | fltr.setLionBundle(bundle); |
| 1133 | tls.setLionBundle(bundle); |
Simon Hunt | 1603c69 | 2017-08-10 19:53:35 -0700 | [diff] [blame] | 1134 | tos.setLionBundle(bundle); |
| 1135 | tov.setLionBundle(bundle); |
Simon Hunt | caed041 | 2017-08-12 13:49:17 -0700 | [diff] [blame] | 1136 | tss.setLionBundle(bundle); |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1139 | angular.module('ovTopo') |
| 1140 | .factory('TopoForceService', |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 1141 | ['$log', '$timeout', 'FnService', 'SvgUtilService', |
Simon Hunt | 86b7c88 | 2015-04-02 23:06:08 -0700 | [diff] [blame] | 1142 | 'ThemeService', 'FlashService', 'WebSocketService', |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 1143 | 'TopoOverlayService', 'TopoInstService', 'TopoModelService', |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 1144 | 'TopoD3Service', 'TopoSelectService', 'TopoTrafficService', |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 1145 | 'TopoObliqueService', 'TopoFilterService', 'TopoLinkService', |
Andrea Campanella | 732ea83 | 2017-02-06 09:25:59 -0800 | [diff] [blame] | 1146 | 'TopoProtectedIntentsService', |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1147 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 1148 | function (_$log_, _$timeout_, _fs_, _sus_, _ts_, _flash_, _wss_, _tov_, |
Andrea Campanella | 732ea83 | 2017-02-06 09:25:59 -0800 | [diff] [blame] | 1149 | _tis_, _tms_, _td3_, _tss_, _tts_, _tos_, _fltr_, _tls_, _tpis_) { |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1150 | $log = _$log_; |
Simon Hunt | 86b7c88 | 2015-04-02 23:06:08 -0700 | [diff] [blame] | 1151 | $timeout = _$timeout_; |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 1152 | fs = _fs_; |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1153 | sus = _sus_; |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 1154 | ts = _ts_; |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 1155 | flash = _flash_; |
Simon Hunt | 237676b5 | 2015-03-10 19:04:26 -0700 | [diff] [blame] | 1156 | wss = _wss_; |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 1157 | tov = _tov_; |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 1158 | tis = _tis_; |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1159 | tms = _tms_; |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 1160 | td3 = _td3_; |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 1161 | tss = _tss_; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1162 | tts = _tts_; |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 1163 | tos = _tos_; |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 1164 | fltr = _fltr_; |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 1165 | tls = _tls_; |
Andrea Campanella | 732ea83 | 2017-02-06 09:25:59 -0800 | [diff] [blame] | 1166 | tpis = _tpis_; |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1167 | |
Simon Hunt | f51bf46 | 2016-06-29 16:22:57 -0700 | [diff] [blame] | 1168 | ts.addListener(updateLinksAndNodes); |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 1169 | |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1170 | // forceG is the SVG group to display the force layout in |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 1171 | // uplink is the api from the main topo source file |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1172 | // dim is the initial dimensions of the SVG as [w,h] |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1173 | // opts are, well, optional :) |
Simon Hunt | 3ab2028 | 2015-02-26 20:32:19 -0800 | [diff] [blame] | 1174 | function initForce(_svg_, forceG, _uplink_, _dim_, opts) { |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 1175 | uplink = _uplink_; |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1176 | dim = _dim_; |
Simon Hunt | 3ab2028 | 2015-02-26 20:32:19 -0800 | [diff] [blame] | 1177 | svg = _svg_; |
| 1178 | |
| 1179 | lu = network.lookup; |
| 1180 | rlk = network.revLinkToKey; |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1181 | |
| 1182 | $log.debug('initForce().. dim = ' + dim); |
| 1183 | |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 1184 | tov.setApi(mkOverlayApi(), tss); |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 1185 | tms.initModel(mkModelApi(uplink), dim); |
Steven Burrows | f17f0ab | 2017-04-11 11:03:58 -0700 | [diff] [blame] | 1186 | td3.initD3(mkD3Api(), uplink.zoomer()); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 1187 | tss.initSelect(mkSelectApi()); |
| 1188 | tts.initTraffic(mkTrafficApi()); |
Andrea Campanella | 732ea83 | 2017-02-06 09:25:59 -0800 | [diff] [blame] | 1189 | tpis.initProtectedIntents(mkTrafficApi()); |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 1190 | tos.initOblique(mkObliqueApi(uplink, fltr)); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 1191 | fltr.initFilter(mkFilterApi()); |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 1192 | tls.initLink(mkLinkApi(svg, uplink), td3); |
Simon Hunt | a11b4eb | 2015-01-28 16:20:50 -0800 | [diff] [blame] | 1193 | |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1194 | settings = angular.extend({}, defaultSettings, opts); |
| 1195 | |
| 1196 | linkG = forceG.append('g').attr('id', 'topo-links'); |
| 1197 | linkLabelG = forceG.append('g').attr('id', 'topo-linkLabels'); |
Bri Prebilic Cole | 8040176 | 2015-07-16 11:36:18 -0700 | [diff] [blame] | 1198 | numLinkLblsG = forceG.append('g').attr('id', 'topo-numLinkLabels'); |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1199 | nodeG = forceG.append('g').attr('id', 'topo-nodes'); |
Simon Hunt | 1a5301e | 2015-02-25 15:31:25 -0800 | [diff] [blame] | 1200 | portLabelG = forceG.append('g').attr('id', 'topo-portLabels'); |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1201 | |
| 1202 | link = linkG.selectAll('.link'); |
| 1203 | linkLabel = linkLabelG.selectAll('.linkLabel'); |
| 1204 | node = nodeG.selectAll('.node'); |
| 1205 | |
| 1206 | force = d3.layout.force() |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1207 | .size(dim) |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1208 | .nodes(network.nodes) |
| 1209 | .links(network.links) |
| 1210 | .gravity(settings.gravity) |
| 1211 | .friction(settings.friction) |
| 1212 | .charge(settings.charge._def_) |
| 1213 | .linkDistance(settings.linkDistance._def_) |
| 1214 | .linkStrength(settings.linkStrength._def_) |
| 1215 | .on('tick', tick); |
| 1216 | |
| 1217 | drag = sus.createDragBehavior(force, |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 1218 | tss.selectObject, atDragEnd, dragEnabled, clickEnabled); |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1219 | } |
| 1220 | |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1221 | function newDim(_dim_) { |
| 1222 | dim = _dim_; |
| 1223 | force.size(dim); |
| 1224 | tms.newDim(dim); |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1225 | } |
| 1226 | |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1227 | function destroyForce() { |
Simon Hunt | 3ab2028 | 2015-02-26 20:32:19 -0800 | [diff] [blame] | 1228 | force.stop(); |
| 1229 | |
Simon Hunt | fb8ea1f | 2015-02-24 21:38:09 -0800 | [diff] [blame] | 1230 | tls.destroyLink(); |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 1231 | tos.destroyOblique(); |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1232 | tts.destroyTraffic(); |
Andrea Campanella | 732ea83 | 2017-02-06 09:25:59 -0800 | [diff] [blame] | 1233 | tpis.destroyProtectedIntents(); |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1234 | tss.destroySelect(); |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 1235 | td3.destroyD3(); |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1236 | tms.destroyModel(); |
Simon Hunt | 8d22c4b | 2015-08-06 16:24:43 -0700 | [diff] [blame] | 1237 | // note: no need to destroy overlay service |
Simon Hunt | f51bf46 | 2016-06-29 16:22:57 -0700 | [diff] [blame] | 1238 | ts.removeListener(updateLinksAndNodes); |
Simon Hunt | 3ab2028 | 2015-02-26 20:32:19 -0800 | [diff] [blame] | 1239 | |
| 1240 | // clean up the DOM |
| 1241 | svg.selectAll('g').remove(); |
| 1242 | svg.selectAll('defs').remove(); |
| 1243 | |
| 1244 | // clean up internal state |
| 1245 | network.nodes = []; |
| 1246 | network.links = []; |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 1247 | network.linksByDevice = {}; |
Simon Hunt | 3ab2028 | 2015-02-26 20:32:19 -0800 | [diff] [blame] | 1248 | network.lookup = {}; |
| 1249 | network.revLinkToKey = {}; |
| 1250 | |
Bri Prebilic Cole | 8040176 | 2015-07-16 11:36:18 -0700 | [diff] [blame] | 1251 | linkNums = []; |
| 1252 | |
| 1253 | linkG = linkLabelG = numLinkLblsG = nodeG = portLabelG = null; |
Simon Hunt | 3ab2028 | 2015-02-26 20:32:19 -0800 | [diff] [blame] | 1254 | link = linkLabel = node = null; |
| 1255 | force = drag = null; |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 1256 | |
| 1257 | // clean up $timeout promises |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 1258 | if (fTimer) { |
| 1259 | $timeout.cancel(fTimer); |
| 1260 | } |
Bri Prebilic Cole | aeeb33e | 2015-07-09 15:15:54 -0700 | [diff] [blame] | 1261 | if (fNodesTimer) { |
| 1262 | $timeout.cancel(fNodesTimer); |
| 1263 | } |
| 1264 | if (fLinksTimer) { |
| 1265 | $timeout.cancel(fLinksTimer); |
| 1266 | } |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1267 | } |
| 1268 | |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1269 | return { |
| 1270 | initForce: initForce, |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1271 | newDim: newDim, |
| 1272 | destroyForce: destroyForce, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 1273 | |
Simon Hunt | a4242de | 2015-02-24 17:11:55 -0800 | [diff] [blame] | 1274 | updateDeviceColors: td3.updateDeviceColors, |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 1275 | toggleHosts: toggleHosts, |
Simon Hunt | 9e2104c | 2015-02-26 10:48:59 -0800 | [diff] [blame] | 1276 | togglePorts: tls.togglePorts, |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 1277 | toggleOffline: toggleOffline, |
| 1278 | cycleDeviceLabels: cycleDeviceLabels, |
Simon Hunt | 10618f6 | 2017-06-15 19:30:52 -0700 | [diff] [blame] | 1279 | cycleHostLabels: cycleHostLabels, |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 1280 | unpin: unpin, |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 1281 | showMastership: showMastership, |
Simon Hunt | 86b7c88 | 2015-04-02 23:06:08 -0700 | [diff] [blame] | 1282 | showBadLinks: showBadLinks, |
Steven Burrows | f17f0ab | 2017-04-11 11:03:58 -0700 | [diff] [blame] | 1283 | setNodeScale: setNodeScale, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 1284 | |
Simon Hunt | fd7106c | 2016-02-09 15:05:26 -0800 | [diff] [blame] | 1285 | resetAllLocations: resetAllLocations, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 1286 | addDevice: addDevice, |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 1287 | updateDevice: updateDevice, |
| 1288 | removeDevice: removeDevice, |
| 1289 | addHost: addHost, |
| 1290 | updateHost: updateHost, |
Simon Hunt | 95d56fd | 2015-11-12 11:06:44 -0800 | [diff] [blame] | 1291 | moveHost: moveHost, |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 1292 | removeHost: removeHost, |
| 1293 | addLink: addLink, |
| 1294 | updateLink: updateLink, |
Simon Hunt | 4a6b54b | 2015-10-27 22:08:25 -0700 | [diff] [blame] | 1295 | removeLink: removeLink, |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 1296 | topoStartDone: topoStartDone, |
Simon Hunt | e2d9dc7 | 2017-08-10 15:21:04 -0700 | [diff] [blame] | 1297 | |
| 1298 | setLionBundle: setLionBundle, |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1299 | }; |
| 1300 | }]); |
| 1301 | }()); |