UNPKG

ingenious-flow-designer

Version:

[演示地址](http://antd-vben5-pro.madong.tech/)

129 lines (115 loc) 3.48 kB
import { GraphModel, h, DiamondNode, DiamondNodeModel } from "@logicflow/core"; import { ColorEnum, NodeStateEnum } from "../types/enums"; class ForkModel extends DiamondNodeModel { constructor(data: any, graphModel: GraphModel) { super(data, graphModel); } setAttributes(): void { this.text.value = ""; this.text.draggable = false; this.text.editable = false; const baseSize = 48; if (this.properties._width) { this.rx = this.properties._width / 2; this.ry = this.properties._width / 2; } else if (this.properties._height) { this.rx = this.properties._height / 2; this.ry = this.properties._height / 2; } else { this.rx = baseSize / 2; this.ry = baseSize / 2; } if (this.properties._stroke) { this.properties.stroke = this.properties._stroke; } if (this.properties._fill) { this.properties.fill = this.properties._fill; } if (this.properties._strokeWidth) { this.properties.strokeWidth = this.properties._strokeWidth; } if (this.properties._opacity) { this.properties.opacity = this.properties._opacity; } } getNodeStyle() { const style = super.getNodeStyle(); const state = this.properties.state; if(state === NodeStateEnum.history) { style.stroke = ColorEnum.historyColor; style.fill = `${ColorEnum.historyColor}10`; } else if(state === NodeStateEnum.active) { style.stroke = ColorEnum.activeColor; style.fill = `${ColorEnum.activeColor}10`; } else if(state === NodeStateEnum.error) { style.stroke = ColorEnum.errorColor; style.fill = `${ColorEnum.errorColor}10`; } else { style.stroke = ColorEnum.primaryColor; style.fill = `${ColorEnum.primaryColor}10`; } if (this.properties._stroke) { style.stroke = this.properties._stroke; } if (this.properties._fill) { style.fill = this.properties._fill; } if (this.properties._strokeWidth) { style.strokeWidth = this.properties._strokeWidth; } if (this.properties._opacity !== undefined) { style.opacity = this.properties._opacity; } return style; } } class ForkView extends DiamondNode { private getForkIcon() { const { model } = this.props; const { x, y } = model; const style = model.getNodeStyle(); const iconSize = 16; const halfSize = iconSize / 2; const thickness = 2; return h("g", {}, [ h("line", { x1: x - halfSize, y1: y, x2: x + halfSize, y2: y, stroke: style.stroke, strokeWidth: thickness, strokeLinecap: "round" }), h("line", { x1: x, y1: y - halfSize, x2: x, y2: y + halfSize, stroke: style.stroke, strokeWidth: thickness, strokeLinecap: "round" }) ]); } getResizeShape() { const { model } = this.props; const { x, y, width, height } = model; const style = model.getNodeStyle(); return h("g", {}, [ h("path", { ...style, d: `M ${x} ${y - height/2} L ${x + width/2} ${y} L ${x} ${y + height/2} L ${x - width/2} ${y} Z` }), this.getForkIcon() ]); } getShape() { return this.getResizeShape(); } } export default { type: "fork", view: ForkView, model: ForkModel, };