basant307/AI_Governance_Project
048
1import roundNode from "./treemap/round.js";2import treemapDice from "./treemap/dice.js";3 4export default function() {5 var dx = 1,6 dy = 1,7 padding = 0,8 round = false;9 10 function partition(root) {11 var n = root.height + 1;12 root.x0 =13 root.y0 = padding;14 root.x1 = dx;15 root.y1 = dy / n;16 root.eachBefore(positionNode(dy, n));17 if (round) root.eachBefore(roundNode);18 return root;19 }20 21 function positionNode(dy, n) {22 return function(node) {23 if (node.children) {24 treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);25 }26 var x0 = node.x0,27 y0 = node.y0,28 x1 = node.x1 - padding,29 y1 = node.y1 - padding;30 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;31 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;32 node.x0 = x0;33 node.y0 = y0;34 node.x1 = x1;35 node.y1 = y1;36 };37 }38 39 partition.round = function(x) {40 return arguments.length ? (round = !!x, partition) : round;41 };42 43 partition.size = function(x) {44 return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];45 };46 47 partition.padding = function(x) {48 return arguments.length ? (padding = +x, partition) : padding;49 };50 51 return partition;52}53 