import { Graph, Dom, Node } from '@antv/x6' import { basicPorts, customPorts } from './ports' // 基础节点 export const FlowChartRect = Graph.registerNode('flow-chart-rect', { inherit: 'rect', width: 80, height: 42, attrs: { body: { stroke: '#5F95FF', strokeWidth: 1, fill: '#ffffff' }, text: { fontSize: 12, fill: '#080808' } }, markup: [ { tagName: 'rect', selector: 'body' }, { tagName: 'text', selector: 'text' }, { tagName: 'foreignObject', selector: 'fo', children: [ { ns: Dom.ns.xhtml, tagName: 'body', selector: 'foBody', children: [ { tagName: 'div', selector: 'edit-text' } ] } ] } ], ports: { ...basicPorts } }) // 子流程节点 export const SubRect = Graph.registerNode('sub-flow-rect', { inherit: 'rect', width: 200, height: 60, attrs: { body: { stroke: '#5F95FF', strokeWidth: 1, fill: 'rgba(95,149,255,0.05)' }, title: { text: 'Node', refX: 40, refY: 14, fill: 'rgba(0,0,0,0.85)', fontSize: 12, 'text-anchor': 'start' }, text: { text: 'this is content text', refX: 40, refY: 38, fontSize: 12, fill: 'rgba(0,0,0,0.6)', 'text-anchor': 'start' } }, markup: [ { tagName: 'rect', selector: 'body' }, { tagName: 'text', selector: 'title' }, { tagName: 'text', selector: 'text' } ], ports: { ...basicPorts } }) // 逻辑节点 export const logicPath = Graph.registerNode('logic-flow-path', { inherit: 'circle', width: 20, height: 20, attrs: { body: { stroke: '#5F95FF', strokeWidth: 1, fill: '#ffffff' }, lip: { refX: 4, refY: 4, fill: '#d4237a', transform: 'scale(0.01)' } }, markup: [ { tagName: 'circle', selector: 'body' }, { tagName: 'path', selector: 'lip', attrs: { d: 'M366.336 270.506667c20.736 19.029333 21.333333 49.493333 1.536 68.949333l-1.536 1.536L131.84 554.666667l234.496 213.674666c20.736 18.944 21.333333 49.322667 1.536 68.864l-1.536 1.536a58.538667 58.538667 0 0 1-75.605333 1.450667l-1.706667-1.450667-273.066667-248.917333a46.677333 46.677333 0 0 1-1.536-68.864l1.536-1.450667 273.066667-248.917333a58.453333 58.453333 0 0 1 77.312 0z m593.92 425.216c35.242667 0 63.744 26.709333 63.744 59.733333 0 32.256-27.306667 58.624-61.525333 59.733333H509.696c-35.157333 0-63.658667-26.794667-63.658667-59.733333 0-32.341333 27.306667-58.624 61.44-59.733333h452.778667z m0-398.250667c35.242667 0 63.744 26.794667 63.744 59.733333 0 32.341333-27.306667 58.624-61.525333 59.733334H509.696c-35.157333 0-63.658667-26.709333-63.658667-59.733334 0-32.256 27.306667-58.624 61.44-59.733333h452.778667z' } } ], ports: { ...basicPorts } }) // 组合节点 export const FlowChartImageRect = Graph.registerNode('flow-chart-image-rect', { inherit: 'rect', width: 200, height: 60, attrs: { body: { stroke: '#5F95FF', strokeWidth: 1, fill: 'rgba(95,149,255,0.05)' }, title: { text: 'Node', refX: 40, refY: 14, fill: 'rgba(0,0,0,0.85)', fontSize: 12, 'text-anchor': 'start' }, text: { text: 'this is content text', refX: 40, refY: 38, fontSize: 12, fill: 'rgba(0,0,0,0.6)', 'text-anchor': 'start' } }, markup: [ { tagName: 'rect', selector: 'body' }, { tagName: 'text', selector: 'title' }, { tagName: 'text', selector: 'text' } ], ports: { ...basicPorts } }) export const FlowChartTitleRect = Graph.registerNode('flow-chart-title-rect', { inherit: 'rect', width: 200, height: 68, attrs: { body: { stroke: '#5F95FF', strokeWidth: 1, fill: 'rgba(95,149,255,0.05)' }, head: { refWidth: '100%', stroke: 'transparent', height: 28, fill: 'rgb(95,149,255)' }, image: { 'xlink:href': 'https://gw.alipayobjects.com/zos/antfincdn/FLrTNDvlna/antv.png', height: 16, x: 6, y: 6 }, title: { text: 'Node', refX: 30, refY: 9, fill: '#ffffff', fontSize: 12, 'text-anchor': 'start' }, text: { text: 'this is content text', refX: 8, refY: 45, fontSize: 12, fill: 'rgba(0,0,0,0.6)', 'text-anchor': 'start' } }, markup: [ { tagName: 'rect', selector: 'body' }, { tagName: 'rect', selector: 'head' }, { tagName: 'image', selector: 'image' }, { tagName: 'text', selector: 'title' }, { tagName: 'text', selector: 'text' } ], ports: { ...basicPorts } }) export const FlowChartAnimateText = Graph.registerNode('flow-chart-animate-text', { inherit: 'rect', width: 200, height: 60, attrs: { body: { stroke: '#5F95FF', strokeWidth: 1, fill: 'rgba(95,149,255,0.05)' }, text1: { class: 'animate-text1', text: 'AntV X6', fontSize: 32 }, text2: { class: 'animate-text2', text: 'AntV X6', fontSize: 32 } }, markup: [ { tagName: 'rect', selector: 'body' }, { tagName: 'text', selector: 'text1' }, { tagName: 'text', selector: 'text2' } ] }) // 自定义 系统设计图 export const FlowChartImageRectCustom = Graph.registerNode('flow-chart-image-rect-custom', { inherit: 'rect', width: 80, height: 80, markup: [ { tagName: 'rect', selector: 'body' }, { tagName: 'image' }, { tagName: 'text', selector: 'label' } ], attrs: { body: { // 节点线的颜色 stroke: 'transparent', // 背景填充色 fill: 'transparent' }, // 自定义图片 image: { width: 60, height: 60, refX: 0, refY: 0 }, label: { refX: 3, refY: 2, textAnchor: 'left', textVerticalAnchor: 'top', fontSize: 12, fill: 'black' }, text: { fontSize: 12, fill: '#080808' } }, ports: { ...customPorts } }) // 节点组 export class NodeGroup extends Node { collapsed = true postprocess() { this.toggleCollapse(true) } isCollapsed() { return this.collapsed } toggleCollapse(collapsed?: boolean) { const target = collapsed == null ? !this.collapsed : collapsed if (target) { this.attr('buttonSign', { d: 'M 1 5 9 5 M 5 1 5 9' }) this.resize(200, 40) } else { this.attr('buttonSign', { d: 'M 2 5 8 5' }) this.resize(240, 240) } this.collapsed = target } } NodeGroup.config({ shape: 'rect', markup: [ { tagName: 'rect', selector: 'body' }, { tagName: 'image', selector: 'image' }, { tagName: 'text', selector: 'text' }, { tagName: 'g', selector: 'buttonGroup', children: [ { tagName: 'rect', selector: 'button', attrs: { 'pointer-events': 'visiblePainted' } }, { tagName: 'path', selector: 'buttonSign', attrs: { fill: 'none', 'pointer-events': 'none' } } ] } ], attrs: { body: { refWidth: '100%', refHeight: '100%', strokeWidth: 1, fill: 'rgba(95,149,255,0.05)', stroke: '#5F95FF' }, image: { 'xlink:href': 'https://gw.alipayobjects.com/mdn/rms_0b51a4/afts/img/A*X4e0TrDsEiIAAAAAAAAAAAAAARQnAQ', width: 16, height: 16, x: 8, y: 12 }, text: { fontSize: 12, fill: 'rgba(0,0,0,0.85)', refX: 30, refY: 15 }, buttonGroup: { refX: '100%', refX2: -25, refY: 13 }, button: { height: 14, width: 16, rx: 2, ry: 2, fill: '#f5f5f5', stroke: '#ccc', cursor: 'pointer', event: 'node:collapse' }, buttonSign: { refX: 3, refY: 2, stroke: '#808080' } } }) Graph.registerNode('groupNode', NodeGroup)