blob: 2af2e2bfc9ff62f64d99b279476a59fd678c6f66 [file] [log] [blame]
Simon Hunt0b05d4a2014-10-21 21:50:15 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
16
17/*
Simon Hunt0b05d4a2014-10-21 21:50:15 -070018 ONOS network topology viewer - PoC version 1.0
19
20 @author Simon Hunt
21 */
22
23(function (onos) {
24 'use strict';
25
Simon Huntd35961b2014-10-28 08:49:48 -070026 // reference to the framework api
Simon Hunt0b05d4a2014-10-21 21:50:15 -070027 var api = onos.api;
28
Simon Huntd35961b2014-10-28 08:49:48 -070029 // configuration data
Simon Hunt0b05d4a2014-10-21 21:50:15 -070030 var config = {
Simon Huntb4d9d4c2014-10-30 11:27:23 -070031 useLiveData: true,
Simon Hunt73171372014-10-30 09:25:36 -070032 debugOn: false,
33 debug: {
34 showNodeXY: false,
35 showKeyHandler: true
36 },
37 options: {
38 layering: true,
Simon Huntee66e612014-10-30 14:56:31 -070039 collisionPrevention: true,
40 loadBackground: true
Simon Hunt73171372014-10-30 09:25:36 -070041 },
Simon Huntee66e612014-10-30 14:56:31 -070042 backgroundUrl: 'img/us-map.png',
Simon Huntb4d9d4c2014-10-30 11:27:23 -070043 data: {
44 live: {
45 jsonUrl: 'rs/topology/graph',
46 detailPrefix: 'rs/topology/graph/',
47 detailSuffix: ''
48 },
49 fake: {
50 jsonUrl: 'json/network2.json',
51 detailPrefix: 'json/',
52 detailSuffix: '.json'
53 }
54 },
Simon Hunt73171372014-10-30 09:25:36 -070055 iconUrl: {
56 device: 'img/device.png',
57 host: 'img/host.png',
58 pkt: 'img/pkt.png',
59 opt: 'img/opt.png'
60 },
61 mastHeight: 36,
62 force: {
63 note: 'node.class or link.class is used to differentiate',
64 linkDistance: {
65 infra: 200,
66 host: 40
Simon Huntd35961b2014-10-28 08:49:48 -070067 },
Simon Hunt73171372014-10-30 09:25:36 -070068 linkStrength: {
69 infra: 1.0,
70 host: 1.0
Simon Hunt2c9e0c22014-10-23 15:12:58 -070071 },
Simon Hunt73171372014-10-30 09:25:36 -070072 charge: {
73 device: -800,
74 host: -1000
Simon Hunt68ae6652014-10-22 13:58:07 -070075 },
Simon Hunt73171372014-10-30 09:25:36 -070076 ticksWithoutCollisions: 50,
77 marginLR: 20,
78 marginTB: 20,
79 translate: function() {
80 return 'translate(' +
81 config.force.marginLR + ',' +
82 config.force.marginTB + ')';
83 }
84 },
85 labels: {
86 imgPad: 16,
87 padLR: 8,
88 padTB: 6,
89 marginLR: 3,
Simon Hunt69a8d212014-10-30 17:57:35 -070090 marginTB: 2,
91 port: {
92 gap: 2,
93 width: 12,
94 height: 12
95 }
Simon Hunt73171372014-10-30 09:25:36 -070096 },
97 icons: {
98 w: 32,
99 h: 32,
100 xoff: -12,
101 yoff: -8
102 },
103 constraints: {
104 ypos: {
105 host: 0.05,
106 switch: 0.3,
107 roadm: 0.7
108 }
109 },
110 hostLinkWidth: 1.0,
111 hostRadius: 7,
112 mouseOutTimerDelayMs: 120
113 };
Simon Huntd35961b2014-10-28 08:49:48 -0700114
115 // state variables
116 var view = {},
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700117 network = {},
118 selected = {},
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700119 highlighted = null,
Simon Hunt9a16c822014-10-28 16:09:19 -0700120 hovered = null,
Simon Hunt69a8d212014-10-30 17:57:35 -0700121 viewMode = 'showAll',
122 portLabelsOn = false;
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700123
124
Simon Huntd35961b2014-10-28 08:49:48 -0700125 function debug(what) {
126 return config.debugOn && config.debug[what];
127 }
128
Simon Huntb4d9d4c2014-10-30 11:27:23 -0700129 function urlData() {
130 return config.data[config.useLiveData ? 'live' : 'fake'];
131 }
132
133 function networkJsonUrl() {
134 return urlData().jsonUrl;
135 }
136
Simon Hunt69a8d212014-10-30 17:57:35 -0700137 function safeId(id) {
138 return id.replace(/[^a-z0-9]/gi, '_');
139 }
140
Simon Huntb4d9d4c2014-10-30 11:27:23 -0700141 function detailJsonUrl(id) {
142 var u = urlData(),
Simon Hunt69a8d212014-10-30 17:57:35 -0700143 encId = config.useLiveData ? encodeURIComponent(id) : safeId(id);
Simon Huntb4d9d4c2014-10-30 11:27:23 -0700144 return u.detailPrefix + encId + u.detailSuffix;
145 }
146
147
Simon Huntd35961b2014-10-28 08:49:48 -0700148 // load the topology view of the network
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700149 function loadNetworkView() {
150 // Hey, here I am, calling something on the ONOS api:
151 api.printTime();
152
153 resize();
154
Simon Huntd35961b2014-10-28 08:49:48 -0700155 // go get our network data from the server...
Simon Huntb4d9d4c2014-10-30 11:27:23 -0700156 var url = networkJsonUrl();
157 d3.json(url , function (err, data) {
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700158 if (err) {
159 alert('Oops! Error reading JSON...\n\n' +
Simon Huntb4d9d4c2014-10-30 11:27:23 -0700160 'URL: ' + url + '\n\n' +
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700161 'Error: ' + err.message);
162 return;
163 }
Simon Huntd35961b2014-10-28 08:49:48 -0700164// console.log("here is the JSON data...");
165// console.log(data);
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700166
167 network.data = data;
168 drawNetwork();
169 });
170
Simon Huntd35961b2014-10-28 08:49:48 -0700171 // while we wait for the data, set up the handlers...
172 setUpClickHandler();
173 setUpRadioButtonHandler();
174 setUpKeyHandler();
175 $(window).on('resize', resize);
176 }
177
178 function setUpClickHandler() {
179 // click handler for "selectable" objects
180 $(document).on('click', '.select-object', function () {
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700181 // when any object of class "select-object" is clicked...
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700182 var obj = network.lookup[$(this).data('id')];
183 if (obj) {
184 selectObject(obj);
185 }
186 // stop propagation of event (I think) ...
187 return false;
188 });
Simon Huntd35961b2014-10-28 08:49:48 -0700189 }
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700190
Simon Huntd35961b2014-10-28 08:49:48 -0700191 function setUpRadioButtonHandler() {
192 d3.selectAll('#displayModes .radio').on('click', function () {
193 var id = d3.select(this).attr('id');
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700194 if (id !== viewMode) {
195 radioButton('displayModes', id);
196 viewMode = id;
Simon Huntf967d512014-10-28 20:34:29 -0700197 doRadioAction(id);
198 }
199 });
200 }
201
202 function doRadioAction(id) {
203 showAllLayers();
204 if (id === 'showPkt') {
205 showPacketLayer();
206 } else if (id === 'showOpt') {
207 showOpticalLayer();
208 }
209 }
210
211 function showAllLayers() {
212 network.node.classed('inactive', false);
213 network.link.classed('inactive', false);
214 }
215
216 function showPacketLayer() {
217 network.node.each(function(d) {
218 // deactivate nodes that are not hosts or switches
219 if (d.class === 'device' && d.type !== 'switch') {
220 d3.select(this).classed('inactive', true);
221 }
222 });
223
224 network.link.each(function(lnk) {
225 // deactivate infrastructure links that have opt's as endpoints
226 if (lnk.source.type === 'roadm' || lnk.target.type === 'roadm') {
227 d3.select(this).classed('inactive', true);
228 }
229 });
230 }
231
232 function showOpticalLayer() {
233 network.node.each(function(d) {
234 // deactivate nodes that are not optical devices
235 if (d.type !== 'roadm') {
236 d3.select(this).classed('inactive', true);
237 }
238 });
239
240 network.link.each(function(lnk) {
241 // deactivate infrastructure links that have opt's as endpoints
242 if (lnk.source.type !== 'roadm' || lnk.target.type !== 'roadm') {
243 d3.select(this).classed('inactive', true);
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700244 }
245 });
246 }
247
Simon Huntd35961b2014-10-28 08:49:48 -0700248 function setUpKeyHandler() {
249 d3.select('body')
250 .on('keydown', function () {
251 processKeyEvent();
252 if (debug('showKeyHandler')) {
253 network.svg.append('text')
254 .attr('x', 5)
255 .attr('y', 15)
256 .style('font-size', '20pt')
257 .text('keyCode: ' + d3.event.keyCode +
258 ' applied to : ' + contextLabel())
259 .transition().duration(2000)
260 .style('font-size', '2pt')
261 .style('fill-opacity', 0.01)
262 .remove();
263 }
264 });
265 }
266
Simon Hunt9a16c822014-10-28 16:09:19 -0700267 function contextLabel() {
268 return hovered === null ? "(nothing)" : hovered.id;
269 }
270
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700271 function radioButton(group, id) {
272 d3.selectAll("#" + group + " .radio").classed("active", false);
273 d3.select("#" + group + " #" + id).classed("active", true);
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700274 }
275
Simon Huntd35961b2014-10-28 08:49:48 -0700276 function processKeyEvent() {
277 var code = d3.event.keyCode;
278 switch (code) {
Simon Huntee66e612014-10-30 14:56:31 -0700279 case 66: // B
280 toggleBackground();
281 break;
Thomas Vachuska1de66012014-10-30 03:03:30 -0700282 case 71: // G
283 cycleLayout();
284 break;
Simon Huntd35961b2014-10-28 08:49:48 -0700285 case 76: // L
286 cycleLabels();
287 break;
288 case 80: // P
289 togglePorts();
Simon Hunt9a16c822014-10-28 16:09:19 -0700290 break;
291 case 85: // U
292 unpin();
293 break;
Simon Huntd35961b2014-10-28 08:49:48 -0700294 }
295
296 }
297
Simon Huntee66e612014-10-30 14:56:31 -0700298 function toggleBackground() {
299 var bg = d3.select('#bg'),
300 vis = bg.style('visibility'),
301 newvis = (vis === 'hidden') ? 'visible' : 'hidden';
302 bg.style('visibility', newvis);
303 }
304
Thomas Vachuska1de66012014-10-30 03:03:30 -0700305 function cycleLayout() {
306 config.options.layering = !config.options.layering;
307 network.force.resume();
308 }
309
Simon Huntd35961b2014-10-28 08:49:48 -0700310 function cycleLabels() {
Simon Hunt9a16c822014-10-28 16:09:19 -0700311 console.log('Cycle Labels - context = ' + contextLabel());
Simon Huntd35961b2014-10-28 08:49:48 -0700312 }
313
314 function togglePorts() {
Simon Hunt69a8d212014-10-30 17:57:35 -0700315 portLabelsOn = !portLabelsOn;
316 var portVis = portLabelsOn ? 'visible' : 'hidden';
317 d3.selectAll('.port').style('visibility', portVis);
Simon Hunt9a16c822014-10-28 16:09:19 -0700318 }
319
320 function unpin() {
321 if (hovered) {
322 hovered.fixed = false;
Simon Huntf967d512014-10-28 20:34:29 -0700323 findNodeFromData(hovered).classed('fixed', false);
Simon Hunt9a16c822014-10-28 16:09:19 -0700324 network.force.resume();
325 }
326 console.log('Unpin - context = ' + contextLabel());
Simon Huntd35961b2014-10-28 08:49:48 -0700327 }
328
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700329
330 // ========================================================
331
332 function drawNetwork() {
333 $('#view').empty();
334
335 prepareNodesAndLinks();
336 createLayout();
337 console.log("\n\nHere is the augmented network object...");
Simon Hunt9a16c822014-10-28 16:09:19 -0700338 console.log(network);
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700339 }
340
341 function prepareNodesAndLinks() {
342 network.lookup = {};
343 network.nodes = [];
344 network.links = [];
345
346 var nw = network.forceWidth,
347 nh = network.forceHeight;
348
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700349 function yPosConstraintForNode(n) {
350 return config.constraints.ypos[n.type || 'host'];
351 }
352
353 // Note that both 'devices' and 'hosts' get mapped into the nodes array
354
355 // first, the devices...
356 network.data.devices.forEach(function(n) {
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700357 var ypc = yPosConstraintForNode(n),
Simon Hunt3ab76a82014-10-22 13:07:32 -0700358 ix = Math.random() * 0.6 * nw + 0.2 * nw,
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700359 iy = ypc * nh,
360 node = {
Simon Hunt69a8d212014-10-30 17:57:35 -0700361 id: safeId(n.id),
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700362 labels: n.labels,
363 class: 'device',
364 icon: 'device',
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700365 type: n.type,
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700366 x: ix,
367 y: iy,
368 constraint: {
369 weight: 0.7,
370 y: iy
371 }
372 };
373 network.lookup[n.id] = node;
374 network.nodes.push(node);
375 });
376
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700377 // then, the hosts...
378 network.data.hosts.forEach(function(n) {
379 var ypc = yPosConstraintForNode(n),
380 ix = Math.random() * 0.6 * nw + 0.2 * nw,
381 iy = ypc * nh,
382 node = {
Simon Hunt69a8d212014-10-30 17:57:35 -0700383 id: safeId(n.id),
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700384 labels: n.labels,
385 class: 'host',
386 icon: 'host',
387 type: n.type,
388 x: ix,
389 y: iy,
390 constraint: {
391 weight: 0.7,
392 y: iy
393 }
394 };
395 network.lookup[n.id] = node;
396 network.nodes.push(node);
397 });
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700398
399
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700400 // now, process the explicit links...
Simon Hunt6f376a32014-10-28 12:38:30 -0700401 network.data.links.forEach(function(lnk) {
402 var src = network.lookup[lnk.src],
403 dst = network.lookup[lnk.dst],
Simon Hunt69a8d212014-10-30 17:57:35 -0700404 id = src.id + "-" + dst.id;
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700405
406 var link = {
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700407 class: 'infra',
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700408 id: id,
Simon Hunt6f376a32014-10-28 12:38:30 -0700409 type: lnk.type,
410 width: lnk.linkWidth,
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700411 source: src,
Simon Hunt69a8d212014-10-30 17:57:35 -0700412 srcPort: lnk.srcPort,
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700413 target: dst,
Simon Hunt69a8d212014-10-30 17:57:35 -0700414 tgtPort: lnk.dstPort,
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700415 strength: config.force.linkStrength.infra
416 };
417 network.links.push(link);
418 });
419
420 // finally, infer host links...
421 network.data.hosts.forEach(function(n) {
422 var src = network.lookup[n.id],
423 dst = network.lookup[n.cp.device],
Simon Hunt69a8d212014-10-30 17:57:35 -0700424 id = src.id + "-" + dst.id;
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700425
426 var link = {
427 class: 'host',
428 id: id,
429 type: 'hostLink',
430 width: config.hostLinkWidth,
431 source: src,
432 target: dst,
433 strength: config.force.linkStrength.host
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700434 };
435 network.links.push(link);
436 });
437 }
438
439 function createLayout() {
440
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700441 var cfg = config.force;
442
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700443 network.force = d3.layout.force()
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700444 .size([network.forceWidth, network.forceHeight])
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700445 .nodes(network.nodes)
446 .links(network.links)
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700447 .linkStrength(function(d) { return cfg.linkStrength[d.class]; })
448 .linkDistance(function(d) { return cfg.linkDistance[d.class]; })
449 .charge(function(d) { return cfg.charge[d.class]; })
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700450 .on('tick', tick);
451
452 network.svg = d3.select('#view').append('svg')
453 .attr('width', view.width)
454 .attr('height', view.height)
455 .append('g')
Simon Huntae968a62014-10-22 14:54:41 -0700456 .attr('transform', config.force.translate());
Simon Hunt3ab76a82014-10-22 13:07:32 -0700457// .attr('id', 'zoomable')
Simon Hunt3ab76a82014-10-22 13:07:32 -0700458// .call(d3.behavior.zoom().on("zoom", zoomRedraw));
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700459
Thomas Vachuska8cd66a52014-10-30 11:53:07 -0700460 network.svg.append('svg:image')
461 .attr({
462 id: 'bg',
463 width: view.width,
464 height: view.height,
Simon Huntee66e612014-10-30 14:56:31 -0700465 'xlink:href': config.backgroundUrl
466 })
467 .style('visibility',
468 config.options.loadBackground ? 'visible' : 'hidden');
Thomas Vachuska8cd66a52014-10-30 11:53:07 -0700469
Simon Hunt3ab76a82014-10-22 13:07:32 -0700470// function zoomRedraw() {
471// d3.select("#zoomable").attr("transform",
472// "translate(" + d3.event.translate + ")"
473// + " scale(" + d3.event.scale + ")");
474// }
475
Simon Hunt3ab76a82014-10-22 13:07:32 -0700476 // TODO: move glow/blur stuff to util script
477 var glow = network.svg.append('filter')
478 .attr('x', '-50%')
479 .attr('y', '-50%')
480 .attr('width', '200%')
481 .attr('height', '200%')
482 .attr('id', 'blue-glow');
483
484 glow.append('feColorMatrix')
485 .attr('type', 'matrix')
486 .attr('values', '0 0 0 0 0 ' +
487 '0 0 0 0 0 ' +
488 '0 0 0 0 .7 ' +
489 '0 0 0 1 0 ');
490
491 glow.append('feGaussianBlur')
492 .attr('stdDeviation', 3)
493 .attr('result', 'coloredBlur');
494
495 glow.append('feMerge').selectAll('feMergeNode')
496 .data(['coloredBlur', 'SourceGraphic'])
497 .enter().append('feMergeNode')
498 .attr('in', String);
499
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700500 // TODO: legend (and auto adjust on scroll)
Simon Hunt3ab76a82014-10-22 13:07:32 -0700501// $('#view').on('scroll', function() {
502//
503// });
504
505
Simon Hunt6f376a32014-10-28 12:38:30 -0700506 // TODO: move drag behavior into separate method.
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700507 // == define node drag behavior...
Simon Hunt3ab76a82014-10-22 13:07:32 -0700508 network.draggedThreshold = d3.scale.linear()
509 .domain([0, 0.1])
510 .range([5, 20])
511 .clamp(true);
512
513 function dragged(d) {
514 var threshold = network.draggedThreshold(network.force.alpha()),
515 dx = d.oldX - d.px,
516 dy = d.oldY - d.py;
517 if (Math.abs(dx) >= threshold || Math.abs(dy) >= threshold) {
518 d.dragged = true;
519 }
520 return d.dragged;
521 }
522
523 network.drag = d3.behavior.drag()
524 .origin(function(d) { return d; })
525 .on('dragstart', function(d) {
526 d.oldX = d.x;
527 d.oldY = d.y;
528 d.dragged = false;
529 d.fixed |= 2;
530 })
531 .on('drag', function(d) {
532 d.px = d3.event.x;
533 d.py = d3.event.y;
534 if (dragged(d)) {
535 if (!network.force.alpha()) {
536 network.force.alpha(.025);
537 }
538 }
539 })
540 .on('dragend', function(d) {
541 if (!dragged(d)) {
542 selectObject(d, this);
543 }
544 d.fixed &= ~6;
Simon Hunt9a16c822014-10-28 16:09:19 -0700545
546 // once we've finished moving, pin the node in position,
Simon Huntf967d512014-10-28 20:34:29 -0700547 // if it is a device (not a host)
Simon Hunt9a16c822014-10-28 16:09:19 -0700548 if (d.class === 'device') {
549 d.fixed = true;
Simon Huntf967d512014-10-28 20:34:29 -0700550 d3.select(this).classed('fixed', true)
Simon Hunt9a16c822014-10-28 16:09:19 -0700551 }
Simon Hunt3ab76a82014-10-22 13:07:32 -0700552 });
553
554 $('#view').on('click', function(e) {
555 if (!$(e.target).closest('.node').length) {
556 deselectObject();
557 }
558 });
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700559
Simon Hunt69a8d212014-10-30 17:57:35 -0700560 // ...............................................................
561
562 // add links to the display
563 network.link = network.svg.append('g').attr('id', 'links')
564 .selectAll('.link')
565 .data(network.force.links(), function(d) {return d.id})
566 .enter().append('line')
567 .attr('class', function(d) {return 'link ' + d.class});
568
569 network.linkSrcPort = network.svg.append('g')
570 .attr({
571 id: 'srcPorts',
572 class: 'portLayer'
573 });
574 network.linkTgtPort = network.svg.append('g')
575 .attr({
576 id: 'tgtPorts',
577 class: 'portLayer'
578 });
579
580 var portVis = portLabelsOn ? 'visible' : 'hidden';
581
582 network.link.filter('.infra').each(function(d, i) {
583 network.linkSrcPort.append('rect').attr({
584 id: 'srcPort-' + d.id,
585 class: 'port',
586 width: 12,
587 height: 12,
588 x: i * 20,
589 y: 0
590 })
591 .style('visibility', portVis)
592 .append('text').text(d.srcPort);
593
594 network.linkTgtPort.append('rect').attr({
595 id: 'tgtPort-' + d.id,
596 class: 'port',
597 width: 12,
598 height: 12,
599 x: i * 20,
600 y: 20
601 })
602 .style('visibility', portVis);
603
604 });
605
606 // ...............................................................
Simon Hunt1c5f8b62014-10-22 14:43:01 -0700607
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700608 // add nodes to the display
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700609 network.node = network.svg.selectAll('.node')
610 .data(network.force.nodes(), function(d) {return d.id})
611 .enter().append('g')
Simon Hunt3ab76a82014-10-22 13:07:32 -0700612 .attr('class', function(d) {
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700613 var cls = 'node ' + d.class;
614 if (d.type) {
615 cls += ' ' + d.type;
616 }
617 return cls;
Simon Hunt3ab76a82014-10-22 13:07:32 -0700618 })
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700619 .attr('transform', function(d) {
620 return translate(d.x, d.y);
621 })
Simon Hunt3ab76a82014-10-22 13:07:32 -0700622 .call(network.drag)
623 .on('mouseover', function(d) {
Simon Hunt6f376a32014-10-28 12:38:30 -0700624 // TODO: show tooltip
Simon Hunt9a16c822014-10-28 16:09:19 -0700625 if (network.mouseoutTimeout) {
626 clearTimeout(network.mouseoutTimeout);
627 network.mouseoutTimeout = null;
Simon Hunt3ab76a82014-10-22 13:07:32 -0700628 }
Simon Hunt9a16c822014-10-28 16:09:19 -0700629 hoverObject(d);
Simon Hunt3ab76a82014-10-22 13:07:32 -0700630 })
631 .on('mouseout', function(d) {
Simon Hunt6f376a32014-10-28 12:38:30 -0700632 // TODO: hide tooltip
Simon Hunt9a16c822014-10-28 16:09:19 -0700633 if (network.mouseoutTimeout) {
634 clearTimeout(network.mouseoutTimeout);
635 network.mouseoutTimeout = null;
Simon Hunt3ab76a82014-10-22 13:07:32 -0700636 }
Simon Hunt9a16c822014-10-28 16:09:19 -0700637 network.mouseoutTimeout = setTimeout(function() {
638 hoverObject(null);
639 }, config.mouseOutTimerDelayMs);
Simon Hunt3ab76a82014-10-22 13:07:32 -0700640 });
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700641
Simon Hunt6f376a32014-10-28 12:38:30 -0700642
643 // deal with device nodes first
644 network.nodeRect = network.node.filter('.device')
645 .append('rect')
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700646 .attr({
647 rx: 5,
648 ry: 5,
649 width: 100,
650 height: 12
651 });
652 // note that width/height are adjusted to fit the label text
Simon Hunt6f376a32014-10-28 12:38:30 -0700653 // then padded, and space made for the icon.
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700654
Simon Hunt6f376a32014-10-28 12:38:30 -0700655 network.node.filter('.device').each(function(d) {
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700656 var node = d3.select(this),
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700657 icon = iconUrl(d);
658
659 node.append('text')
660 // TODO: add label cycle behavior
661 .text(d.id)
662 .attr('dy', '1.1em');
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700663
664 if (icon) {
665 var cfg = config.icons;
666 node.append('svg:image')
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700667 .attr({
668 width: cfg.w,
669 height: cfg.h,
670 'xlink:href': icon
671 });
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700672 // note, icon relative positioning (x,y) is done after we have
673 // adjusted the bounds of the rectangle...
674 }
Simon Hunt68ae6652014-10-22 13:58:07 -0700675
Simon Huntd35961b2014-10-28 08:49:48 -0700676 // debug function to show the modelled x,y coordinates of nodes...
677 if (debug('showNodeXY')) {
678 node.select('rect').attr('fill-opacity', 0.5);
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700679 node.append('circle')
680 .attr({
681 class: 'debug',
682 cx: 0,
683 cy: 0,
684 r: '3px'
685 });
686 }
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700687 });
688
Simon Hunt6f376a32014-10-28 12:38:30 -0700689 // now process host nodes
690 network.nodeCircle = network.node.filter('.host')
691 .append('circle')
692 .attr({
693 r: config.hostRadius
694 });
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700695
Simon Hunt6f376a32014-10-28 12:38:30 -0700696 network.node.filter('.host').each(function(d) {
697 var node = d3.select(this),
698 icon = iconUrl(d);
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700699
Simon Hunt6f376a32014-10-28 12:38:30 -0700700 // debug function to show the modelled x,y coordinates of nodes...
701 if (debug('showNodeXY')) {
702 node.select('circle').attr('fill-opacity', 0.5);
703 node.append('circle')
704 .attr({
705 class: 'debug',
706 cx: 0,
707 cy: 0,
708 r: '3px'
709 });
710 }
711 });
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700712
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700713 // this function is scheduled to happen soon after the given thread ends
714 setTimeout(function() {
Simon Hunt69a8d212014-10-30 17:57:35 -0700715 var lab = config.labels,
716 portGap = lab.port.gap,
717 midW = portGap + lab.port.width/ 2,
718 midH = portGap + lab.port.height / 2;
719
Simon Hunt6f376a32014-10-28 12:38:30 -0700720 // post process the device nodes, to pad their size to fit the
721 // label text and attach the icon to the right location.
722 network.node.filter('.device').each(function(d) {
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700723 // for every node, recompute size, padding, etc. so text fits
724 var node = d3.select(this),
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700725 text = node.select('text'),
Simon Hunt69a8d212014-10-30 17:57:35 -0700726 box = adjustRectToFitText(node);
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700727
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700728 // now make the computed adjustment
Simon Hunt1c5f8b62014-10-22 14:43:01 -0700729 node.select('rect')
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700730 .attr(box);
Simon Hunt1c5f8b62014-10-22 14:43:01 -0700731
732 node.select('image')
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700733 .attr('x', box.x + config.icons.xoff)
734 .attr('y', box.y + config.icons.yoff);
Simon Hunt1c219892014-10-22 16:32:39 -0700735
Simon Hunt69a8d212014-10-30 17:57:35 -0700736 var bounds = boundsFromBox(box),
737 portBounds = {
738 x1: bounds.x1 - midW,
739 x2: bounds.x2 + midW,
740 y1: bounds.y1 - midH,
741 y2: bounds.y2 + midH
742 };
Simon Hunt5cd0e8f2014-10-27 16:18:40 -0700743
744 // todo: clean up extent and edge work..
Simon Hunt1c219892014-10-22 16:32:39 -0700745 d.extent = {
746 left: bounds.x1 - lab.marginLR,
747 right: bounds.x2 + lab.marginLR,
748 top: bounds.y1 - lab.marginTB,
749 bottom: bounds.y2 + lab.marginTB
750 };
751
752 d.edge = {
753 left : new geo.LineSegment(bounds.x1, bounds.y1, bounds.x1, bounds.y2),
754 right : new geo.LineSegment(bounds.x2, bounds.y1, bounds.x2, bounds.y2),
755 top : new geo.LineSegment(bounds.x1, bounds.y1, bounds.x2, bounds.y1),
756 bottom : new geo.LineSegment(bounds.x1, bounds.y2, bounds.x2, bounds.y2)
757 };
758
Simon Hunt69a8d212014-10-30 17:57:35 -0700759 d.portEdge = {
760 left : new geo.LineSegment(
761 portBounds.x1, portBounds.y1, portBounds.x1, portBounds.y2
762 ),
763 right : new geo.LineSegment(
764 portBounds.x2, portBounds.y1, portBounds.x2, portBounds.y2
765 ),
766 top : new geo.LineSegment(
767 portBounds.x1, portBounds.y1, portBounds.x2, portBounds.y1
768 ),
769 bottom : new geo.LineSegment(
770 portBounds.x1, portBounds.y2, portBounds.x2, portBounds.y2
771 )
772 };
773
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700774 });
775
776 network.numTicks = 0;
777 network.preventCollisions = false;
778 network.force.start();
Simon Hunt1c219892014-10-22 16:32:39 -0700779 for (var i = 0; i < config.force.ticksWithoutCollisions; i++) {
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700780 network.force.tick();
781 }
782 network.preventCollisions = true;
783 $('#view').css('visibility', 'visible');
784 });
785
Simon Hunt6f376a32014-10-28 12:38:30 -0700786
787 // returns the newly computed bounding box of the rectangle
788 function adjustRectToFitText(n) {
789 var text = n.select('text'),
790 box = text.node().getBBox(),
791 lab = config.labels;
792
Simon Hunt9a16c822014-10-28 16:09:19 -0700793 // not sure why n.data() returns an array of 1 element...
794 var data = n.data()[0];
795
Simon Hunt6f376a32014-10-28 12:38:30 -0700796 text.attr('text-anchor', 'middle')
797 .attr('y', '-0.8em')
798 .attr('x', lab.imgPad/2)
799 ;
800
Simon Hunt6f376a32014-10-28 12:38:30 -0700801 // translate the bbox so that it is centered on [x,y]
802 box.x = -box.width / 2;
803 box.y = -box.height / 2;
804
805 // add padding
806 box.x -= (lab.padLR + lab.imgPad/2);
807 box.width += lab.padLR * 2 + lab.imgPad;
808 box.y -= lab.padTB;
809 box.height += lab.padTB * 2;
810
811 return box;
812 }
813
814 function boundsFromBox(box) {
815 return {
816 x1: box.x,
817 y1: box.y,
818 x2: box.x + box.width,
819 y2: box.y + box.height
820 };
821 }
822
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700823 }
824
Simon Hunt68ae6652014-10-22 13:58:07 -0700825 function iconUrl(d) {
Thomas Vachuska1de66012014-10-30 03:03:30 -0700826 return 'img/' + d.type + '.png';
827// return config.iconUrl[d.icon];
Simon Hunt68ae6652014-10-22 13:58:07 -0700828 }
829
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700830 function translate(x, y) {
831 return 'translate(' + x + ',' + y + ')';
832 }
833
Simon Hunt6f376a32014-10-28 12:38:30 -0700834 // prevents collisions amongst device nodes
Simon Hunt1c219892014-10-22 16:32:39 -0700835 function preventCollisions() {
Simon Hunt6f376a32014-10-28 12:38:30 -0700836 var quadtree = d3.geom.quadtree(network.nodes),
837 hrad = config.hostRadius;
Simon Hunt1c219892014-10-22 16:32:39 -0700838
839 network.nodes.forEach(function(n) {
Simon Hunt6f376a32014-10-28 12:38:30 -0700840 var nx1, nx2, ny1, ny2;
841
842 if (n.class === 'device') {
843 nx1 = n.x + n.extent.left;
844 nx2 = n.x + n.extent.right;
845 ny1 = n.y + n.extent.top;
Simon Hunt1c219892014-10-22 16:32:39 -0700846 ny2 = n.y + n.extent.bottom;
847
Simon Hunt6f376a32014-10-28 12:38:30 -0700848 } else {
849 nx1 = n.x - hrad;
850 nx2 = n.x + hrad;
851 ny1 = n.y - hrad;
852 ny2 = n.y + hrad;
853 }
854
Simon Hunt1c219892014-10-22 16:32:39 -0700855 quadtree.visit(function(quad, x1, y1, x2, y2) {
856 if (quad.point && quad.point !== n) {
Simon Hunt6f376a32014-10-28 12:38:30 -0700857 // check if the rectangles/circles intersect
Simon Hunt1c219892014-10-22 16:32:39 -0700858 var p = quad.point,
Simon Hunt6f376a32014-10-28 12:38:30 -0700859 px1, px2, py1, py2, ix;
860
861 if (p.class === 'device') {
862 px1 = p.x + p.extent.left;
863 px2 = p.x + p.extent.right;
864 py1 = p.y + p.extent.top;
865 py2 = p.y + p.extent.bottom;
866
867 } else {
868 px1 = p.x - hrad;
869 px2 = p.x + hrad;
870 py1 = p.y - hrad;
871 py2 = p.y + hrad;
872 }
873
874 ix = (px1 <= nx2 && nx1 <= px2 && py1 <= ny2 && ny1 <= py2);
875
Simon Hunt1c219892014-10-22 16:32:39 -0700876 if (ix) {
877 var xa1 = nx2 - px1, // shift n left , p right
878 xa2 = px2 - nx1, // shift n right, p left
879 ya1 = ny2 - py1, // shift n up , p down
880 ya2 = py2 - ny1, // shift n down , p up
881 adj = Math.min(xa1, xa2, ya1, ya2);
882
883 if (adj == xa1) {
884 n.x -= adj / 2;
885 p.x += adj / 2;
886 } else if (adj == xa2) {
887 n.x += adj / 2;
888 p.x -= adj / 2;
889 } else if (adj == ya1) {
890 n.y -= adj / 2;
891 p.y += adj / 2;
892 } else if (adj == ya2) {
893 n.y += adj / 2;
894 p.y -= adj / 2;
895 }
896 }
897 return ix;
898 }
899 });
900
901 });
902 }
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700903
904 function tick(e) {
905 network.numTicks++;
906
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700907 if (config.options.layering) {
Simon Hunt68ae6652014-10-22 13:58:07 -0700908 // adjust the y-coord of each node, based on y-pos constraints
909 network.nodes.forEach(function (n) {
910 var z = e.alpha * n.constraint.weight;
911 if (!isNaN(n.constraint.y)) {
912 n.y = (n.constraint.y * z + n.y * (1 - z));
913 }
914 });
915 }
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700916
Simon Hunt2c9e0c22014-10-23 15:12:58 -0700917 if (config.options.collisionPrevention && network.preventCollisions) {
Simon Hunt1c219892014-10-22 16:32:39 -0700918 preventCollisions();
919 }
920
Simon Hunt69a8d212014-10-30 17:57:35 -0700921 var portHalfW = config.labels.port.width / 2,
922 portHalfH = config.labels.port.height / 2;
923
Simon Huntd35961b2014-10-28 08:49:48 -0700924 // clip visualization of links at bounds of nodes...
925 network.link.each(function(d) {
Simon Hunt69a8d212014-10-30 17:57:35 -0700926 var xs = d.source.x,
927 ys = d.source.y,
928 xt = d.target.x,
929 yt = d.target.y,
930 line = new geo.LineSegment(xs, ys, xt, yt),
931 e, ix,
932 exs, eys, ext, eyt,
933 pxs, pys, pxt, pyt;
Simon Hunt1c219892014-10-22 16:32:39 -0700934
Simon Hunt69a8d212014-10-30 17:57:35 -0700935 if (d.class === 'host') {
936 // no adjustment for source end of link, since hosts are dots
937 exs = xs;
938 eys = ys;
939
940 } else {
Simon Huntd35961b2014-10-28 08:49:48 -0700941 for (e in d.source.edge) {
942 ix = line.intersect(d.source.edge[e].offset(xs, ys));
Simon Hunt1c219892014-10-22 16:32:39 -0700943 if (ix.in1 && ix.in2) {
Simon Hunt69a8d212014-10-30 17:57:35 -0700944 exs = ix.x;
945 eys = ix.y;
946
947 // also pick off the port label intersection
948 ix = line.intersect(d.source.portEdge[e].offset(xs, ys));
949 pxs = ix.x;
950 pys = ix.y;
Simon Huntd35961b2014-10-28 08:49:48 -0700951 break;
952 }
953 }
Simon Hunt69a8d212014-10-30 17:57:35 -0700954 }
Simon Huntd35961b2014-10-28 08:49:48 -0700955
Simon Hunt69a8d212014-10-30 17:57:35 -0700956 for (e in d.target.edge) {
957 ix = line.intersect(d.target.edge[e].offset(xt, yt));
958 if (ix.in1 && ix.in2) {
959 ext = ix.x;
960 eyt = ix.y;
961
962 // also pick off the port label intersection
963 ix = line.intersect(d.target.portEdge[e].offset(xt, yt));
964 pxt = ix.x;
965 pyt = ix.y;
966 break;
Simon Hunt1c219892014-10-22 16:32:39 -0700967 }
Simon Hunt69a8d212014-10-30 17:57:35 -0700968 }
Simon Hunt1c219892014-10-22 16:32:39 -0700969
Simon Hunt69a8d212014-10-30 17:57:35 -0700970 // adjust the endpoints of the link's line to match rectangles
971 d3.select(this)
972 .attr('x1', exs)
973 .attr('y1', eys)
974 .attr('x2', ext)
975 .attr('y2', eyt);
976
977 d3.select('#srcPort-' + d.id)
978 .attr('x', pxs - portHalfW)
979 .attr('y', pys - portHalfH);
980
981 d3.select('#tgtPort-' + d.id)
982 .attr('x', pxt - portHalfW)
983 .attr('y', pyt - portHalfH);
984
985 });
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700986
Simon Huntd35961b2014-10-28 08:49:48 -0700987 // position each node by translating the node (group) by x,y
Simon Hunt0b05d4a2014-10-21 21:50:15 -0700988 network.node
989 .attr('transform', function(d) {
990 return translate(d.x, d.y);
991 });
992
993 }
994
995 // $('#docs-close').on('click', function() {
996 // deselectObject();
997 // return false;
998 // });
999
1000 // $(document).on('click', '.select-object', function() {
1001 // var obj = graph.data[$(this).data('name')];
1002 // if (obj) {
1003 // selectObject(obj);
1004 // }
1005 // return false;
1006 // });
1007
Simon Hunt6f376a32014-10-28 12:38:30 -07001008 function findNodeFromData(d) {
1009 var el = null;
1010 network.node.filter('.' + d.class).each(function(n) {
1011 if (n.id === d.id) {
1012 el = d3.select(this);
1013 }
1014 });
1015 return el;
1016 }
1017
Simon Hunt0b05d4a2014-10-21 21:50:15 -07001018 function selectObject(obj, el) {
1019 var node;
1020 if (el) {
1021 node = d3.select(el);
1022 } else {
1023 network.node.each(function(d) {
1024 if (d == obj) {
1025 node = d3.select(el = this);
1026 }
1027 });
1028 }
1029 if (!node) return;
1030
1031 if (node.classed('selected')) {
1032 deselectObject();
Simon Huntc586e212014-10-28 21:24:08 -07001033 flyinPane(null);
Simon Hunt0b05d4a2014-10-21 21:50:15 -07001034 return;
1035 }
1036 deselectObject(false);
1037
1038 selected = {
1039 obj : obj,
1040 el : el
1041 };
1042
Simon Hunt0b05d4a2014-10-21 21:50:15 -07001043 node.classed('selected', true);
Simon Huntc586e212014-10-28 21:24:08 -07001044 flyinPane(obj);
Simon Hunt0b05d4a2014-10-21 21:50:15 -07001045 }
1046
1047 function deselectObject(doResize) {
1048 // Review: logic of 'resize(...)' function.
1049 if (doResize || typeof doResize == 'undefined') {
1050 resize(false);
1051 }
Simon Hunt9a16c822014-10-28 16:09:19 -07001052
Simon Hunt0b05d4a2014-10-21 21:50:15 -07001053 // deselect all nodes in the network...
1054 network.node.classed('selected', false);
1055 selected = {};
Simon Huntc586e212014-10-28 21:24:08 -07001056 flyinPane(null);
1057 }
1058
1059 function flyinPane(obj) {
1060 var pane = d3.select('#flyout'),
Simon Huntcc267562014-10-29 10:22:17 -07001061 url;
Simon Huntc586e212014-10-28 21:24:08 -07001062
1063 if (obj) {
Simon Huntcc267562014-10-29 10:22:17 -07001064 // go get details of the selected object from the server...
Simon Huntb4d9d4c2014-10-30 11:27:23 -07001065 url = detailJsonUrl(obj.id);
Simon Huntcc267562014-10-29 10:22:17 -07001066 d3.json(url, function (err, data) {
1067 if (err) {
1068 alert('Oops! Error reading JSON...\n\n' +
1069 'URL: ' + url + '\n\n' +
1070 'Error: ' + err.message);
1071 return;
1072 }
1073// console.log("JSON data... " + url);
1074// console.log(data);
1075
1076 displayDetails(data, pane);
1077 });
1078
1079 } else {
1080 // hide pane
1081 pane.transition().duration(750)
1082 .style('right', '-320px')
1083 .style('opacity', 0.0);
1084 }
1085 }
1086
1087 function displayDetails(data, pane) {
1088 $('#flyout').empty();
1089
Thomas Vachuska1de66012014-10-30 03:03:30 -07001090 var title = pane.append("h2"),
1091 table = pane.append("table"),
Simon Huntcc267562014-10-29 10:22:17 -07001092 tbody = table.append("tbody");
1093
Thomas Vachuska1de66012014-10-30 03:03:30 -07001094 $('<img src="img/' + data.type + '.png">').appendTo(title);
1095 $('<span>').attr('class', 'icon').text(data.id).appendTo(title);
1096
1097
Simon Huntcc267562014-10-29 10:22:17 -07001098 // TODO: consider using d3 data bind to TR/TD
1099
1100 data.propOrder.forEach(function(p) {
Thomas Vachuska1de66012014-10-30 03:03:30 -07001101 if (p === '-') {
1102 addSep(tbody);
1103 } else {
1104 addProp(tbody, p, data.props[p]);
1105 }
Simon Huntcc267562014-10-29 10:22:17 -07001106 });
1107
Thomas Vachuska1de66012014-10-30 03:03:30 -07001108 function addSep(tbody) {
1109 var tr = tbody.append('tr');
1110 $('<hr>').appendTo(tr.append('td').attr('colspan', 2));
1111 }
1112
Simon Huntcc267562014-10-29 10:22:17 -07001113 function addProp(tbody, label, value) {
1114 var tr = tbody.append('tr');
1115
1116 tr.append('td')
1117 .attr('class', 'label')
1118 .text(label + ' :');
1119
1120 tr.append('td')
1121 .attr('class', 'value')
1122 .text(value);
Simon Huntc586e212014-10-28 21:24:08 -07001123 }
1124
Simon Huntcc267562014-10-29 10:22:17 -07001125 // show pane
Simon Huntc586e212014-10-28 21:24:08 -07001126 pane.transition().duration(750)
Simon Huntcc267562014-10-29 10:22:17 -07001127 .style('right', '20px')
1128 .style('opacity', 1.0);
Simon Hunt0b05d4a2014-10-21 21:50:15 -07001129 }
1130
1131 function highlightObject(obj) {
1132 if (obj) {
1133 if (obj != highlighted) {
1134 // TODO set or clear "inactive" class on nodes, based on criteria
1135 network.node.classed('inactive', function(d) {
1136 // return (obj !== d &&
1137 // d.relation(obj.id));
1138 return (obj !== d);
1139 });
1140 // TODO: same with links
1141 network.link.classed('inactive', function(d) {
1142 return (obj !== d.source && obj !== d.target);
1143 });
1144 }
1145 highlighted = obj;
1146 } else {
1147 if (highlighted) {
1148 // clear the inactive flag (no longer suppressed visually)
1149 network.node.classed('inactive', false);
1150 network.link.classed('inactive', false);
1151 }
1152 highlighted = null;
1153
1154 }
1155 }
1156
Simon Hunt9a16c822014-10-28 16:09:19 -07001157 function hoverObject(obj) {
1158 if (obj) {
1159 hovered = obj;
1160 } else {
1161 if (hovered) {
1162 hovered = null;
1163 }
1164 }
1165 }
1166
1167
Simon Huntc586e212014-10-28 21:24:08 -07001168 function resize() {
Simon Hunt0b05d4a2014-10-21 21:50:15 -07001169 view.height = window.innerHeight - config.mastHeight;
1170 view.width = window.innerWidth;
1171 $('#view')
1172 .css('height', view.height + 'px')
1173 .css('width', view.width + 'px');
1174
1175 network.forceWidth = view.width - config.force.marginLR;
1176 network.forceHeight = view.height - config.force.marginTB;
1177 }
1178
1179 // ======================================================================
1180 // register with the UI framework
1181
1182 api.addView('network', {
1183 load: loadNetworkView
1184 });
1185
1186
1187}(ONOS));
1188