UNPKG

@antv/f2

Version:

Charts for mobile visualization.

51 lines (50 loc) 1.5 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = _default; var _round = _interopRequireDefault(require("./treemap/round.js")); var _dice = _interopRequireDefault(require("./treemap/dice.js")); function _default() { var dx = 1, dy = 1, padding = 0, round = false; function partition(root) { var n = root.height + 1; root.x0 = root.y0 = padding; root.x1 = dx; root.y1 = dy / n; root.eachBefore(positionNode(dy, n)); if (round) root.eachBefore(_round.default); return root; } function positionNode(dy, n) { return function (node) { if (node.children) { (0, _dice.default)(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n); } var x0 = node.x0, y0 = node.y0, x1 = node.x1 - padding, y1 = node.y1 - padding; if (x1 < x0) x0 = x1 = (x0 + x1) / 2; if (y1 < y0) y0 = y1 = (y0 + y1) / 2; node.x0 = x0; node.y0 = y0; node.x1 = x1; node.y1 = y1; }; } partition.round = function (x) { return arguments.length ? (round = !!x, partition) : round; }; partition.size = function (x) { return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy]; }; partition.padding = function (x) { return arguments.length ? (padding = +x, partition) : padding; }; return partition; }