@visactor/vchart
Version:
charts lib based @visactor/VGrammar
22 lines (18 loc) • 800 B
JavaScript
import { flattenNodes, TreemapLayout } from "@visactor/vlayouts";
import { isFunction } from "@visactor/vutils";
import { DEFAULT_HIERARCHY_ROOT } from "../../constant/hierarchy";
export const treemapLayout = (data, op) => {
const options = isFunction(op) ? op() : op, viewBox = options.getViewBox();
if (viewBox) {
const res = new TreemapLayout(options).layout(data, viewBox), nodes = [];
return flattenNodes(res, nodes, {
maxDepth: null == options ? void 0 : options.maxDepth
}), nodes.forEach((datum => {
datum && [ DEFAULT_HIERARCHY_ROOT, "name" ].forEach((key => {
datum[key] = datum.datum[datum.depth][options.nameField];
}));
})), nodes;
}
return [];
};
//# sourceMappingURL=treemap.js.map