2014-06-24 Alejandro Gallardo <alejandro.gallardo@artica.es>
* include/graphs/pandora.d3.js: Fixed some errors on the graph created by the function "treeMap". git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10279 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
752b7a9fee
commit
2a829eea2e
|
@ -1,3 +1,8 @@
|
||||||
|
2014-06-24 Alejandro Gallardo <alejandro.gallardo@artica.es>
|
||||||
|
|
||||||
|
* include/graphs/pandora.d3.js: Fixed some errors on
|
||||||
|
the graph created by the function "treeMap".
|
||||||
|
|
||||||
2014-06-24 Miguel de Dios <miguel.dedios@artica.es>
|
2014-06-24 Miguel de Dios <miguel.dedios@artica.es>
|
||||||
|
|
||||||
* godmode/setup/setup_visuals.php, include/functions_networkmap.php,
|
* godmode/setup/setup_visuals.php, include/functions_networkmap.php,
|
||||||
|
|
|
@ -337,149 +337,152 @@ function treeMap(recipient, data, width, height) {
|
||||||
var nodes = treemap.nodes(root);
|
var nodes = treemap.nodes(root);
|
||||||
|
|
||||||
var children = nodes.filter(function(d) {
|
var children = nodes.filter(function(d) {
|
||||||
return !d.children;
|
return !d.children;
|
||||||
});
|
});
|
||||||
var parents = nodes.filter(function(d) {
|
var parents = nodes.filter(function(d) {
|
||||||
return d.children;
|
return d.children;
|
||||||
});
|
});
|
||||||
|
|
||||||
// create parent cells
|
// create parent cells
|
||||||
var parentCells = chart.selectAll("g.cell.parent")
|
var parentCells = chart.selectAll("g.cell.parent")
|
||||||
.data(parents, function(d) {
|
.data(parents, function(d) {
|
||||||
return "p-" + d.name;
|
return d.id;
|
||||||
});
|
});
|
||||||
var parentEnterTransition = parentCells.enter()
|
var parentEnterTransition = parentCells.enter()
|
||||||
.append("g")
|
.append("g")
|
||||||
.attr("class", "cell parent")
|
.attr("class", "cell parent")
|
||||||
.on("click", function(d) {
|
.on("click", function(d) {
|
||||||
zoom(d);
|
zoom(d);
|
||||||
})
|
})
|
||||||
.append("svg")
|
.append("svg")
|
||||||
.attr("class", "clip")
|
.attr("class", "clip")
|
||||||
.attr("width", function(d) {
|
.attr("width", function(d) {
|
||||||
return Math.max(0.01, d.dx);
|
return Math.max(0.01, d.dx);
|
||||||
})
|
})
|
||||||
.attr("height", headerHeight);
|
.attr("height", headerHeight);
|
||||||
parentEnterTransition.append("rect")
|
parentEnterTransition.append("rect")
|
||||||
.attr("width", function(d) {
|
.attr("width", function(d) {
|
||||||
return Math.max(0.01, d.dx);
|
return Math.max(0.01, d.dx);
|
||||||
})
|
})
|
||||||
.attr("height", headerHeight)
|
.attr("height", headerHeight)
|
||||||
.style("fill", headerColor);
|
.style("fill", headerColor);
|
||||||
parentEnterTransition.append('text')
|
parentEnterTransition.append('text')
|
||||||
.attr("class", "label")
|
.attr("class", "label")
|
||||||
.attr("fill", "white")
|
.attr("fill", "white")
|
||||||
.attr("transform", "translate(3, 13)")
|
.attr("transform", "translate(3, 13)")
|
||||||
.attr("width", function(d) {
|
.attr("width", function(d) {
|
||||||
return Math.max(0.01, d.dx);
|
return Math.max(0.01, d.dx);
|
||||||
})
|
})
|
||||||
.attr("height", headerHeight)
|
.attr("height", headerHeight)
|
||||||
.text(function(d) {
|
.text(function(d) {
|
||||||
return d.name;
|
return d.name;
|
||||||
});
|
});
|
||||||
// update transition
|
// update transition
|
||||||
var parentUpdateTransition = parentCells.transition().duration(transitionDuration);
|
var parentUpdateTransition = parentCells.transition().duration(transitionDuration);
|
||||||
parentUpdateTransition.select(".cell")
|
parentUpdateTransition.select(".cell")
|
||||||
.attr("transform", function(d) {
|
.attr("transform", function(d) {
|
||||||
return "translate(" + d.dx + "," + d.y + ")";
|
return "translate(" + d.dx + "," + d.y + ")";
|
||||||
});
|
});
|
||||||
parentUpdateTransition.select("rect")
|
parentUpdateTransition.select("rect")
|
||||||
.attr("width", function(d) {
|
.attr("width", function(d) {
|
||||||
return Math.max(0.01, d.dx);
|
return Math.max(0.01, d.dx);
|
||||||
})
|
})
|
||||||
.attr("height", headerHeight)
|
.attr("height", headerHeight)
|
||||||
.style("fill", headerColor);
|
.style("fill", headerColor);
|
||||||
parentUpdateTransition.select(".label")
|
parentUpdateTransition.select(".label")
|
||||||
.attr("transform", "translate(3, 13)")
|
.attr("transform", "translate(3, 13)")
|
||||||
.attr("width", function(d) {
|
.attr("width", function(d) {
|
||||||
return Math.max(0.01, d.dx);
|
return Math.max(0.01, d.dx);
|
||||||
})
|
})
|
||||||
.attr("height", headerHeight)
|
.attr("height", headerHeight)
|
||||||
.text(function(d) {
|
.text(function(d) {
|
||||||
return d.name;
|
return d.name;
|
||||||
});
|
});
|
||||||
// remove transition
|
// remove transition
|
||||||
parentCells.exit()
|
parentCells.exit()
|
||||||
.remove();
|
.remove();
|
||||||
|
|
||||||
// create children cells
|
// create children cells
|
||||||
var childrenCells = chart.selectAll("g.cell.child")
|
var childrenCells = chart.selectAll("g.cell.child")
|
||||||
.data(children, function(d) {
|
.data(children, function(d) {
|
||||||
return "c-" + d.name;
|
return d.id;
|
||||||
});
|
});
|
||||||
// enter transition
|
|
||||||
var childEnterTransition = childrenCells.enter()
|
|
||||||
.append("g")
|
|
||||||
.attr("class", "cell child")
|
|
||||||
.on("click", function(d) {
|
|
||||||
zoom(node === d.parent ? root : d.parent);
|
|
||||||
})
|
|
||||||
.on("mouseover", over_user)
|
|
||||||
.on("mouseout", out_user)
|
|
||||||
.on("mousemove", move_tooltip)
|
|
||||||
.append("svg")
|
|
||||||
.attr("class", "clip");
|
|
||||||
childEnterTransition.append("rect")
|
|
||||||
.classed("background", true)
|
|
||||||
.style("fill", function(d) {
|
|
||||||
return color(d.parent.name);
|
|
||||||
});
|
|
||||||
childEnterTransition.append('text')
|
|
||||||
.attr("class", "label")
|
|
||||||
.attr('x', function(d) {
|
|
||||||
return d.dx / 2;
|
|
||||||
})
|
|
||||||
.attr('y', function(d) {
|
|
||||||
return d.dy / 2;
|
|
||||||
})
|
|
||||||
.attr("dy", ".35em")
|
|
||||||
.attr("text-anchor", "middle")
|
|
||||||
.style("display", "none")
|
|
||||||
.text(function(d) {
|
|
||||||
return d.name;
|
|
||||||
});
|
|
||||||
// update transition
|
|
||||||
var childUpdateTransition = childrenCells.transition().duration(transitionDuration);
|
|
||||||
childUpdateTransition.select(".cell")
|
|
||||||
.attr("transform", function(d) {
|
|
||||||
return "translate(" + d.x + "," + d.y + ")";
|
|
||||||
});
|
|
||||||
childUpdateTransition.select("rect")
|
|
||||||
.attr("width", function(d) {
|
|
||||||
return Math.max(0.01, d.dx);
|
|
||||||
})
|
|
||||||
.attr("height", function(d) {
|
|
||||||
return d.dy;
|
|
||||||
})
|
|
||||||
.style("fill", function(d) {
|
|
||||||
return color(d.parent.name);
|
|
||||||
});
|
|
||||||
childUpdateTransition.select(".label")
|
|
||||||
.attr('x', function(d) {
|
|
||||||
return d.dx / 2;
|
|
||||||
})
|
|
||||||
.attr('y', function(d) {
|
|
||||||
return d.dy / 2;
|
|
||||||
})
|
|
||||||
.attr("dy", ".35em")
|
|
||||||
.attr("text-anchor", "middle")
|
|
||||||
.style("display", "none")
|
|
||||||
.text(function(d) {
|
|
||||||
return d.name;
|
|
||||||
});
|
|
||||||
|
|
||||||
// exit transition
|
// enter transition
|
||||||
childrenCells.exit()
|
var childEnterTransition = childrenCells.enter()
|
||||||
.remove();
|
.append("g")
|
||||||
|
.attr("class", "cell child")
|
||||||
|
.on("click", function(d) {
|
||||||
|
zoom(node === d.parent ? root : d.parent);
|
||||||
|
})
|
||||||
|
.on("mouseover", over_user)
|
||||||
|
.on("mouseout", out_user)
|
||||||
|
.on("mousemove", move_tooltip)
|
||||||
|
.append("svg")
|
||||||
|
.attr("class", "clip");
|
||||||
|
|
||||||
d3.select("select").on("change", function() {
|
childEnterTransition.append("rect")
|
||||||
console.log("select zoom(node)");
|
.classed("background", true)
|
||||||
treemap.value(this.value == "size" ? size : count)
|
.style("fill", function(d) {
|
||||||
.nodes(root);
|
return color(d.name);
|
||||||
zoom(node);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
zoom(node);
|
childEnterTransition.append('text')
|
||||||
|
.attr("class", "label")
|
||||||
|
.attr('x', function(d) {
|
||||||
|
return d.dx / 2;
|
||||||
|
})
|
||||||
|
.attr('y', function(d) {
|
||||||
|
return d.dy / 2;
|
||||||
|
})
|
||||||
|
.attr("dy", ".35em")
|
||||||
|
.attr("text-anchor", "middle")
|
||||||
|
.style("display", "none")
|
||||||
|
.text(function(d) {
|
||||||
|
return d.name;
|
||||||
|
});
|
||||||
|
|
||||||
|
// update transition
|
||||||
|
var childUpdateTransition = childrenCells.transition().duration(transitionDuration);
|
||||||
|
|
||||||
|
childUpdateTransition.select(".cell")
|
||||||
|
.attr("transform", function(d) {
|
||||||
|
return "translate(" + d.x + "," + d.y + ")";
|
||||||
|
});
|
||||||
|
|
||||||
|
childUpdateTransition.select("rect")
|
||||||
|
.attr("width", function(d) {
|
||||||
|
return Math.max(0.01, d.dx);
|
||||||
|
})
|
||||||
|
.attr("height", function(d) {
|
||||||
|
return d.dy;
|
||||||
|
});
|
||||||
|
|
||||||
|
childUpdateTransition.select(".label")
|
||||||
|
.attr('x', function(d) {
|
||||||
|
return d.dx / 2;
|
||||||
|
})
|
||||||
|
.attr('y', function(d) {
|
||||||
|
return d.dy / 2;
|
||||||
|
})
|
||||||
|
.attr("dy", ".35em")
|
||||||
|
.attr("text-anchor", "middle")
|
||||||
|
.style("display", "none")
|
||||||
|
.text(function(d) {
|
||||||
|
return d.name;
|
||||||
|
});
|
||||||
|
|
||||||
|
// exit transition
|
||||||
|
childrenCells.exit()
|
||||||
|
.remove();
|
||||||
|
|
||||||
|
d3.select("select").on("change", function() {
|
||||||
|
treemap.value(this.value == "size" ? size : count)
|
||||||
|
.nodes(root);
|
||||||
|
zoom(node);
|
||||||
|
});
|
||||||
|
|
||||||
|
zoom(node);
|
||||||
|
|
||||||
function size(d) {
|
function size(d) {
|
||||||
return d.size;
|
return d.size;
|
||||||
|
@ -513,90 +516,88 @@ function treeMap(recipient, data, width, height) {
|
||||||
var bgDelta = (components.R * 0.299) + (components.G * 0.587) + (components.B * 0.114);
|
var bgDelta = (components.R * 0.299) + (components.G * 0.587) + (components.B * 0.114);
|
||||||
return ((255 - bgDelta) < nThreshold) ? "#000000" : "#ffffff";
|
return ((255 - bgDelta) < nThreshold) ? "#000000" : "#ffffff";
|
||||||
}
|
}
|
||||||
function zoom(d) {
|
|
||||||
treemap
|
|
||||||
.padding([headerHeight / (chartHeight / d.dy), 0, 0, 0])
|
|
||||||
.nodes(d);
|
|
||||||
|
|
||||||
// moving the next two lines above treemap layout messes up padding of zoom result
|
function zoom(d) {
|
||||||
var kx = chartWidth / d.dx;
|
treemap
|
||||||
var ky = chartHeight / d.dy;
|
.padding([headerHeight / (chartHeight / d.dy), 0, 0, 0])
|
||||||
var level = d;
|
.nodes(d);
|
||||||
|
|
||||||
xscale.domain([d.x, d.x + d.dx]);
|
// moving the next two lines above treemap layout messes up padding of zoom result
|
||||||
yscale.domain([d.y, d.y + d.dy]);
|
var kx = chartWidth / d.dx;
|
||||||
|
var ky = chartHeight / d.dy;
|
||||||
|
var level = d;
|
||||||
|
|
||||||
if (node != level) {
|
xscale.domain([d.x, d.x + d.dx]);
|
||||||
chart.selectAll(".cell.child .label")
|
yscale.domain([d.y, d.y + d.dy]);
|
||||||
.style("display", "none");
|
|
||||||
}
|
|
||||||
|
|
||||||
var zoomTransition = chart.selectAll("g.cell").transition().duration(transitionDuration)
|
if (node != level) {
|
||||||
.attr("transform", function(d) {
|
chart.selectAll(".cell.child .label")
|
||||||
return "translate(" + xscale(d.x) + "," + yscale(d.y) + ")";
|
.style("display", "none");
|
||||||
})
|
}
|
||||||
.each("start", function() {
|
|
||||||
d3.select(this).select("label")
|
|
||||||
.style("display", "none");
|
|
||||||
})
|
|
||||||
.each("end", function(d, i) {
|
|
||||||
if (!i && (level !== self.root)) {
|
|
||||||
chart.selectAll(".cell.child")
|
|
||||||
.filter(function(d) {
|
|
||||||
return d.parent === self.node; // only get the children for selected group
|
|
||||||
})
|
|
||||||
.select(".label")
|
|
||||||
.style("display", "")
|
|
||||||
.style("fill", function(d) {
|
|
||||||
return idealTextColor(color(d.parent.name));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
zoomTransition.select(".clip")
|
var zoomTransition = chart.selectAll("g.cell").transition().duration(transitionDuration)
|
||||||
.attr("width", function(d) {
|
.attr("transform", function(d) {
|
||||||
return Math.max(0.01, (kx * d.dx));
|
return "translate(" + xscale(d.x) + "," + yscale(d.y) + ")";
|
||||||
})
|
})
|
||||||
.attr("height", function(d) {
|
.each("start", function() {
|
||||||
return d.children ? headerHeight : Math.max(0.01, (ky * d.dy));
|
d3.select(this).select("label")
|
||||||
});
|
.style("display", "none");
|
||||||
|
})
|
||||||
|
.each("end", function(d, i) {
|
||||||
|
if (!i && (level !== self.root)) {
|
||||||
|
chart.selectAll(".cell.child")
|
||||||
|
.filter(function(d) {
|
||||||
|
return d.parent === self.node; // only get the children for selected group
|
||||||
|
})
|
||||||
|
.select(".label")
|
||||||
|
.style("display", "")
|
||||||
|
.style("color", function(d) {
|
||||||
|
return idealTextColor(color(d.parent.name));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
zoomTransition.select(".label")
|
zoomTransition.select(".clip")
|
||||||
.attr("width", function(d) {
|
.attr("width", function(d) {
|
||||||
return Math.max(0.01, (kx * d.dx));
|
return Math.max(0.01, (kx * d.dx));
|
||||||
})
|
})
|
||||||
.attr("height", function(d) {
|
.attr("height", function(d) {
|
||||||
return d.children ? headerHeight : Math.max(0.01, (ky * d.dy));
|
return d.children ? headerHeight : Math.max(0.01, (ky * d.dy));
|
||||||
})
|
});
|
||||||
.text(function(d) {
|
|
||||||
return d.name;
|
|
||||||
});
|
|
||||||
|
|
||||||
zoomTransition.select(".child .label")
|
zoomTransition.select(".label")
|
||||||
.attr("x", function(d) {
|
.attr("width", function(d) {
|
||||||
return kx * d.dx / 2;
|
return Math.max(0.01, (kx * d.dx));
|
||||||
})
|
})
|
||||||
.attr("y", function(d) {
|
.attr("height", function(d) {
|
||||||
return ky * d.dy / 2;
|
return d.children ? headerHeight : Math.max(0.01, (ky * d.dy));
|
||||||
});
|
})
|
||||||
|
.text(function(d) {
|
||||||
|
return d.name;
|
||||||
|
});
|
||||||
|
|
||||||
zoomTransition.select("rect")
|
zoomTransition.select(".child .label")
|
||||||
.attr("width", function(d) {
|
.attr("x", function(d) {
|
||||||
return Math.max(0.01, (kx * d.dx));
|
return kx * d.dx / 2;
|
||||||
})
|
})
|
||||||
.attr("height", function(d) {
|
.attr("y", function(d) {
|
||||||
return d.children ? headerHeight : Math.max(0.01, (ky * d.dy));
|
return ky * d.dy / 2;
|
||||||
})
|
});
|
||||||
.style("fill", function(d) {
|
|
||||||
return d.children ? headerColor : color(d.parent.name);
|
|
||||||
});
|
|
||||||
|
|
||||||
node = d;
|
zoomTransition.select("rect")
|
||||||
|
.attr("width", function(d) {
|
||||||
|
return Math.max(0.01, (kx * d.dx));
|
||||||
|
})
|
||||||
|
.attr("height", function(d) {
|
||||||
|
return d.children ? headerHeight : Math.max(0.01, (ky * d.dy));
|
||||||
|
});
|
||||||
|
|
||||||
if (d3.event) {
|
node = d;
|
||||||
d3.event.stopPropagation();
|
|
||||||
}
|
if (d3.event) {
|
||||||
}
|
d3.event.stopPropagation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function position() {
|
function position() {
|
||||||
|
|
Loading…
Reference in New Issue