1.使用
通过使用antd-pro封装好的流程编辑器修改,如图:
![图片[1]-流程编辑器](https://liush.top/wp-content/uploads/2022/06/OH_9EZYO9I_VN0F8ISTJ-1024x515.png)
2.自定义节点和边
2.1自定义边
注意:这里需要graph属性注册边形状,不然无法自定义,如下面代码,属性参考文档
<Col span={16} className={styles.editorContent}>
<Flow className={styles.flow} graph={{
edgeDefaultShape: 'custom-edge',
}}/>
<CustomEdge/>
<CustomNode/>
</Col>
import React from "react";
import { RegisterEdge} from "gg-editor";
class CustomEdge extends React.Component {
render() {
const config = {
getStyle(item) {
const model = item.getModel();
const { color, size } = model;
return {
stroke: color || "#A3B1BF",
lineWidth: size
};
},
getAnchorStyle() {
return {
stroke: '#ff0'
}
}
};
return (
<RegisterEdge name="custom-edge" config={config} extend={"flow-smooth"} />
);
}
}
export default CustomEdge;
2.2自定义边的箭头
const config = {
getStyle(item) {
const model = item.getModel();
const {color, size} = model;
return {
startArrow: false,
endArrow: true, // 结束箭头是否显示
};
},
endArrow: {
// 箭头路径
path(item) {
const keyShape = item.getKeyShape();
let lineWidth = keyShape.attr('lineWidth');
lineWidth = lineWidth > MIN_ARROW_SIZE ? lineWidth : MIN_ARROW_SIZE;
const width = lineWidth * 10 / 3;
const halfHeight = lineWidth * 4 / 3;
const radius = lineWidth * 4;
return [
[ 'M', -width, halfHeight ],
[ 'L', 0, 0 ],
[ 'L', -width, -halfHeight ],
[ 'A', radius, radius, 0, 0, 1, -width, halfHeight ],
[ 'Z' ]
];
},
shorten(item) {
const keyShape = item.getKeyShape();
const lineWidth = keyShape.attr('lineWidth');
return (lineWidth > MIN_ARROW_SIZE ? lineWidth : MIN_ARROW_SIZE) * 3.1;
},
style(item) {
const keyShape = item.getKeyShape();
const { strokeOpacity, stroke } = keyShape.attr();
return {
fillOpacity: strokeOpacity,
fill: '#0099CC' // 箭头颜色
};
}
}
};
2.3自定义节点
import React from "react";
import { RegisterNode } from "gg-editor";
class CustomNode extends React.Component {
render() {
const config = {
draw(item) {
const keyShape = this.drawKeyShape(item);
// 绘制图标
const group = item.getGraphicGroup();
group.addShape("text", {
attrs: {
x: -15,
y: -25,
width: 30,
height: 30,
}
});
// 绘制标签
this.drawLabel(item);
return keyShape;
},
anchor: [
// [0.5,1],
// [0, 0.5],
// [0.5, 0],
// [1,0.5],
// 上边中点
]
};
return (
<RegisterNode name="dispatch-node" config={config} extend={"flow-capsule"} />
);
}
}
export default CustomNode;
3.问题汇总
3.1无法注册边的问题?
就是注册的边没有先自定义,查看如上自定义边可以解决
3.2箭头无法显示的问题?
就是注册边时候没有启动箭头显示
3.3如何让画布变成只读模式?
panBlank:点击节点不会触发,panCanvas:点击节点会触发节点
const graphConfig = {
edgeDefaultShape: ['custom-edge'],
mode: "readOnly",
modes: {
readOnly: ["clickNodeSelected", "wheelChangeViewport", "keydownMoveSelection", "hoverNodeActived", "panBlank", "clickExpandedButton", "hoverButton", "clickCanvasSelected"]
}
}
<Flow graph={graphConfig}/>
4.相关组件推荐
4.1ggEditor(v2)
介绍:基于 G6 和 React 的可视化图编辑器,不推荐使用 ,因为很久未维护,推荐x6或者 G6
有关文档:
https://www.yuque.com/blueju/gg-editor/ueldgh
https://www.yuque.com/antv/g6/custom-edge(记得查看v2版本)
4.2Butterfly
地址:Butterfly
介绍:一个基于JS的数据驱动的节点式编排组件库
© 版权声明
本站网络名称:
柳杉前端
本站永久网址:
https://liush.top
网站侵权说明:
本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长QQ715207475删除处理。
1 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
2 本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
3 本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
1 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
2 本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
3 本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
THE END
暂无评论内容