UNPKG

@rxflow/base

Version:

BaseFlow - 核心 Flow 组件库

133 lines (129 loc) 3.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mindMapLayout = void 0; var _hierarchy = _interopRequireDefault(require("@antv/hierarchy")); var _ = require("../.."); var _dimension = require("../dimension"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @author: yanxianliang * @date: 2025-07-03 09:53 * @desc: mindmap 布局 * * Copyright (c) 2025 by yanxianliang, All Rights Reserved. */ const mindMapLayout = (layoutConfig = {}, config) => { const { originNodes, theme, nodeTypes } = config; const rootNode = originNodes?.[0]; if (!rootNode) { return { nodes: [], edges: [] }; } const edges = []; const { hGap = 40, vGap = 20, markerType } = layoutConfig; const layoutInfo = _hierarchy.default.mindmap(rootNode, { direction: 'H', getId(node) { return node.id; }, getWidth(node) { const width = (0, _dimension.getNodeWidth)(node, nodeTypes, theme); // 还不是node实例。 node.width = width; return width; }, getHeight(node) { const height = (0, _dimension.getNodeHeight)(node, nodeTypes, theme); node.height = height; return height; }, getHGap() { return hGap; }, getVGap() { return vGap; }, getSide: node => { const data = node.data; return 'side' in data ? data.side : 'right'; }, getChildren: node => { let children = []; if ('collapsed' in node && node.collapsed === false) { children = node.children || []; } for (const child of children) { // edge ==> 是否显示箭头,需要配置 edges.push({ type: 'smoothstep', id: `${node.id}_${child.id}`, source: node.id, target: child.id, markerEnd: markerType }); } return children; } }); // 开始节点x,y 以(0,0)进行修正,根节点需要能够被检测显示在画布区域 let nodes = []; const { x: rootX, y: rootY } = layoutInfo; layoutInfo.BFTraverse(node => { const { x, y, data } = node; const { id, type, width, height } = data; const nodeWidth = width; const nodeHeight = height; const adjustX = x - rootX; const adjustY = y - rootY; const position = { x: adjustX, y: adjustY }; // 固定宽度和高度的节点,不支持动态适应内容 const graphNode = { id, type, measured: { width: nodeWidth, height: nodeHeight }, width: nodeWidth, height: nodeHeight, data, position: position, zIndex: 10 }; const definition = nodeTypes?.[type]; const handles = definition?.measureHandles?.(graphNode); graphNode.handles = (0, _.parseHandles)(handles); nodes.push(graphNode); }); return { nodes, edges }; }; exports.mindMapLayout = mindMapLayout;