refactor for new topology view
diff --git a/web/ons-demo/js/utils.js b/web/ons-demo/js/utils.js
index 4f6d0c1..d597507 100644
--- a/web/ons-demo/js/utils.js
+++ b/web/ons-demo/js/utils.js
@@ -1,3 +1,6 @@
+/***************************************************************************************************
+extract url parameters into a map
+***************************************************************************************************/
function parseURLParameters() {
var parameters = {};
@@ -13,12 +16,72 @@
return parameters;
}
-function findLink(model, dpid) {
- var links = [];
- model.links.forEach(function (link) {
- if (link['src-switch'] == dpid || link['dst-switch'] == dpid) {
- links.push(link);
- }
- });
- return links;
-}
\ No newline at end of file
+/***************************************************************************************************
+convenience function for moving an SVG element to the front so that it draws on top
+***************************************************************************************************/
+d3.selection.prototype.moveToFront = function() {
+ return this.each(function(){
+ this.parentNode.appendChild(this);
+ });
+};
+
+/***************************************************************************************************
+standard function for generating the 'd' attribute for a path from an array of points
+***************************************************************************************************/
+var line = d3.svg.line()
+ .x(function(d) {
+ return d.x;
+ })
+ .y(function(d) {
+ return d.y;
+ });
+
+
+/***************************************************************************************************
+starts the "pending" animation
+***************************************************************************************************/
+function setPending(selection) {
+ selection.classed('pending', false);
+ setTimeout(function () {
+ selection.classed('pending', true);
+ }, 0);
+}
+
+/***************************************************************************************************
+convert angle in degrees to radians
+***************************************************************************************************/
+function toRadians (degrees) {
+ return degrees * (Math.PI / 180);
+}
+
+/***************************************************************************************************
+used to generate DOM element id for this link
+***************************************************************************************************/
+function makeLinkKey(link) {
+ return link['src-switch'] + '=>' + link['dst-switch'];
+}
+
+/***************************************************************************************************
+used to generate DOM element id for this flow in the topology view
+***************************************************************************************************/
+function makeFlowKey(flow) {
+ return flow.srcDpid + '=>' + flow.dstDpid;
+}
+
+/***************************************************************************************************
+used to generate DOM element id for this flow in the selected flows table
+***************************************************************************************************/
+function makeSelectedFlowKey(flow) {
+ return 'S' + makeFlowKey(flow);
+}
+
+/***************************************************************************************************
+update the app header using the current model
+***************************************************************************************************/
+function updateHeader() {
+ d3.select('#lastUpdate').text(new Date());
+ d3.select('#activeSwitches').text(model.edgeSwitches.length + model.aggregationSwitches.length + model.coreSwitches.length);
+ d3.select('#activeFlows').text(model.flows.length);
+}
+
+