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