Added configurable treemap layout
This commit is contained in:
Родитель
173a936d68
Коммит
32b02b6902
|
@ -1,10 +1,12 @@
|
|||
// Squarified Treemaps by Mark Bruls, Kees Huizing, and Jarke J. van Wijk
|
||||
// Modified to support a target aspect ratio by Jeff Heer
|
||||
d3.layout.treemap = function() {
|
||||
var hierarchy = d3.layout.hierarchy(),
|
||||
round = Math.round,
|
||||
size = [1, 1], // width, height
|
||||
sticky = false,
|
||||
stickies;
|
||||
stickies,
|
||||
target = 0.5 * (1 + Math.sqrt(5));
|
||||
|
||||
// Recursively compute the node area based on value & scale.
|
||||
function scale(node, k) {
|
||||
|
@ -85,7 +87,9 @@ d3.layout.treemap = function() {
|
|||
}
|
||||
s *= s;
|
||||
u *= u;
|
||||
return Math.max((u * rmax) / s, s / (u * rmin));
|
||||
r = Math.abs((u * rmax) / s - target);
|
||||
s = Math.abs(s / (u * rmin) - target);
|
||||
return Math.max(r, s);
|
||||
}
|
||||
|
||||
// Positions the specified row of nodes. Modifies `rect`.
|
||||
|
@ -162,5 +166,11 @@ d3.layout.treemap = function() {
|
|||
return treemap;
|
||||
};
|
||||
|
||||
treemap.target = function(x) {
|
||||
if (!arguments.length) return target;
|
||||
target = x;
|
||||
return treemap;
|
||||
};
|
||||
|
||||
return treemap;
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче