Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
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 | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 26 | var $log, fs, sus, is, ts, flash, tis, tms, tss, tts, tos, fltr, |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 27 | icfg, uplink; |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 28 | |
| 29 | // configuration |
| 30 | var labelConfig = { |
| 31 | imgPad: 16, |
| 32 | padLR: 4, |
| 33 | padTB: 3, |
| 34 | marginLR: 3, |
| 35 | marginTB: 2, |
| 36 | port: { |
| 37 | gap: 3, |
| 38 | width: 18, |
| 39 | height: 14 |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | var deviceIconConfig = { |
| 44 | xoff: -20, |
| 45 | yoff: -18 |
| 46 | }; |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 47 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 48 | var linkConfig = { |
| 49 | light: { |
| 50 | baseColor: '#666', |
| 51 | inColor: '#66f', |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 52 | outColor: '#f00' |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 53 | }, |
| 54 | dark: { |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 55 | baseColor: '#aaa', |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 56 | inColor: '#66f', |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 57 | outColor: '#f66' |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 58 | }, |
| 59 | inWidth: 12, |
| 60 | outWidth: 10 |
| 61 | }; |
| 62 | |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 63 | // internal state |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 64 | var settings, // merged default settings and options |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 65 | force, // force layout object |
| 66 | drag, // drag behavior handler |
| 67 | network = { |
| 68 | nodes: [], |
| 69 | links: [], |
| 70 | lookup: {}, |
| 71 | revLinkToKey: {} |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 72 | }, |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 73 | lu = network.lookup, // shorthand |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 74 | rlk = network.revLinkToKey, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 75 | deviceLabelIndex = 0, // for device label cycling |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 76 | hostLabelIndex = 0, // for host label cycling |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 77 | showHosts = false, // whether hosts are displayed |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 78 | showOffline = true, // whether offline devices are displayed |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 79 | nodeLock = false, // whether nodes can be dragged or not (locked) |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 80 | dim; // the dimensions of the force layout [w,h] |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 81 | |
| 82 | // SVG elements; |
| 83 | var linkG, linkLabelG, nodeG; |
| 84 | |
| 85 | // D3 selections; |
| 86 | var link, linkLabel, node; |
| 87 | |
| 88 | // default settings for force layout |
| 89 | var defaultSettings = { |
| 90 | gravity: 0.4, |
| 91 | friction: 0.7, |
| 92 | charge: { |
| 93 | // note: key is node.class |
| 94 | device: -8000, |
| 95 | host: -5000, |
| 96 | _def_: -12000 |
| 97 | }, |
| 98 | linkDistance: { |
| 99 | // note: key is link.type |
| 100 | direct: 100, |
| 101 | optical: 120, |
| 102 | hostLink: 3, |
| 103 | _def_: 50 |
| 104 | }, |
| 105 | linkStrength: { |
| 106 | // note: key is link.type |
| 107 | // range: {0.0 ... 1.0} |
| 108 | //direct: 1.0, |
| 109 | //optical: 1.0, |
| 110 | //hostLink: 1.0, |
| 111 | _def_: 1.0 |
| 112 | } |
| 113 | }; |
| 114 | |
| 115 | |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 116 | // ========================== |
| 117 | // === EVENT HANDLERS |
| 118 | |
| 119 | function addDevice(data) { |
| 120 | var id = data.id, |
| 121 | d; |
| 122 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 123 | uplink.showNoDevs(false); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 124 | |
| 125 | // although this is an add device event, if we already have the |
| 126 | // device, treat it as an update instead.. |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 127 | if (lu[id]) { |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 128 | updateDevice(data); |
| 129 | return; |
| 130 | } |
| 131 | |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 132 | d = tms.createDeviceNode(data); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 133 | network.nodes.push(d); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 134 | lu[id] = d; |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 135 | updateNodes(); |
| 136 | fStart(); |
| 137 | } |
| 138 | |
| 139 | function updateDevice(data) { |
| 140 | var id = data.id, |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 141 | d = lu[id], |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 142 | wasOnline; |
| 143 | |
| 144 | if (d) { |
| 145 | wasOnline = d.online; |
| 146 | angular.extend(d, data); |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 147 | if (tms.positionNode(d, true)) { |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 148 | sendUpdateMeta(d); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 149 | } |
| 150 | updateNodes(); |
| 151 | if (wasOnline !== d.online) { |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 152 | tms.findAttachedLinks(d.id).forEach(restyleLinkElement); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 153 | updateOfflineVisibility(d); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 154 | } |
| 155 | } else { |
| 156 | // TODO: decide whether we want to capture logic errors |
| 157 | //logicError('updateDevice lookup fail. ID = "' + id + '"'); |
| 158 | } |
| 159 | } |
| 160 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 161 | function removeDevice(data) { |
| 162 | var id = data.id, |
| 163 | d = lu[id]; |
| 164 | if (d) { |
| 165 | removeDeviceElement(d); |
| 166 | } else { |
| 167 | // TODO: decide whether we want to capture logic errors |
| 168 | //logicError('removeDevice lookup fail. ID = "' + id + '"'); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | function addHost(data) { |
| 173 | var id = data.id, |
| 174 | d, lnk; |
| 175 | |
| 176 | // although this is an add host event, if we already have the |
| 177 | // host, treat it as an update instead.. |
| 178 | if (lu[id]) { |
| 179 | updateHost(data); |
| 180 | return; |
| 181 | } |
| 182 | |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 183 | d = tms.createHostNode(data); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 184 | network.nodes.push(d); |
| 185 | lu[id] = d; |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 186 | updateNodes(); |
| 187 | |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 188 | lnk = tms.createHostLink(data); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 189 | if (lnk) { |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 190 | d.linkData = lnk; // cache ref on its host |
| 191 | network.links.push(lnk); |
| 192 | lu[d.ingress] = lnk; |
| 193 | lu[d.egress] = lnk; |
| 194 | updateLinks(); |
| 195 | } |
| 196 | |
| 197 | fStart(); |
| 198 | } |
| 199 | |
| 200 | function updateHost(data) { |
| 201 | var id = data.id, |
| 202 | d = lu[id]; |
| 203 | if (d) { |
| 204 | angular.extend(d, data); |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 205 | if (tms.positionNode(d, true)) { |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 206 | sendUpdateMeta(d); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 207 | } |
| 208 | updateNodes(); |
| 209 | } else { |
| 210 | // TODO: decide whether we want to capture logic errors |
| 211 | //logicError('updateHost lookup fail. ID = "' + id + '"'); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | function removeHost(data) { |
| 216 | var id = data.id, |
| 217 | d = lu[id]; |
| 218 | if (d) { |
| 219 | removeHostElement(d, true); |
| 220 | } else { |
| 221 | // may have already removed host, if attached to removed device |
| 222 | //console.warn('removeHost lookup fail. ID = "' + id + '"'); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | function addLink(data) { |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 227 | var result = tms.findLink(data, 'add'), |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 228 | bad = result.badLogic, |
| 229 | d = result.ldata; |
| 230 | |
| 231 | if (bad) { |
| 232 | //logicError(bad + ': ' + link.id); |
| 233 | return; |
| 234 | } |
| 235 | |
| 236 | if (d) { |
| 237 | // we already have a backing store link for src/dst nodes |
| 238 | addLinkUpdate(d, data); |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | // no backing store link yet |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 243 | d = tms.createLink(data); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 244 | if (d) { |
| 245 | network.links.push(d); |
| 246 | lu[d.key] = d; |
| 247 | updateLinks(); |
| 248 | fStart(); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | function updateLink(data) { |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 253 | var result = tms.findLink(data, 'update'), |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 254 | bad = result.badLogic; |
| 255 | if (bad) { |
| 256 | //logicError(bad + ': ' + link.id); |
| 257 | return; |
| 258 | } |
| 259 | result.updateWith(link); |
| 260 | } |
| 261 | |
| 262 | function removeLink(data) { |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 263 | var result = tms.findLink(data, 'remove'), |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 264 | bad = result.badLogic; |
| 265 | if (bad) { |
| 266 | // may have already removed link, if attached to removed device |
| 267 | //console.warn(bad + ': ' + link.id); |
| 268 | return; |
| 269 | } |
| 270 | result.removeRawLink(); |
| 271 | } |
| 272 | |
| 273 | // ======================== |
| 274 | |
| 275 | function addLinkUpdate(ldata, link) { |
| 276 | // add link event, but we already have the reverse link installed |
| 277 | ldata.fromTarget = link; |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 278 | rlk[link.id] = ldata.key; |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 279 | restyleLinkElement(ldata); |
| 280 | } |
| 281 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 282 | |
| 283 | var widthRatio = 1.4, |
| 284 | linkScale = d3.scale.linear() |
| 285 | .domain([1, 12]) |
| 286 | .range([widthRatio, 12 * widthRatio]) |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 287 | .clamp(true), |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 288 | allLinkTypes = 'direct indirect optical tunnel'; |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 289 | |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 290 | function restyleLinkElement(ldata, immediate) { |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 291 | // this fn's job is to look at raw links and decide what svg classes |
| 292 | // need to be applied to the line element in the DOM |
| 293 | var th = ts.theme(), |
| 294 | el = ldata.el, |
| 295 | type = ldata.type(), |
| 296 | lw = ldata.linkWidth(), |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 297 | online = ldata.online(), |
| 298 | delay = immediate ? 0 : 1000; |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 299 | |
| 300 | el.classed('link', true); |
| 301 | el.classed('inactive', !online); |
| 302 | el.classed(allLinkTypes, false); |
| 303 | if (type) { |
| 304 | el.classed(type, true); |
| 305 | } |
| 306 | el.transition() |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 307 | .duration(delay) |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 308 | .attr('stroke-width', linkScale(lw)) |
| 309 | .attr('stroke', linkConfig[th].baseColor); |
| 310 | } |
| 311 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 312 | function removeLinkElement(d) { |
| 313 | var idx = fs.find(d.key, network.links, 'key'), |
| 314 | removed; |
| 315 | if (idx >=0) { |
| 316 | // remove from links array |
| 317 | removed = network.links.splice(idx, 1); |
| 318 | // remove from lookup cache |
| 319 | delete lu[removed[0].key]; |
| 320 | updateLinks(); |
| 321 | fResume(); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | function removeHostElement(d, upd) { |
| 326 | // first, remove associated hostLink... |
| 327 | removeLinkElement(d.linkData); |
| 328 | |
| 329 | // remove hostLink bindings |
| 330 | delete lu[d.ingress]; |
| 331 | delete lu[d.egress]; |
| 332 | |
| 333 | // remove from lookup cache |
| 334 | delete lu[d.id]; |
| 335 | // remove from nodes array |
| 336 | var idx = fs.find(d.id, network.nodes); |
| 337 | network.nodes.splice(idx, 1); |
| 338 | |
| 339 | // remove from SVG |
| 340 | // NOTE: upd is false if we were called from removeDeviceElement() |
| 341 | if (upd) { |
| 342 | updateNodes(); |
| 343 | fResume(); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | function removeDeviceElement(d) { |
| 348 | var id = d.id; |
| 349 | // first, remove associated hosts and links.. |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 350 | tms.findAttachedHosts(id).forEach(removeHostElement); |
| 351 | tms.findAttachedLinks(id).forEach(removeLinkElement); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 352 | |
| 353 | // remove from lookup cache |
| 354 | delete lu[id]; |
| 355 | // remove from nodes array |
| 356 | var idx = fs.find(id, network.nodes); |
| 357 | network.nodes.splice(idx, 1); |
| 358 | |
| 359 | if (!network.nodes.length) { |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 360 | uplink.showNoDevs(true); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | // remove from SVG |
| 364 | updateNodes(); |
| 365 | fResume(); |
| 366 | } |
| 367 | |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 368 | function updateHostVisibility() { |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 369 | sus.visible(nodeG.selectAll('.host'), showHosts); |
| 370 | sus.visible(linkG.selectAll('.hostLink'), showHosts); |
Simon Hunt | 8eb4d3a | 2015-02-23 18:23:29 -0800 | [diff] [blame] | 371 | sus.visible(linkLabelG.selectAll('.hostLinkLabel'), showHosts); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | function updateOfflineVisibility(dev) { |
| 375 | function updDev(d, show) { |
Simon Hunt | 8eb4d3a | 2015-02-23 18:23:29 -0800 | [diff] [blame] | 376 | var b; |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 377 | sus.visible(d.el, show); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 378 | |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 379 | tms.findAttachedLinks(d.id).forEach(function (link) { |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 380 | b = show && ((link.type() !== 'hostLink') || showHosts); |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 381 | sus.visible(link.el, b); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 382 | }); |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 383 | tms.findAttachedHosts(d.id).forEach(function (host) { |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 384 | b = show && showHosts; |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 385 | sus.visible(host.el, b); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 386 | }); |
| 387 | } |
| 388 | |
| 389 | if (dev) { |
| 390 | // updating a specific device that just toggled off/on-line |
| 391 | updDev(dev, dev.online || showOffline); |
| 392 | } else { |
| 393 | // updating all offline devices |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 394 | tms.findDevices(true).forEach(function (d) { |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 395 | updDev(d, showOffline); |
| 396 | }); |
| 397 | } |
| 398 | } |
| 399 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 400 | |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 401 | function sendUpdateMeta(d, clearPos) { |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 402 | var metaUi = {}, |
| 403 | ll; |
| 404 | |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 405 | // if we are not clearing the position data (unpinning), |
| 406 | // attach the x, y, longitude, latitude... |
| 407 | if (!clearPos) { |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 408 | ll = tms.lngLatFromCoord([d.x, d.y]); |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 409 | metaUi = {x: d.x, y: d.y, lng: ll[0], lat: ll[1]}; |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 410 | } |
| 411 | d.metaUi = metaUi; |
| 412 | uplink.sendEvent('updateMeta', { |
| 413 | id: d.id, |
| 414 | 'class': d.class, |
| 415 | memento: metaUi |
| 416 | }); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 417 | } |
| 418 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 419 | |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 420 | // ========================== |
| 421 | // === Devices and hosts - D3 rendering |
| 422 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 423 | |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 424 | // Returns the newly computed bounding box of the rectangle |
| 425 | function adjustRectToFitText(n) { |
| 426 | var text = n.select('text'), |
| 427 | box = text.node().getBBox(), |
| 428 | lab = labelConfig; |
| 429 | |
| 430 | text.attr('text-anchor', 'middle') |
| 431 | .attr('y', '-0.8em') |
| 432 | .attr('x', lab.imgPad/2); |
| 433 | |
| 434 | // translate the bbox so that it is centered on [x,y] |
| 435 | box.x = -box.width / 2; |
| 436 | box.y = -box.height / 2; |
| 437 | |
| 438 | // add padding |
| 439 | box.x -= (lab.padLR + lab.imgPad/2); |
| 440 | box.width += lab.padLR * 2 + lab.imgPad; |
| 441 | box.y -= lab.padTB; |
| 442 | box.height += lab.padTB * 2; |
| 443 | |
| 444 | return box; |
| 445 | } |
| 446 | |
| 447 | function mkSvgClass(d) { |
| 448 | return d.fixed ? d.svgClass + ' fixed' : d.svgClass; |
| 449 | } |
| 450 | |
| 451 | function hostLabel(d) { |
| 452 | var idx = (hostLabelIndex < d.labels.length) ? hostLabelIndex : 0; |
| 453 | return d.labels[idx]; |
| 454 | } |
| 455 | function deviceLabel(d) { |
| 456 | var idx = (deviceLabelIndex < d.labels.length) ? deviceLabelIndex : 0; |
| 457 | return d.labels[idx]; |
| 458 | } |
| 459 | function trimLabel(label) { |
| 460 | return (label && label.trim()) || ''; |
| 461 | } |
| 462 | |
| 463 | function emptyBox() { |
| 464 | return { |
| 465 | x: -2, |
| 466 | y: -2, |
| 467 | width: 4, |
| 468 | height: 4 |
| 469 | }; |
| 470 | } |
| 471 | |
| 472 | |
| 473 | function updateDeviceLabel(d) { |
| 474 | var label = trimLabel(deviceLabel(d)), |
| 475 | noLabel = !label, |
| 476 | node = d.el, |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 477 | dim = icfg.device.dim, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 478 | devCfg = deviceIconConfig, |
| 479 | box, dx, dy; |
| 480 | |
| 481 | node.select('text') |
| 482 | .text(label) |
| 483 | .style('opacity', 0) |
| 484 | .transition() |
| 485 | .style('opacity', 1); |
| 486 | |
| 487 | if (noLabel) { |
| 488 | box = emptyBox(); |
| 489 | dx = -dim/2; |
| 490 | dy = -dim/2; |
| 491 | } else { |
| 492 | box = adjustRectToFitText(node); |
| 493 | dx = box.x + devCfg.xoff; |
| 494 | dy = box.y + devCfg.yoff; |
| 495 | } |
| 496 | |
| 497 | node.select('rect') |
| 498 | .transition() |
| 499 | .attr(box); |
| 500 | |
| 501 | node.select('g.deviceIcon') |
| 502 | .transition() |
| 503 | .attr('transform', sus.translate(dx, dy)); |
| 504 | } |
| 505 | |
| 506 | function updateHostLabel(d) { |
| 507 | var label = trimLabel(hostLabel(d)); |
| 508 | d.el.select('text').text(label); |
| 509 | } |
| 510 | |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 511 | function updateDeviceColors(d) { |
| 512 | if (d) { |
| 513 | setDeviceColor(d); |
| 514 | } else { |
| 515 | node.filter('.device').each(function (d) { |
| 516 | setDeviceColor(d); |
| 517 | }); |
| 518 | } |
| 519 | } |
| 520 | |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 521 | function vis(b) { |
| 522 | return b ? 'visible' : 'hidden'; |
| 523 | } |
| 524 | |
| 525 | function toggleHosts() { |
| 526 | showHosts = !showHosts; |
| 527 | updateHostVisibility(); |
| 528 | flash.flash('Hosts ' + vis(showHosts)); |
| 529 | } |
| 530 | |
| 531 | function toggleOffline() { |
| 532 | showOffline = !showOffline; |
| 533 | updateOfflineVisibility(); |
| 534 | flash.flash('Offline devices ' + vis(showOffline)); |
| 535 | } |
| 536 | |
| 537 | function cycleDeviceLabels() { |
Simon Hunt | 1c36711 | 2015-02-05 18:02:46 -0800 | [diff] [blame] | 538 | deviceLabelIndex = (deviceLabelIndex+1) % 3; |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 539 | tms.findDevices().forEach(function (d) { |
Simon Hunt | 1c36711 | 2015-02-05 18:02:46 -0800 | [diff] [blame] | 540 | updateDeviceLabel(d); |
| 541 | }); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 542 | } |
| 543 | |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 544 | function unpin() { |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 545 | var hov = tss.hovered(); |
| 546 | if (hov) { |
| 547 | sendUpdateMeta(hov, true); |
| 548 | hov.fixed = false; |
| 549 | hov.el.classed('fixed', false); |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 550 | fResume(); |
| 551 | } |
| 552 | } |
| 553 | |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 554 | function showMastership(masterId) { |
| 555 | if (!masterId) { |
| 556 | restoreLayerState(); |
| 557 | } else { |
| 558 | showMastershipFor(masterId); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | function restoreLayerState() { |
| 563 | // NOTE: this level of indirection required, for when we have |
| 564 | // the layer filter functionality re-implemented |
| 565 | suppressLayers(false); |
| 566 | } |
| 567 | |
| 568 | function showMastershipFor(id) { |
| 569 | suppressLayers(true); |
| 570 | node.each(function (n) { |
| 571 | if (n.master === id) { |
| 572 | n.el.classed('suppressed', false); |
| 573 | } |
| 574 | }); |
| 575 | } |
| 576 | |
| 577 | function suppressLayers(b) { |
| 578 | node.classed('suppressed', b); |
| 579 | link.classed('suppressed', b); |
| 580 | // d3.selectAll('svg .port').classed('inactive', b); |
| 581 | // d3.selectAll('svg .portText').classed('inactive', b); |
| 582 | } |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 583 | |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 584 | // ========================================== |
| 585 | |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 586 | var dCol = { |
| 587 | black: '#000', |
| 588 | paleblue: '#acf', |
| 589 | offwhite: '#ddd', |
Simon Hunt | 78c10bf | 2015-02-03 21:18:20 -0800 | [diff] [blame] | 590 | darkgrey: '#444', |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 591 | midgrey: '#888', |
| 592 | lightgrey: '#bbb', |
| 593 | orange: '#f90' |
| 594 | }; |
| 595 | |
| 596 | // note: these are the device icon colors without affinity |
| 597 | var dColTheme = { |
| 598 | light: { |
Simon Hunt | 78c10bf | 2015-02-03 21:18:20 -0800 | [diff] [blame] | 599 | rfill: dCol.offwhite, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 600 | online: { |
Simon Hunt | 78c10bf | 2015-02-03 21:18:20 -0800 | [diff] [blame] | 601 | glyph: dCol.darkgrey, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 602 | rect: dCol.paleblue |
| 603 | }, |
| 604 | offline: { |
| 605 | glyph: dCol.midgrey, |
| 606 | rect: dCol.lightgrey |
| 607 | } |
| 608 | }, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 609 | dark: { |
Simon Hunt | 78c10bf | 2015-02-03 21:18:20 -0800 | [diff] [blame] | 610 | rfill: dCol.midgrey, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 611 | online: { |
Simon Hunt | 78c10bf | 2015-02-03 21:18:20 -0800 | [diff] [blame] | 612 | glyph: dCol.darkgrey, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 613 | rect: dCol.paleblue |
| 614 | }, |
| 615 | offline: { |
| 616 | glyph: dCol.midgrey, |
Simon Hunt | 78c10bf | 2015-02-03 21:18:20 -0800 | [diff] [blame] | 617 | rect: dCol.darkgrey |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | }; |
| 621 | |
| 622 | function devBaseColor(d) { |
| 623 | var o = d.online ? 'online' : 'offline'; |
| 624 | return dColTheme[ts.theme()][o]; |
| 625 | } |
| 626 | |
| 627 | function setDeviceColor(d) { |
| 628 | var o = d.online, |
| 629 | s = d.el.classed('selected'), |
| 630 | c = devBaseColor(d), |
| 631 | a = instColor(d.master, o), |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 632 | icon = d.el.select('g.deviceIcon'), |
| 633 | g, r; |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 634 | |
| 635 | if (s) { |
| 636 | g = c.glyph; |
| 637 | r = dCol.orange; |
| 638 | } else if (tis.isVisible()) { |
| 639 | g = o ? a : c.glyph; |
Simon Hunt | 78c10bf | 2015-02-03 21:18:20 -0800 | [diff] [blame] | 640 | r = o ? c.rfill : a; |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 641 | } else { |
| 642 | g = c.glyph; |
| 643 | r = c.rect; |
| 644 | } |
| 645 | |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 646 | icon.select('use').style('fill', g); |
| 647 | icon.select('rect').style('fill', r); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | function instColor(id, online) { |
| 651 | return sus.cat7().getColor(id, !online, ts.theme()); |
| 652 | } |
| 653 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 654 | // ========================== |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 655 | |
| 656 | function updateNodes() { |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 657 | // select all the nodes in the layout: |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 658 | node = nodeG.selectAll('.node') |
| 659 | .data(network.nodes, function (d) { return d.id; }); |
| 660 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 661 | // operate on existing nodes: |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 662 | node.filter('.device').each(deviceExisting); |
| 663 | node.filter('.host').each(hostExisting); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 664 | |
| 665 | // operate on entering nodes: |
| 666 | var entering = node.enter() |
| 667 | .append('g') |
| 668 | .attr({ |
| 669 | id: function (d) { return sus.safeId(d.id); }, |
| 670 | class: mkSvgClass, |
| 671 | transform: function (d) { return sus.translate(d.x, d.y); }, |
| 672 | opacity: 0 |
| 673 | }) |
| 674 | .call(drag) |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 675 | .on('mouseover', tss.nodeMouseOver) |
| 676 | .on('mouseout', tss.nodeMouseOut) |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 677 | .transition() |
| 678 | .attr('opacity', 1); |
| 679 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 680 | // augment entering nodes: |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 681 | entering.filter('.device').each(deviceEnter); |
| 682 | entering.filter('.host').each(hostEnter); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 683 | |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 684 | // operate on both existing and new nodes: |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 685 | updateDeviceColors(); |
| 686 | |
| 687 | // operate on exiting nodes: |
| 688 | // Note that the node is removed after 2 seconds. |
| 689 | // Sub element animations should be shorter than 2 seconds. |
| 690 | var exiting = node.exit() |
| 691 | .transition() |
| 692 | .duration(2000) |
| 693 | .style('opacity', 0) |
| 694 | .remove(); |
| 695 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 696 | // exiting node specifics: |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 697 | exiting.filter('.host').each(hostExit); |
| 698 | exiting.filter('.device').each(deviceExit); |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 699 | |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 700 | // finally, resume the force layout |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 701 | fResume(); |
| 702 | } |
| 703 | |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 704 | // ========================== |
| 705 | // updateNodes - subfunctions |
| 706 | |
| 707 | function deviceExisting(d) { |
| 708 | var node = d.el; |
| 709 | node.classed('online', d.online); |
| 710 | updateDeviceLabel(d); |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 711 | tms.positionNode(d, true); |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | function hostExisting(d) { |
| 715 | updateHostLabel(d); |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 716 | tms.positionNode(d, true); |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | function deviceEnter(d) { |
| 720 | var node = d3.select(this), |
| 721 | glyphId = d.type || 'unknown', |
| 722 | label = trimLabel(deviceLabel(d)), |
| 723 | devCfg = deviceIconConfig, |
| 724 | noLabel = !label, |
| 725 | box, dx, dy, icon; |
| 726 | |
| 727 | d.el = node; |
| 728 | |
| 729 | node.append('rect').attr({ rx: 5, ry: 5 }); |
| 730 | node.append('text').text(label).attr('dy', '1.1em'); |
| 731 | box = adjustRectToFitText(node); |
| 732 | node.select('rect').attr(box); |
| 733 | |
| 734 | icon = is.addDeviceIcon(node, glyphId); |
| 735 | |
| 736 | if (noLabel) { |
| 737 | dx = -icon.dim/2; |
| 738 | dy = -icon.dim/2; |
| 739 | } else { |
| 740 | box = adjustRectToFitText(node); |
| 741 | dx = box.x + devCfg.xoff; |
| 742 | dy = box.y + devCfg.yoff; |
| 743 | } |
| 744 | |
| 745 | icon.attr('transform', sus.translate(dx, dy)); |
| 746 | } |
| 747 | |
| 748 | function hostEnter(d) { |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 749 | var node = d3.select(this), |
| 750 | gid = d.type || 'unknown', |
| 751 | rad = icfg.host.radius, |
| 752 | r = d.type ? rad.withGlyph : rad.noGlyph, |
| 753 | textDy = r + 10; |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 754 | |
| 755 | d.el = node; |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 756 | sus.visible(node, showHosts); |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 757 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 758 | is.addHostIcon(node, r, gid); |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 759 | |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 760 | node.append('text') |
| 761 | .text(hostLabel) |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 762 | .attr('dy', textDy) |
Simon Hunt | 5105659 | 2015-02-03 21:48:07 -0800 | [diff] [blame] | 763 | .attr('text-anchor', 'middle'); |
| 764 | } |
| 765 | |
| 766 | function hostExit(d) { |
| 767 | var node = d.el; |
| 768 | node.select('use') |
| 769 | .style('opacity', 0.5) |
| 770 | .transition() |
| 771 | .duration(800) |
| 772 | .style('opacity', 0); |
| 773 | |
| 774 | node.select('text') |
| 775 | .style('opacity', 0.5) |
| 776 | .transition() |
| 777 | .duration(800) |
| 778 | .style('opacity', 0); |
| 779 | |
| 780 | node.select('circle') |
| 781 | .style('stroke-fill', '#555') |
| 782 | .style('fill', '#888') |
| 783 | .style('opacity', 0.5) |
| 784 | .transition() |
| 785 | .duration(1500) |
| 786 | .attr('r', 0); |
| 787 | } |
| 788 | |
| 789 | function deviceExit(d) { |
| 790 | var node = d.el; |
| 791 | node.select('use') |
| 792 | .style('opacity', 0.5) |
| 793 | .transition() |
| 794 | .duration(800) |
| 795 | .style('opacity', 0); |
| 796 | |
| 797 | node.selectAll('rect') |
| 798 | .style('stroke-fill', '#555') |
| 799 | .style('fill', '#888') |
| 800 | .style('opacity', 0.5); |
| 801 | } |
| 802 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 803 | // ========================== |
| 804 | |
| 805 | function updateLinks() { |
| 806 | var th = ts.theme(); |
| 807 | |
| 808 | link = linkG.selectAll('.link') |
| 809 | .data(network.links, function (d) { return d.key; }); |
| 810 | |
| 811 | // operate on existing links: |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 812 | link.each(linkExisting); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 813 | |
| 814 | // operate on entering links: |
| 815 | var entering = link.enter() |
| 816 | .append('line') |
| 817 | .attr({ |
| 818 | x1: function (d) { return d.x1; }, |
| 819 | y1: function (d) { return d.y1; }, |
| 820 | x2: function (d) { return d.x2; }, |
| 821 | y2: function (d) { return d.y2; }, |
| 822 | stroke: linkConfig[th].inColor, |
| 823 | 'stroke-width': linkConfig.inWidth |
| 824 | }); |
| 825 | |
| 826 | // augment links |
| 827 | entering.each(linkEntering); |
| 828 | |
| 829 | // operate on both existing and new links: |
| 830 | //link.each(...) |
| 831 | |
| 832 | // apply or remove labels |
| 833 | var labelData = getLabelData(); |
| 834 | applyLinkLabels(labelData); |
| 835 | |
| 836 | // operate on exiting links: |
| 837 | link.exit() |
| 838 | .attr('stroke-dasharray', '3 3') |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 839 | .attr('stroke', linkConfig[th].outColor) |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 840 | .style('opacity', 0.5) |
| 841 | .transition() |
| 842 | .duration(1500) |
| 843 | .attr({ |
| 844 | 'stroke-dasharray': '3 12', |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 845 | 'stroke-width': linkConfig.outWidth |
| 846 | }) |
| 847 | .style('opacity', 0.0) |
| 848 | .remove(); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | // ========================== |
| 852 | // updateLinks - subfunctions |
| 853 | |
| 854 | function getLabelData() { |
| 855 | // create the backing data for showing labels.. |
| 856 | var data = []; |
| 857 | link.each(function (d) { |
| 858 | if (d.label) { |
| 859 | data.push({ |
| 860 | id: 'lab-' + d.key, |
| 861 | key: d.key, |
| 862 | label: d.label, |
| 863 | ldata: d |
| 864 | }); |
| 865 | } |
| 866 | }); |
| 867 | return data; |
| 868 | } |
| 869 | |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 870 | function linkExisting(d) { |
Simon Hunt | e01de78 | 2015-02-19 16:01:02 -0800 | [diff] [blame] | 871 | // this is supposed to be an existing link, but we have observed |
| 872 | // occasions (where links are deleted and added rapidly?) where |
| 873 | // the DOM element has not been defined. So protection against that... |
| 874 | if (d.el) { |
| 875 | restyleLinkElement(d, true); |
| 876 | } |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 877 | } |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 878 | |
| 879 | function linkEntering(d) { |
| 880 | var link = d3.select(this); |
| 881 | d.el = link; |
| 882 | restyleLinkElement(d); |
| 883 | if (d.type() === 'hostLink') { |
Simon Hunt | 18bf982 | 2015-02-12 17:35:45 -0800 | [diff] [blame] | 884 | sus.visible(link, showHosts); |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | |
| 888 | //function linkExiting(d) { } |
| 889 | |
| 890 | var linkLabelOffset = '0.3em'; |
| 891 | |
| 892 | function applyLinkLabels(data) { |
| 893 | var entering; |
| 894 | |
| 895 | linkLabel = linkLabelG.selectAll('.linkLabel') |
| 896 | .data(data, function (d) { return d.id; }); |
| 897 | |
| 898 | // for elements already existing, we need to update the text |
| 899 | // and adjust the rectangle size to fit |
| 900 | linkLabel.each(function (d) { |
| 901 | var el = d3.select(this), |
| 902 | rect = el.select('rect'), |
| 903 | text = el.select('text'); |
| 904 | text.text(d.label); |
| 905 | rect.attr(rectAroundText(el)); |
| 906 | }); |
| 907 | |
| 908 | entering = linkLabel.enter().append('g') |
| 909 | .classed('linkLabel', true) |
| 910 | .attr('id', function (d) { return d.id; }); |
| 911 | |
| 912 | entering.each(function (d) { |
| 913 | var el = d3.select(this), |
| 914 | rect, |
| 915 | text, |
| 916 | parms = { |
Simon Hunt | 4d4996e | 2015-02-24 11:28:48 -0800 | [diff] [blame^] | 917 | x1: d.ldata.source.x, |
| 918 | y1: d.ldata.source.y, |
| 919 | x2: d.ldata.target.x, |
| 920 | y2: d.ldata.target.y |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 921 | }; |
| 922 | |
Simon Hunt | 8eb4d3a | 2015-02-23 18:23:29 -0800 | [diff] [blame] | 923 | if (d.ldata.type() === 'hostLink') { |
| 924 | el.classed('hostLinkLabel', true); |
| 925 | sus.visible(el, showHosts); |
| 926 | } |
| 927 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 928 | d.el = el; |
| 929 | rect = el.append('rect'); |
| 930 | text = el.append('text').text(d.label); |
| 931 | rect.attr(rectAroundText(el)); |
| 932 | text.attr('dy', linkLabelOffset); |
| 933 | |
| 934 | el.attr('transform', transformLabel(parms)); |
| 935 | }); |
| 936 | |
| 937 | // Remove any labels that are no longer required. |
| 938 | linkLabel.exit().remove(); |
| 939 | } |
| 940 | |
| 941 | function rectAroundText(el) { |
| 942 | var text = el.select('text'), |
| 943 | box = text.node().getBBox(); |
| 944 | |
| 945 | // translate the bbox so that it is centered on [x,y] |
| 946 | box.x = -box.width / 2; |
| 947 | box.y = -box.height / 2; |
| 948 | |
| 949 | // add padding |
| 950 | box.x -= 1; |
| 951 | box.width += 2; |
| 952 | return box; |
| 953 | } |
| 954 | |
| 955 | function transformLabel(p) { |
| 956 | var dx = p.x2 - p.x1, |
| 957 | dy = p.y2 - p.y1, |
| 958 | xMid = dx/2 + p.x1, |
| 959 | yMid = dy/2 + p.y1; |
| 960 | return sus.translate(xMid, yMid); |
| 961 | } |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 962 | |
| 963 | // ========================== |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 964 | // force layout tick function |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 965 | |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 966 | function fResume() { |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 967 | if (!tos.isOblique()) { |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 968 | force.resume(); |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | function fStart() { |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 973 | if (!tos.isOblique()) { |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 974 | force.start(); |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | var tickStuff = { |
| 979 | nodeAttr: { |
| 980 | transform: function (d) { return sus.translate(d.x, d.y); } |
| 981 | }, |
| 982 | linkAttr: { |
| 983 | x1: function (d) { return d.source.x; }, |
| 984 | y1: function (d) { return d.source.y; }, |
| 985 | x2: function (d) { return d.target.x; }, |
| 986 | y2: function (d) { return d.target.y; } |
| 987 | }, |
| 988 | linkLabelAttr: { |
| 989 | transform: function (d) { |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 990 | var lnk = tms.findLinkById(d.key); |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 991 | if (lnk) { |
| 992 | return transformLabel({ |
| 993 | x1: lnk.source.x, |
| 994 | y1: lnk.source.y, |
| 995 | x2: lnk.target.x, |
| 996 | y2: lnk.target.y |
| 997 | }); |
| 998 | } |
| 999 | } |
| 1000 | } |
| 1001 | }; |
| 1002 | |
| 1003 | function tick() { |
| 1004 | node.attr(tickStuff.nodeAttr); |
| 1005 | link.attr(tickStuff.linkAttr); |
| 1006 | linkLabel.attr(tickStuff.linkLabelAttr); |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 1010 | // ========================== |
| 1011 | // === MOUSE GESTURE HANDLERS |
| 1012 | |
Simon Hunt | 205099e | 2015-02-07 13:12:01 -0800 | [diff] [blame] | 1013 | function zoomingOrPanning(ev) { |
| 1014 | return ev.metaKey || ev.altKey; |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | function atDragEnd(d) { |
| 1018 | // once we've finished moving, pin the node in position |
| 1019 | d.fixed = true; |
| 1020 | d3.select(this).classed('fixed', true); |
| 1021 | sendUpdateMeta(d); |
| 1022 | } |
| 1023 | |
| 1024 | // predicate that indicates when dragging is active |
| 1025 | function dragEnabled() { |
| 1026 | var ev = d3.event.sourceEvent; |
| 1027 | // nodeLock means we aren't allowing nodes to be dragged... |
Simon Hunt | 205099e | 2015-02-07 13:12:01 -0800 | [diff] [blame] | 1028 | return !nodeLock && !zoomingOrPanning(ev); |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | // predicate that indicates when clicking is active |
| 1032 | function clickEnabled() { |
| 1033 | return true; |
| 1034 | } |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1035 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1036 | // ========================== |
| 1037 | // function entry points for traffic module |
| 1038 | |
| 1039 | var allTrafficClasses = 'primary secondary animated optical'; |
| 1040 | |
| 1041 | function clearLinkTrafficStyle() { |
| 1042 | link.style('stroke-width', null) |
| 1043 | .classed(allTrafficClasses, false); |
| 1044 | } |
| 1045 | |
| 1046 | function removeLinkLabels() { |
| 1047 | network.links.forEach(function (d) { |
| 1048 | d.label = ''; |
| 1049 | }); |
| 1050 | } |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1051 | |
| 1052 | // ========================== |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 1053 | // Module definition |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1054 | |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 1055 | function mkModelApi(uplink) { |
| 1056 | return { |
| 1057 | projection: uplink.projection, |
| 1058 | network: network, |
| 1059 | restyleLinkElement: restyleLinkElement, |
| 1060 | removeLinkElement: removeLinkElement |
| 1061 | }; |
| 1062 | } |
| 1063 | |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 1064 | function mkSelectApi(uplink) { |
| 1065 | return { |
| 1066 | node: function () { return node; }, |
| 1067 | zoomingOrPanning: zoomingOrPanning, |
| 1068 | updateDeviceColors: updateDeviceColors, |
| 1069 | sendEvent: uplink.sendEvent |
| 1070 | }; |
| 1071 | } |
| 1072 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1073 | function mkTrafficApi(uplink) { |
| 1074 | return { |
| 1075 | clearLinkTrafficStyle: clearLinkTrafficStyle, |
| 1076 | removeLinkLabels: removeLinkLabels, |
| 1077 | updateLinks: updateLinks, |
| 1078 | findLinkById: tms.findLinkById, |
| 1079 | hovered: tss.hovered, |
| 1080 | validateSelectionContext: tss.validateSelectionContext, |
| 1081 | selectOrder: tss.selectOrder, |
| 1082 | sendEvent: uplink.sendEvent |
| 1083 | } |
| 1084 | } |
| 1085 | |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 1086 | function mkObliqueApi(uplink, fltr) { |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 1087 | return { |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 1088 | force: function() { return force; }, |
| 1089 | zoomLayer: uplink.zoomLayer, |
| 1090 | nodeGBBox: function() { return nodeG.node().getBBox(); }, |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 1091 | node: function () { return node; }, |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 1092 | link: function () { return link; }, |
| 1093 | linkLabel: function () { return linkLabel; }, |
| 1094 | nodes: function () { return network.nodes; }, |
| 1095 | tickStuff: tickStuff, |
| 1096 | nodeLock: function (b) { |
| 1097 | var old = nodeLock; |
| 1098 | nodeLock = b; |
| 1099 | return old; |
| 1100 | }, |
| 1101 | opacifyMap: uplink.opacifyMap, |
| 1102 | inLayer: fltr.inLayer |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 1103 | }; |
| 1104 | } |
| 1105 | |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 1106 | function mkFilterApi(uplink) { |
| 1107 | return { |
| 1108 | node: function () { return node; }, |
| 1109 | link: function () { return link; } |
| 1110 | }; |
| 1111 | } |
| 1112 | |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1113 | angular.module('ovTopo') |
| 1114 | .factory('TopoForceService', |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 1115 | ['$log', 'FnService', 'SvgUtilService', 'IconService', 'ThemeService', |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1116 | 'FlashService', 'TopoInstService', 'TopoModelService', |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 1117 | 'TopoSelectService', 'TopoTrafficService', |
| 1118 | 'TopoObliqueService', 'TopoFilterService', |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1119 | |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1120 | function (_$log_, _fs_, _sus_, _is_, _ts_, _flash_, |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 1121 | _tis_, _tms_, _tss_, _tts_, _tos_, _fltr_) { |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1122 | $log = _$log_; |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 1123 | fs = _fs_; |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1124 | sus = _sus_; |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 1125 | is = _is_; |
| 1126 | ts = _ts_; |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 1127 | flash = _flash_; |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 1128 | tis = _tis_; |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1129 | tms = _tms_; |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 1130 | tss = _tss_; |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1131 | tts = _tts_; |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 1132 | tos = _tos_; |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 1133 | fltr = _fltr_; |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1134 | |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 1135 | icfg = is.iconConfig(); |
| 1136 | |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 1137 | var themeListener = ts.addListener(function () { |
| 1138 | updateLinks(); |
| 1139 | updateNodes(); |
| 1140 | }); |
| 1141 | |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1142 | // forceG is the SVG group to display the force layout in |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 1143 | // uplink is the api from the main topo source file |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1144 | // dim is the initial dimensions of the SVG as [w,h] |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1145 | // opts are, well, optional :) |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1146 | function initForce(forceG, _uplink_, _dim_, opts) { |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 1147 | uplink = _uplink_; |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1148 | dim = _dim_; |
| 1149 | |
| 1150 | $log.debug('initForce().. dim = ' + dim); |
| 1151 | |
Simon Hunt | dc6adea | 2015-02-09 22:29:36 -0800 | [diff] [blame] | 1152 | tms.initModel(mkModelApi(uplink), dim); |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 1153 | tss.initSelect(mkSelectApi(uplink)); |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1154 | tts.initTraffic(mkTrafficApi(uplink)); |
Simon Hunt | c3c5b67 | 2015-02-20 11:32:13 -0800 | [diff] [blame] | 1155 | tos.initOblique(mkObliqueApi(uplink, fltr)); |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 1156 | fltr.initFilter(mkFilterApi(uplink), d3.select('#mast-right')); |
Simon Hunt | a11b4eb | 2015-01-28 16:20:50 -0800 | [diff] [blame] | 1157 | |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1158 | settings = angular.extend({}, defaultSettings, opts); |
| 1159 | |
| 1160 | linkG = forceG.append('g').attr('id', 'topo-links'); |
| 1161 | linkLabelG = forceG.append('g').attr('id', 'topo-linkLabels'); |
| 1162 | nodeG = forceG.append('g').attr('id', 'topo-nodes'); |
| 1163 | |
| 1164 | link = linkG.selectAll('.link'); |
| 1165 | linkLabel = linkLabelG.selectAll('.linkLabel'); |
| 1166 | node = nodeG.selectAll('.node'); |
| 1167 | |
| 1168 | force = d3.layout.force() |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1169 | .size(dim) |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1170 | .nodes(network.nodes) |
| 1171 | .links(network.links) |
| 1172 | .gravity(settings.gravity) |
| 1173 | .friction(settings.friction) |
| 1174 | .charge(settings.charge._def_) |
| 1175 | .linkDistance(settings.linkDistance._def_) |
| 1176 | .linkStrength(settings.linkStrength._def_) |
| 1177 | .on('tick', tick); |
| 1178 | |
| 1179 | drag = sus.createDragBehavior(force, |
Simon Hunt | 08f841d0 | 2015-02-10 14:39:20 -0800 | [diff] [blame] | 1180 | tss.selectObject, atDragEnd, dragEnabled, clickEnabled); |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1181 | } |
| 1182 | |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1183 | function newDim(_dim_) { |
| 1184 | dim = _dim_; |
| 1185 | force.size(dim); |
| 1186 | tms.newDim(dim); |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1187 | // Review -- do we need to nudge the layout ? |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1188 | } |
| 1189 | |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1190 | function destroyForce() { |
Simon Hunt | eb0fa05 | 2015-02-17 19:20:28 -0800 | [diff] [blame] | 1191 | fltr.destroyFilter(); |
Simon Hunt | 96f88c6 | 2015-02-19 17:57:25 -0800 | [diff] [blame] | 1192 | tos.destroyOblique(); |
Simon Hunt | f542d84 | 2015-02-11 16:20:33 -0800 | [diff] [blame] | 1193 | tts.destroyTraffic(); |
| 1194 | tss.destroySelect(); |
| 1195 | tms.destroyModel(); |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 1196 | ts.removeListener(themeListener); |
| 1197 | themeListener = null; |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1198 | } |
| 1199 | |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1200 | return { |
| 1201 | initForce: initForce, |
Simon Hunt | 3a6eec0 | 2015-02-09 21:16:43 -0800 | [diff] [blame] | 1202 | newDim: newDim, |
| 1203 | destroyForce: destroyForce, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 1204 | |
| 1205 | updateDeviceColors: updateDeviceColors, |
Simon Hunt | 5724fb4 | 2015-02-05 16:59:40 -0800 | [diff] [blame] | 1206 | toggleHosts: toggleHosts, |
| 1207 | toggleOffline: toggleOffline, |
| 1208 | cycleDeviceLabels: cycleDeviceLabels, |
Simon Hunt | 445e815 | 2015-02-06 13:00:12 -0800 | [diff] [blame] | 1209 | unpin: unpin, |
Simon Hunt | a142dd2 | 2015-02-12 22:07:51 -0800 | [diff] [blame] | 1210 | showMastership: showMastership, |
Simon Hunt | ac4c6f7 | 2015-02-03 19:50:53 -0800 | [diff] [blame] | 1211 | |
| 1212 | addDevice: addDevice, |
Simon Hunt | 1894d79 | 2015-02-04 17:09:20 -0800 | [diff] [blame] | 1213 | updateDevice: updateDevice, |
| 1214 | removeDevice: removeDevice, |
| 1215 | addHost: addHost, |
| 1216 | updateHost: updateHost, |
| 1217 | removeHost: removeHost, |
| 1218 | addLink: addLink, |
| 1219 | updateLink: updateLink, |
| 1220 | removeLink: removeLink |
Simon Hunt | 737c89f | 2015-01-28 12:23:19 -0800 | [diff] [blame] | 1221 | }; |
| 1222 | }]); |
| 1223 | }()); |