From 6358ef4d361fa71179e61d73d0254fb63733e1d1 Mon Sep 17 00:00:00 2001 From: Gabriel Hurley Date: Fri, 27 Sep 2013 19:35:05 -0700 Subject: [PATCH] Code quality improvements in heat topology Ensure that functions are not declared conditionally and that they are declared before being assigned as callbacks. This commit contains no code changes, only rearrangement plus whitespace and semicolon fixes. Fixes Bug #1226945 Change-Id: Ie549d48d0ea47d00d904b36555bd68c95ad12f49 --- horizon/static/horizon/js/horizon.heattop.js | 446 ++++++++++--------- 1 file changed, 228 insertions(+), 218 deletions(-) diff --git a/horizon/static/horizon/js/horizon.heattop.js b/horizon/static/horizon/js/horizon.heattop.js index baf9e72c6a..5bd3e125e6 100644 --- a/horizon/static/horizon/js/horizon.heattop.js +++ b/horizon/static/horizon/js/horizon.heattop.js @@ -22,11 +22,234 @@ var container = "#heat_resource_topology"; +function update(){ + node = node.data(nodes, function(d) { return d.name; }); + link = link.data(links); + + var nodeEnter = node.enter().append("g") + .attr("class", "node") + .attr("node_name", function(d) { return d.name; }) + .attr("node_id", function(d) { return d.instance; }) + .call(force.drag); + + nodeEnter.append("image") + .attr("xlink:href", function(d) { return d.image; }) + .attr("id", function(d){ return "image_"+ d.name; }) + .attr("x", function(d) { return d.image_x; }) + .attr("y", function(d) { return d.image_y; }) + .attr("width", function(d) { return d.image_size; }) + .attr("height", function(d) { return d.image_size; }); + node.exit().remove(); + + link.enter().insert("svg:line", "g.node") + .attr("class", "link") + .style("stroke-width", function(d) { return Math.sqrt(d.value); }); + link.exit().remove(); + //Setup click action for all nodes + node.on("mouseover", function(d) { + $("#info_box").html(d.info_box); + current_info = d.name; + }); + node.on("mouseout", function(d) { + $("#info_box").html(''); + }); + + force.start(); +} + +function tick() { + link.attr("x1", function(d) { return d.source.x; }) + .attr("y1", function(d) { return d.source.y; }) + .attr("x2", function(d) { return d.target.x; }) + .attr("y2", function(d) { return d.target.y; }); + + node.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }); +} + +function set_in_progress(stack, nodes) { + if (stack.in_progress === true) { in_progress = true; } + for (var i = 0; i < nodes.length; i++) { + var d = nodes[i]; + if (d.in_progress === true){ in_progress = true; return false; } + } +} + +function findNode(name) { + for (var i = 0; i < nodes.length; i++) { + if (nodes[i].name === name){ return nodes[i]; } + } +} + +function findNodeIndex(name) { + for (var i = 0; i < nodes.length; i++) { + if (nodes[i].name === name){ return i; } + } +} + +function addNode (node) { + nodes.push(node); + needs_update = true; +} + +function removeNode (name) { + var i = 0; + var n = findNode(name); + while (i < links.length) { + if ((links[i]['source'] == n)||(links[i]['target'] == n)) + { + links.splice(i,1); + } + else i++; + } + nodes.splice(findNodeIndex(name),1); + needs_update = true; +} + +function remove_nodes(old_nodes, new_nodes){ + //Check for removed nodes + for (var i=0;i