Merge "Code quality improvements in heat topology"

This commit is contained in:
Jenkins 2013-10-01 14:51:02 +00:00 committed by Gerrit Code Review
commit a87b853d73

View File

@ -22,46 +22,19 @@
var container = "#heat_resource_topology";
if ($(container).length){
var width = $(container).width(),
height = 500,
stack_id = $("#stack_id").data("stack_id"),
ajax_url = '/project/stacks/get_d3_data/'+stack_id+'/',
graph = $("#d3_data").data("d3_data"),
force = d3.layout.force()
.nodes(graph.nodes)
.links([])
.gravity(0.1)
.charge(-2000)
.linkDistance(100)
.size([width, height])
.on("tick",tick),
svg = d3.select(container).append("svg")
.attr("width", width)
.attr("height", height),
node = svg.selectAll(".node"),
link = svg.selectAll(".link"),
needs_update = false,
nodes = force.nodes(),
links = force.links();
build_links();
update();
function update(){
node = node.data(nodes, function(d){return d.name});
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 })
.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("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; })
@ -82,47 +55,43 @@ if ($(container).length){
});
force.start();
}
function tick() {
}
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 + ")"; });
}
}
//Load initial Stack box
$("#stack_box").html(graph.stack.info_box);
//On Page load, set Action In Progress
var in_progress = false;
set_in_progress(graph.stack, node);
//If status is In Progress, start AJAX polling
var poll_time = 0;
if (in_progress == true){poll_time = 3000;}
else {poll_time = 30000;}
ajax_poll(poll_time);
function set_in_progress(stack, nodes) {
if (stack.in_progress == true){in_progress = true;}
for (var i=0;i<nodes.length;i++) {
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;}
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) {
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) {
}
function removeNode (name) {
var i = 0;
var n = findNode(name);
while (i < links.length) {
@ -134,8 +103,9 @@ if ($(container).length){
}
nodes.splice(findNodeIndex(name),1);
needs_update = true;
};
function remove_nodes(old_nodes, new_nodes){
}
function remove_nodes(old_nodes, new_nodes){
//Check for removed nodes
for (var i=0;i<old_nodes.length;i++) {
var remove_node = true;
@ -145,18 +115,20 @@ if ($(container).length){
break;
}
}
if (remove_node==true){
if (remove_node === true){
removeNode(old_nodes[i].name);
}
}
}
function build_links(){
}
function build_links(){
for (var i=0;i<nodes.length;i++){
build_node_links(nodes[i]);
build_reverse_links(nodes[i]);
}
}
function build_node_links(node){
}
function build_node_links(node){
for (var j=0;j<node.required_by.length;j++){
var push_link = true;
var target_idx = '';
@ -177,7 +149,7 @@ if ($(container).length){
}
}
if (push_link==true && (source_idx && target_idx)){
if (push_link === true && (source_idx && target_idx)){
links.push({
'source':source_idx,
'target':target_idx,
@ -185,9 +157,9 @@ if ($(container).length){
});
}
}
}
}
function build_reverse_links(node){
function build_reverse_links(node){
for (var i=0;i<nodes.length;i++){
if(nodes[i].required_by){
for (var j=0;j<nodes[i].required_by.length;j++){
@ -198,14 +170,14 @@ if ($(container).length){
'source':findNodeIndex(nodes[i].name),
'target':findNodeIndex(node.name),
'value':1
})
}
});
}
}
}
}
}
function ajax_poll(poll_time){
function ajax_poll(poll_time){
setTimeout(function() {
$.getJSON(ajax_url, function(json) {
//update d3 data element
@ -249,7 +221,7 @@ if ($(container).length){
.transition()
.attr("x", function(d) { return d.image_x; })
.duration(100)
.ease("bounce")
.ease("bounce");
}
//Status has changed, update info_box
@ -262,14 +234,52 @@ if ($(container).length){
});
//if any updates needed, do update now
if (needs_update==true){
if (needs_update === true){
update();
}
});
//if no nodes still in progress, slow AJAX polling
if (in_progress==false){poll_time = 30000;}
else {poll_time = 3000;}
if (in_progress === false) { poll_time = 30000; }
else { poll_time = 3000; }
ajax_poll(poll_time);
}, poll_time);
}
}
if ($(container).length){
var width = $(container).width(),
height = 500,
stack_id = $("#stack_id").data("stack_id"),
ajax_url = '/project/stacks/get_d3_data/' + stack_id + '/',
graph = $("#d3_data").data("d3_data"),
force = d3.layout.force()
.nodes(graph.nodes)
.links([])
.gravity(0.1)
.charge(-2000)
.linkDistance(100)
.size([width, height])
.on("tick", tick),
svg = d3.select(container).append("svg")
.attr("width", width)
.attr("height", height),
node = svg.selectAll(".node"),
link = svg.selectAll(".link"),
needs_update = false,
nodes = force.nodes(),
links = force.links();
build_links();
update();
//Load initial Stack box
$("#stack_box").html(graph.stack.info_box);
//On Page load, set Action In Progress
var in_progress = false;
set_in_progress(graph.stack, node);
//If status is In Progress, start AJAX polling
var poll_time = 0;
if (in_progress === true) { poll_time = 3000; }
else { poll_time = 30000; }
ajax_poll(poll_time);
}