Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 1 | /*************************************************************************************************** |
| 2 | extract url parameters into a map |
| 3 | ***************************************************************************************************/ |
Paul Greyson | bcd3c77 | 2013-03-21 13:16:44 -0700 | [diff] [blame] | 4 | function parseURLParameters() { |
| 5 | var parameters = {}; |
| 6 | |
| 7 | var search = location.href.split('?')[1]; |
| 8 | if (search) { |
| 9 | search.split('&').forEach(function (param) { |
| 10 | var key = param.split('=')[0]; |
| 11 | var value = param.split('=')[1]; |
| 12 | parameters[key] = decodeURIComponent(value); |
| 13 | }); |
| 14 | } |
| 15 | |
| 16 | return parameters; |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 17 | } |
| 18 | |
Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 19 | /*************************************************************************************************** |
| 20 | convenience function for moving an SVG element to the front so that it draws on top |
| 21 | ***************************************************************************************************/ |
| 22 | d3.selection.prototype.moveToFront = function() { |
| 23 | return this.each(function(){ |
| 24 | this.parentNode.appendChild(this); |
| 25 | }); |
| 26 | }; |
| 27 | |
| 28 | /*************************************************************************************************** |
| 29 | standard function for generating the 'd' attribute for a path from an array of points |
| 30 | ***************************************************************************************************/ |
| 31 | var line = d3.svg.line() |
| 32 | .x(function(d) { |
| 33 | return d.x; |
| 34 | }) |
| 35 | .y(function(d) { |
| 36 | return d.y; |
| 37 | }); |
| 38 | |
| 39 | |
| 40 | /*************************************************************************************************** |
| 41 | starts the "pending" animation |
| 42 | ***************************************************************************************************/ |
| 43 | function setPending(selection) { |
| 44 | selection.classed('pending', false); |
| 45 | setTimeout(function () { |
| 46 | selection.classed('pending', true); |
| 47 | }, 0); |
| 48 | } |
| 49 | |
| 50 | /*************************************************************************************************** |
| 51 | convert angle in degrees to radians |
| 52 | ***************************************************************************************************/ |
| 53 | function toRadians (degrees) { |
| 54 | return degrees * (Math.PI / 180); |
| 55 | } |
| 56 | |
| 57 | /*************************************************************************************************** |
| 58 | used to generate DOM element id for this link |
| 59 | ***************************************************************************************************/ |
| 60 | function makeLinkKey(link) { |
| 61 | return link['src-switch'] + '=>' + link['dst-switch']; |
| 62 | } |
| 63 | |
| 64 | /*************************************************************************************************** |
| 65 | used to generate DOM element id for this flow in the topology view |
| 66 | ***************************************************************************************************/ |
| 67 | function makeFlowKey(flow) { |
| 68 | return flow.srcDpid + '=>' + flow.dstDpid; |
| 69 | } |
| 70 | |
| 71 | /*************************************************************************************************** |
| 72 | used to generate DOM element id for this flow in the selected flows table |
| 73 | ***************************************************************************************************/ |
| 74 | function makeSelectedFlowKey(flow) { |
| 75 | return 'S' + makeFlowKey(flow); |
| 76 | } |
| 77 | |
| 78 | /*************************************************************************************************** |
| 79 | update the app header using the current model |
| 80 | ***************************************************************************************************/ |
| 81 | function updateHeader() { |
| 82 | d3.select('#lastUpdate').text(new Date()); |
| 83 | d3.select('#activeSwitches').text(model.edgeSwitches.length + model.aggregationSwitches.length + model.coreSwitches.length); |
| 84 | d3.select('#activeFlows').text(model.flows.length); |
| 85 | } |
| 86 | |
| 87 | |