GUI -- Some cleanup in topo.js
Change-Id: Icee133a25d1638cdcc7be591ffc62fed4e3d9808
Showing
1 changed file
with
27 additions
and
29 deletions
| ... | @@ -113,13 +113,11 @@ | ... | @@ -113,13 +113,11 @@ |
| 113 | 113 | ||
| 114 | // key bindings | 114 | // key bindings |
| 115 | var keyDispatch = { | 115 | var keyDispatch = { |
| 116 | - space: injectTestEvent, // TODO: remove (testing only) | ||
| 117 | - S: injectStartupEvents, // TODO: remove (testing only) | ||
| 118 | - A: testAlert, // TODO: remove (testing only) | ||
| 119 | M: testMe, // TODO: remove (testing only) | 116 | M: testMe, // TODO: remove (testing only) |
| 117 | + S: injectStartupEvents, // TODO: remove (testing only) | ||
| 118 | + space: injectTestEvent, // TODO: remove (testing only) | ||
| 120 | 119 | ||
| 121 | B: toggleBg, | 120 | B: toggleBg, |
| 122 | - G: toggleLayout, | ||
| 123 | L: cycleLabels, | 121 | L: cycleLabels, |
| 124 | P: togglePorts, | 122 | P: togglePorts, |
| 125 | U: unpin | 123 | U: unpin |
| ... | @@ -127,6 +125,7 @@ | ... | @@ -127,6 +125,7 @@ |
| 127 | 125 | ||
| 128 | // state variables | 126 | // state variables |
| 129 | var network = { | 127 | var network = { |
| 128 | + view: null, // view token reference | ||
| 130 | nodes: [], | 129 | nodes: [], |
| 131 | links: [], | 130 | links: [], |
| 132 | lookup: {} | 131 | lookup: {} |
| ... | @@ -167,19 +166,19 @@ | ... | @@ -167,19 +166,19 @@ |
| 167 | // ============================== | 166 | // ============================== |
| 168 | // Key Callbacks | 167 | // Key Callbacks |
| 169 | 168 | ||
| 170 | - function testAlert(view) { | ||
| 171 | - alertNumber++; | ||
| 172 | - view.alert("Test me! -- " + alertNumber); | ||
| 173 | - } | ||
| 174 | - | ||
| 175 | function testMe(view) { | 169 | function testMe(view) { |
| 170 | + view.alert('test'); | ||
| 176 | } | 171 | } |
| 177 | 172 | ||
| 178 | function injectTestEvent(view) { | 173 | function injectTestEvent(view) { |
| 174 | + if (config.useLiveData) { | ||
| 175 | + view.alert("Sorry, currently using live data.."); | ||
| 176 | + return; | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | eventNumber++; | 179 | eventNumber++; |
| 180 | var eventUrl = eventPrefix + eventNumber + '.json'; | 180 | var eventUrl = eventPrefix + eventNumber + '.json'; |
| 181 | 181 | ||
| 182 | - console.log('Fetching JSON: ' + eventUrl); | ||
| 183 | d3.json(eventUrl, function(err, data) { | 182 | d3.json(eventUrl, function(err, data) { |
| 184 | if (err) { | 183 | if (err) { |
| 185 | view.dataLoadError(err, eventUrl); | 184 | view.dataLoadError(err, eventUrl); |
| ... | @@ -190,6 +189,11 @@ | ... | @@ -190,6 +189,11 @@ |
| 190 | } | 189 | } |
| 191 | 190 | ||
| 192 | function injectStartupEvents(view) { | 191 | function injectStartupEvents(view) { |
| 192 | + if (config.useLiveData) { | ||
| 193 | + view.alert("Sorry, currently using live data.."); | ||
| 194 | + return; | ||
| 195 | + } | ||
| 196 | + | ||
| 193 | var lastStartupEvent = 32; | 197 | var lastStartupEvent = 32; |
| 194 | while (eventNumber < lastStartupEvent) { | 198 | while (eventNumber < lastStartupEvent) { |
| 195 | injectTestEvent(view); | 199 | injectTestEvent(view); |
| ... | @@ -201,10 +205,6 @@ | ... | @@ -201,10 +205,6 @@ |
| 201 | bgImg.style('visibility', (vis === 'hidden') ? 'visible' : 'hidden'); | 205 | bgImg.style('visibility', (vis === 'hidden') ? 'visible' : 'hidden'); |
| 202 | } | 206 | } |
| 203 | 207 | ||
| 204 | - function toggleLayout(view) { | ||
| 205 | - | ||
| 206 | - } | ||
| 207 | - | ||
| 208 | function cycleLabels() { | 208 | function cycleLabels() { |
| 209 | labelIdx = (labelIdx === network.deviceLabelCount - 1) ? 0 : labelIdx + 1; | 209 | labelIdx = (labelIdx === network.deviceLabelCount - 1) ? 0 : labelIdx + 1; |
| 210 | network.nodes.forEach(function (d) { | 210 | network.nodes.forEach(function (d) { |
| ... | @@ -232,11 +232,11 @@ | ... | @@ -232,11 +232,11 @@ |
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | function togglePorts(view) { | 234 | function togglePorts(view) { |
| 235 | - | 235 | + view.alert('togglePorts() callback') |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | function unpin(view) { | 238 | function unpin(view) { |
| 239 | - | 239 | + view.alert('unpin() callback') |
| 240 | } | 240 | } |
| 241 | 241 | ||
| 242 | // ============================== | 242 | // ============================== |
| ... | @@ -248,19 +248,19 @@ | ... | @@ -248,19 +248,19 @@ |
| 248 | // d3.selectAll('svg .port').classed('inactive', false); | 248 | // d3.selectAll('svg .port').classed('inactive', false); |
| 249 | // d3.selectAll('svg .portText').classed('inactive', false); | 249 | // d3.selectAll('svg .portText').classed('inactive', false); |
| 250 | // TODO ... | 250 | // TODO ... |
| 251 | - console.log('showAllLayers()'); | 251 | + network.view.alert('showAllLayers() callback'); |
| 252 | } | 252 | } |
| 253 | 253 | ||
| 254 | function showPacketLayer() { | 254 | function showPacketLayer() { |
| 255 | showAllLayers(); | 255 | showAllLayers(); |
| 256 | // TODO ... | 256 | // TODO ... |
| 257 | - console.log('showPacketLayer()'); | 257 | + network.view.alert('showPacketLayer() callback'); |
| 258 | } | 258 | } |
| 259 | 259 | ||
| 260 | function showOpticalLayer() { | 260 | function showOpticalLayer() { |
| 261 | showAllLayers(); | 261 | showAllLayers(); |
| 262 | // TODO ... | 262 | // TODO ... |
| 263 | - console.log('showOpticalLayer()'); | 263 | + network.view.alert('showOpticalLayer() callback'); |
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | // ============================== | 266 | // ============================== |
| ... | @@ -279,11 +279,6 @@ | ... | @@ -279,11 +279,6 @@ |
| 279 | }); | 279 | }); |
| 280 | } | 280 | } |
| 281 | 281 | ||
| 282 | - function establishWebSocket() { | ||
| 283 | - // TODO: establish a real web-socket | ||
| 284 | - // NOTE, for now, we are using the 'Q' key to artificially inject | ||
| 285 | - // "events" from the server. | ||
| 286 | - } | ||
| 287 | 282 | ||
| 288 | // ============================== | 283 | // ============================== |
| 289 | // Event handlers for server-pushed events | 284 | // Event handlers for server-pushed events |
| ... | @@ -334,8 +329,7 @@ | ... | @@ -334,8 +329,7 @@ |
| 334 | // .... | 329 | // .... |
| 335 | 330 | ||
| 336 | function unknownEvent(data) { | 331 | function unknownEvent(data) { |
| 337 | - // TODO: use dialog, not alert | 332 | + network.view.alert('Unknown event type: "' + data.event + '"'); |
| 338 | - alert('Unknown event type: "' + data.event + '"'); | ||
| 339 | } | 333 | } |
| 340 | 334 | ||
| 341 | function handleServerEvent(data) { | 335 | function handleServerEvent(data) { |
| ... | @@ -360,7 +354,9 @@ | ... | @@ -360,7 +354,9 @@ |
| 360 | lnk; | 354 | lnk; |
| 361 | 355 | ||
| 362 | if (!(srcNode && dstNode)) { | 356 | if (!(srcNode && dstNode)) { |
| 363 | - alert('nodes not on map'); | 357 | + // TODO: send warning message back to server on websocket |
| 358 | + network.view.alert('nodes not on map for link\n\n' + | ||
| 359 | + 'src = ' + src + '\ndst = ' + dst); | ||
| 364 | return null; | 360 | return null; |
| 365 | } | 361 | } |
| 366 | 362 | ||
| ... | @@ -381,6 +377,7 @@ | ... | @@ -381,6 +377,7 @@ |
| 381 | 377 | ||
| 382 | function linkWidth(w) { | 378 | function linkWidth(w) { |
| 383 | // w is number of links between nodes. Scale appropriately. | 379 | // w is number of links between nodes. Scale appropriately. |
| 380 | + // TODO: use a d3.scale (linear, log, ... ?) | ||
| 384 | return w * 1.2; | 381 | return w * 1.2; |
| 385 | } | 382 | } |
| 386 | 383 | ||
| ... | @@ -705,7 +702,6 @@ | ... | @@ -705,7 +702,6 @@ |
| 705 | .on('tick', tick); | 702 | .on('tick', tick); |
| 706 | 703 | ||
| 707 | network.drag = d3u.createDragBehavior(network.force, selectCb, atDragEnd); | 704 | network.drag = d3u.createDragBehavior(network.force, selectCb, atDragEnd); |
| 708 | - webSock.connect(); | ||
| 709 | } | 705 | } |
| 710 | 706 | ||
| 711 | function load(view, ctx) { | 707 | function load(view, ctx) { |
| ... | @@ -716,7 +712,9 @@ | ... | @@ -716,7 +712,9 @@ |
| 716 | view.setRadio(btnSet); | 712 | view.setRadio(btnSet); |
| 717 | view.setKeys(keyDispatch); | 713 | view.setKeys(keyDispatch); |
| 718 | 714 | ||
| 719 | - establishWebSocket(); | 715 | + if (config.useLiveData) { |
| 716 | + webSock.connect(); | ||
| 717 | + } | ||
| 720 | } | 718 | } |
| 721 | 719 | ||
| 722 | function resize(view, ctx) { | 720 | function resize(view, ctx) { | ... | ... |
-
Please register or login to post a comment