source: node_modules/d3-hierarchy/src/treemap/resquarify.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 1.0 KB
Line 
1import treemapDice from "./dice.js";
2import treemapSlice from "./slice.js";
3import {phi, squarifyRatio} from "./squarify.js";
4
5export default (function custom(ratio) {
6
7 function resquarify(parent, x0, y0, x1, y1) {
8 if ((rows = parent._squarify) && (rows.ratio === ratio)) {
9 var rows,
10 row,
11 nodes,
12 i,
13 j = -1,
14 n,
15 m = rows.length,
16 value = parent.value;
17
18 while (++j < m) {
19 row = rows[j], nodes = row.children;
20 for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
21 if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += (y1 - y0) * row.value / value : y1);
22 else treemapSlice(row, x0, y0, value ? x0 += (x1 - x0) * row.value / value : x1, y1);
23 value -= row.value;
24 }
25 } else {
26 parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
27 rows.ratio = ratio;
28 }
29 }
30
31 resquarify.ratio = function(x) {
32 return custom((x = +x) > 1 ? x : 1);
33 };
34
35 return resquarify;
36})(phi);
Note: See TracBrowser for help on using the repository browser.