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