安装

npm install @antv/g6 --save

引用

import G6 from '@antv/g6'

自定义节点

/**
* 方式一
*/
G6.registerNode('rect-jsx', (cfg) =>`
<group>
<rect>
<rect style={{
width: 160,
height: 20,
fill: ${cfg.color},
cursor: 'move',
stroke: ${cfg.color}
}} draggable="true">
<text style={{
marginTop: 2,
marginLeft: 75,
textAlign: 'center',
fontWeight: 'bold',
fill: '#333' }}>自定义文字</text>
</rect>
<rect style={{
width: 160,
height: 55,
stroke: ${cfg.color},
fill: ${cfg.color},
}} draggable="true">
<text style={{ marginTop: 5, marginLeft: 3, fill: '#333', marginLeft: 4 }}> {{label}}</text>
<text style={{ marginTop: 10, marginLeft: 3, fill: '#333', marginLeft: 4 }}>{{statusDesc}}</text>
</rect>
</group>
`) /**
* 方式二
*/
G6.registerNode(
'card-node',
{
drawShape: function drawShape(cfg, group) {
const color = cfg.error ? '#F4664A' : '#30BF78';
const r = 2;
const shape = group.addShape('rect', {
attrs: {
x: 0,
y: 0,
width: 200,
height: 60,
stroke: color,
radius: r,
},
name: 'main-box',
draggable: true,
}); group.addShape('rect', {
attrs: {
x: 0,
y: 0,
width: 200,
height: 20,
fill: color,
radius: [r, r, 0, 0],
},
name: 'title-box',
draggable: true,
}); // left icon
group.addShape('image', {
attrs: {
x: 4,
y: 2,
height: 16,
width: 16,
cursor: 'pointer',
img: ICON_MAP[cfg.nodeType || 'app'],
},
name: 'node-icon',
}); // title text
group.addShape('text', {
attrs: {
textBaseline: 'top',
y: 2,
x: 24,
lineHeight: 20,
text: cfg.title,
fill: '#fff',
},
name: 'title',
}); if (cfg.nodeLevel > 0) {
group.addShape('marker', {
attrs: {
x: 184,
y: 30,
r: 6,
cursor: 'pointer',
symbol: cfg.collapse ? G6.Marker.expand : G6.Marker.collapse,
stroke: '#666',
lineWidth: 1,
},
name: 'collapse-icon',
});
} // The content list
cfg.panels.forEach((item, index) => {
// name text
group.addShape('text', {
attrs: {
textBaseline: 'top',
y: 25,
x: 24 + index * 60,
lineHeight: 20,
text: item.title,
fill: 'rgba(0,0,0, 0.4)',
},
name: `index-title-${index}`,
}); // value text
group.addShape('text', {
attrs: {
textBaseline: 'top',
y: 42,
x: 24 + index * 60,
lineHeight: 20,
text: item.value,
fill: '#595959',
},
name: `index-title-${index}`,
});
});
return shape;
},
},
'single-node',
);

绑定事件

   graph.on('aftercreateedge', e => {

    })

    graph.on('click', (evt) => {

    });

    graph.on('node:dblclick', evt => {

    })

