Vue.js 使用AntV X6的示例步驟
0x0 前言
因?yàn)轫?xiàng)目用到流程圖,并且需求也算是不詳細(xì),所以選擇比較靈活的 x6 圖形編輯器作為流程圖編輯器,從文檔來看不算復(fù)雜,這邊就是作為參考教程。
0x1 安裝
根據(jù)教程提示安裝 x6 依賴即可,然后新建個(gè)容器進(jìn)行實(shí)例化:
<div ref="containerRef" class="area-center-container" />
const data = {
// 節(jié)點(diǎn)
nodes: [
{
id: 'node1', // String,可選,節(jié)點(diǎn)的唯一標(biāo)識(shí)
x: 40, // Number,必選,節(jié)點(diǎn)位置的 x 值
y: 40, // Number,必選,節(jié)點(diǎn)位置的 y 值
width: 80, // Number,可選,節(jié)點(diǎn)大小的 width 值
height: 40, // Number,可選,節(jié)點(diǎn)大小的 height 值
label: 'hello', // String,節(jié)點(diǎn)標(biāo)簽
},
{
id: 'node2', // String,節(jié)點(diǎn)的唯一標(biāo)識(shí)
x: 160, // Number,必選,節(jié)點(diǎn)位置的 x 值
y: 180, // Number,必選,節(jié)點(diǎn)位置的 y 值
width: 80, // Number,可選,節(jié)點(diǎn)大小的 width 值
height: 40, // Number,可選,節(jié)點(diǎn)大小的 height 值
label: 'world', // String,節(jié)點(diǎn)標(biāo)簽
},
],
// 邊
edges: [
{
source: 'node1', // String,必須,起始節(jié)點(diǎn) id
target: 'node2', // String,必須,目標(biāo)節(jié)點(diǎn) id
},
],
}
function initGraph() {
const graph = new Graph({
container: this.$refs.containerRef,
grid: {
size: 10, // 網(wǎng)格大小 10px
visible: true // 渲染網(wǎng)格背景
},
snapline: {
enabled: true, // 對(duì)齊線
sharp: true
},
scroller: {
enabled: true,
pageVisible: false,
pageBreak: false,
pannable: true
}
})
// 畫布居中
graph.centerContent()
graph.fromJSON(data)
}
就這樣最簡(jiǎn)單例子實(shí)現(xiàn)了,上面不同的參數(shù)請(qǐng)參考文檔對(duì)應(yīng)的解釋。
0x2 節(jié)點(diǎn)側(cè)邊欄
根據(jù)文檔的 stencil 例子,可以簡(jiǎn)化很多代碼量,直接用封裝好的業(yè)務(wù)就行了,和上面一樣直接寫個(gè)容器實(shí)例化即可:
<el-aside ref="stencilRef" class="area-left" />
this.stencil = new Stencil({
title: '流程節(jié)點(diǎn)側(cè)邊欄',
target: graph,
search: false,
collapsable: true,
stencilGraphWidth: this.$refs.stencilRef.$el.clientWidth,
stencilGraphHeight: this.$refs.stencilRef.$el.clientHeight,
groups: [
{
name: 'group',
title: '流程圖節(jié)點(diǎn)',
collapsable: false
}
],
getDropNode: node => {
let cloneNode = node.clone()
switch (node.shape) {
case 'rect':
cloneNode = new RectShape()
break
case 'circle':
cloneNode = new CircleShape()
break
case 'polygon':
cloneNode = new PolylineShape()
break
}
cloneNode.updateInPorts(graph)
return cloneNode
}
})
// 加載節(jié)點(diǎn)
this.stencil.load([new Rect(rectInfo), new Circle(circleInfo), new Polygon(polygonInfo)], 'group')
0x3 整合例子
在線:https://codesandbox.io/s/icy-meadow-rqihx

以上就是Vue.js 使用Antv X6的示例步驟的詳細(xì)內(nèi)容,更多關(guān)于Vue.js 使用 Antv X6的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
解決打包后出現(xiàn)錯(cuò)誤y.a.addRoute is not a function的
這篇文章主要介紹了解決打包后出現(xiàn)y.a.addRoute is not a function的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10
Vue3實(shí)戰(zhàn)學(xué)習(xí)配置使用vue?router路由步驟示例
這篇文章主要為大家介紹了Vue3實(shí)戰(zhàn)學(xué)習(xí)配置使用vue?router路由步驟示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06
vue.js獲取數(shù)據(jù)庫數(shù)據(jù)實(shí)例代碼
本篇文章主要介紹了vue.js獲取數(shù)據(jù)庫數(shù)據(jù)實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-05-05
vue3.x使用swiperUI動(dòng)態(tài)加載圖片失敗的解決方法
這篇文章主要為大家詳細(xì)介紹了vue3.x使用swiperUI動(dòng)態(tài)加載圖片失敗的解決方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07
VUE table表格動(dòng)態(tài)添加一列數(shù)據(jù),新增的這些數(shù)據(jù)不可以編輯(v-model綁定的數(shù)據(jù)不能實(shí)時(shí)更新)
這篇文章主要介紹了VUE table表格動(dòng)態(tài)添加一列數(shù)據(jù),新增的這些數(shù)據(jù)不可以編輯(v-model綁定的數(shù)據(jù)不能實(shí)時(shí)更新),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2020-04-04

