(ratio, parent, x0, y0, x1, y1)
| 14071 | var phi = (1 + Math.sqrt(5)) / 2; |
| 14072 | |
| 14073 | function squarifyRatio(ratio, parent, x0, y0, x1, y1) { |
| 14074 | var rows = [], |
| 14075 | nodes = parent.children, |
| 14076 | row, |
| 14077 | nodeValue, |
| 14078 | i0 = 0, |
| 14079 | i1 = 0, |
| 14080 | n = nodes.length, |
| 14081 | dx, dy, |
| 14082 | value = parent.value, |
| 14083 | sumValue, |
| 14084 | minValue, |
| 14085 | maxValue, |
| 14086 | newRatio, |
| 14087 | minRatio, |
| 14088 | alpha, |
| 14089 | beta; |
| 14090 | |
| 14091 | while (i0 < n) { |
| 14092 | dx = x1 - x0, dy = y1 - y0; |
| 14093 | |
| 14094 | // Find the next non-empty node. |
| 14095 | do sumValue = nodes[i1++].value; while (!sumValue && i1 < n); |
| 14096 | minValue = maxValue = sumValue; |
| 14097 | alpha = Math.max(dy / dx, dx / dy) / (value * ratio); |
| 14098 | beta = sumValue * sumValue * alpha; |
| 14099 | minRatio = Math.max(maxValue / beta, beta / minValue); |
| 14100 | |
| 14101 | // Keep adding nodes while the aspect ratio maintains or improves. |
| 14102 | for (; i1 < n; ++i1) { |
| 14103 | sumValue += nodeValue = nodes[i1].value; |
| 14104 | if (nodeValue < minValue) minValue = nodeValue; |
| 14105 | if (nodeValue > maxValue) maxValue = nodeValue; |
| 14106 | beta = sumValue * sumValue * alpha; |
| 14107 | newRatio = Math.max(maxValue / beta, beta / minValue); |
| 14108 | if (newRatio > minRatio) { sumValue -= nodeValue; break; } |
| 14109 | minRatio = newRatio; |
| 14110 | } |
| 14111 | |
| 14112 | // Position and record the row orientation. |
| 14113 | rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)}); |
| 14114 | if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1); |
| 14115 | else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1); |
| 14116 | value -= sumValue, i0 = i1; |
| 14117 | } |
| 14118 | |
| 14119 | return rows; |
| 14120 | } |
| 14121 | |
| 14122 | var squarify = (function custom(ratio) { |
| 14123 |
no test coverage detected