连线控制

          {
type: 'create-edge',
trigger: 'click',
key: 'shift',
shouldBegin: e => {
this.setState({begin: e.item._cfg.id})
return true
},
shouldEnd: e => {
let flag = true
this.state.edges.forEach(item => {
if (this.state.begin === item.source) {
if (e.item._cfg.id === item.target) {
flag = false
}
}
})
return flag
}

根据坐标返回位置信息

      const { item } = evt
const model = item.getModel()
const { x, y } = model
const point = graph.getCanvasByPoint(x, y)

注意事项

在数据源多次变化时先需要销毁画布

this.graph.destroy()

详细的边文字、节点提示等等,官方文档介绍的很多,这里介绍React的简单实现,供大家少走弯路。官方链接:https://g6.antv.vision/zh

React使用AntV G6实现流程图的更多相关文章

  1. AntV G6绘制流程图学习例子

    下面代码可以直接贴到html文件中运行看效果. 代码说明 js中data是一个json变量,里面有两个关键对象"nodes.edges",分别来描述节点.节点间箭线. 更多&quo ...

  2. antV G6流程图在Vue中的使用

    最近我司项目中需要加入流程图制作功能,于是乎百度各种找可视化绘制拓扑图的轮子,大部分都是国外的,看文档太吃力,不过好在最终让我发现了AntV G6流程图图表库,最新版为2.0,不过编辑器在2.0版本还 ...

  3. React + umi +antd+antv/g6 实现力图

    官方示例效果:http://antv.alipay.com/zh-cn/g6/2.x/demo/net/2017-link-data.html 改编效果: 实现步骤: 环境:nodejs.yarn/n ...

  4. vue结合antV/g6 实现网络拓扑图

    最近很多业务场景都会需要用到拓扑图,翻找了很多资料,最后选择了antV/g6,主要原因有以下几点: 1.阿里出品,所以框架的成熟性有保障 2.业务场景契合(1.规则拓扑图:2.动画流向:每个节点会有流 ...

  5. antv g6

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  6. 在 React 项目中引入 GG-Editor 编辑可视化流程

    蚂蚁金服数据可视化团队曾经开源了一款G6-Editor,但后来停止了对外支持,学习成本太高 好在后来他们团队的大牛高力结合 React + G6 开源了一个 GG-Editor(其实就是G6-Edit ...

  7. G6 学习资料

    G6 学习资料 网址 G6 1.x API 文档 http://antvis.github.io/g6/doc/index.html 官方demo列表 https://github.com/antvi ...

  8. React 生命周期简介

       React 中组件的生命周期会经历如下三个过程:装载过程.更新过程.卸载过程. 装载过程:组件实例被创建和插入 DOM 树的过程: 更新过程:组件被重新渲染的过程: 卸载过程:组件从 DOM 树 ...

  9. ggEditor流程图增加网格背景

    参考官方文档: https://www.yuque.com/antv/g6/plugin.tool.grid react-ggEditor如何使用 import { Flow } from 'gg-e ...

随机推荐

  1. golang multiconfig 示例

    参考资料:https://github.com/koding/multiconfig 测试代码: package main import ( "fmt" "github. ...

  2. Go Channel 详解

    原文链接:Go Channel 详解 Channel类型 Channel类型的定义格式如下: ChannelType = ( "chan" | "chan" & ...

  3. 求X值问题

    这,其实是一道数学题,难就难在要把数学模型用编程语言实现,其中的规律如果看不出来就比较鸡肋,这类题可以算是智商题,做这类题千万不能紧张,血的教训. 题目描述 已知有整数x,x + 100为一个平方数. ...

  4. 焦大:seo思维光年(下)seo操作如何度量化

    http://www.wocaoseo.com/thread-57-1-1.html 如果不能度量就无法进行改进,所以度量化或数据化是网站分析和网站研究必须进行的一个方面,seo也不能例外.我在上篇文 ...

  5. React的几种组件

    一.函数组件 该函数在React中是一个有效的组件,可以接收唯一带有数据的props(代表属性)对象,并返回一个React元素.函数式组件要特别注意,组件名称首字母一定要大写.这种方式也成为无状态组件 ...

  6. 如何安装CRX格式?Chrome插件离线安装,CRX格式安装方法 JSON-handle Chrome插件下载

    目前,Chrome官方已经禁止非Chrome商店的应用安装了,所以本站的应用还是通过国外服务器从谷歌官方应用市场下载下来的,提供给国内的广大用户使用,下面我们就以 Check my cookies 插 ...

  7. Toast 响应点击事件

    import java.lang.reflect.Field; import android.content.Context; import android.util.Log; import andr ...

  8. python小白入门基础(二:变量)

    #变量:可以改变的量就是变量,实际上是由内存开辟的一块空间,临时存在内存中,以便后续代码使用.#作用:代指内存中某个地址中的内容. #1.变量的概念name = "王五"name ...

  9. mysql必知必会——GROUP BY和HAVING

    mysql必知必会——GROUP BY和HAVING 创建表结构 create table `employ_info` ( `id` int(11) NOT NULL AUTO_INCREMENT, ...

  10. Math Problem(数学)

    链接:https://ac.nowcoder.com/acm/contest/893/C来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K ...