先在終端執(zhí)行命令
vue create relationgraph
創(chuàng)建一個(gè)vue2的項(xiàng)目
然后在編輯器中打開新創(chuàng)建的項(xiàng)目
在終端中執(zhí)行命令
npm install relation-graph --save
引入依賴
這樣 我們r(jià)elation-graph就進(jìn)來了
然后 我們?cè)谛枰褂玫慕M件中編寫代碼如下文章來源:http://www.zghlxwxcb.cn/news/detail-549467.html
<template>
<div>
<div style="width: calc(100% - 10px);height:100vh;">
<SeeksRelationGraph ref="seeksRelationGraph" :options="graphOptions" />
</div>
</div>
</template>
<script>
import SeeksRelationGraph from 'relation-graph';
export default {
name: 'SeeksRelationGraphDemo',
components: { SeeksRelationGraph },
data() {
return {
graphOptions: {
// debug: true,
// 禁用拖拽
disableDragNode: true,
// backgrounImage: 'http://ai-mark.cn/images/ai-mark-desc.png',
backgrounImageNoRepeat: true,
layouts: [
{
label: '多源化',
layoutName: 'tree',
layoutClassName: 'seeks-layout-center',
defaultJunctionPoint: 'border',
defaultNodeShape: 0,
defaultLineShape: 1,
from: 'left',
// 通過這4個(gè)屬性來調(diào)整 tree-層級(jí)距離&節(jié)點(diǎn)距離
min_per_width: '200',
max_per_width: '500',
// min_per_height: '40',
// max_per_height: '60',
// 如果此選項(xiàng)有值,則優(yōu)先級(jí)高于上面那4個(gè)選項(xiàng)
levelDistance: '',
},
],
// 箭頭樣式
defaultLineMarker: {
markerWidth: '0',
markerHeight: '0',
refX: '0',
refY: '0',
},
defaultExpandHolderPosition: 'right',
defaultNodeShape: 1,
defaultNodeWidth: '100', // 節(jié)點(diǎn)寬度
defaultLineShape: 4, //線條樣式
defaultJunctionPoint: 'lr',
defaultNodeBorderWidth: 0,
defaultLineColor: 'rgba(0, 186, 189, 1)',
defaultNodeColor: 'rgba(0, 206, 209, 1)',
}
};
},
mounted() {
this.setGraphData();
},
methods: {
setGraphData() {
var __graph_json_data = {
rootId: 'N1',
nodes: [
{ id: 'N1', text: '測(cè)試方案', color: '#2E4E8F' },
{ id: 'N15', text: '高級(jí)規(guī)劃', color: '#4ea2f0' },
{
id: 'N16',
color: '#4ea2f0',
html: `<div class="A">
<div class="A-1">高級(jí)測(cè)試管理方案</div>
<div class="A-2">映射工具</div>
</div>`,
},
{
id: 'N17',
text: '微化文案管理',
color: '#4ea2f0',
},
{ id: 'N18', text: '初級(jí)測(cè)試文案', color: '#4ea2f0' }
],
links: [
{ from: 'N1', to: 'N15' },
{ from: 'N15', to: 'N16' },
{ from: 'N15', to: 'N17' },
{ from: 'N15', to: 'N18' },
{ from: 'N15', to: 'N19' },
],
};
this.$refs.seeksRelationGraph.setJsonData(
__graph_json_data,
(seeksRGGraph) => {
console.log(seeksRGGraph);
}
);
},
},
};
</script>
<style>
</style>
這里 首先 大家要縷清關(guān)系 我們每個(gè)節(jié)點(diǎn)都帶有id 例如N1 N15
然后 我們?cè)O(shè)置根節(jié)點(diǎn)的id是N1
links梳理了元素之前的關(guān)系
N15 插入在N1 下 剩下的 N16 N17 N18 N19則插入在N15下
然后 我們可以通過
{ id: ‘唯一標(biāo)識(shí)’, text: ‘內(nèi)容文本’, color: ‘顏色代碼’ }
也可以通過
{ id: ‘唯一標(biāo)識(shí)’, html: ‘頁面結(jié)構(gòu)字符串’, color: ‘顏色代碼’ }
來完成
最后 我們運(yùn)行出來的效果是這樣的
右邊的操作了也都是可以用的 我們可以進(jìn)行放大 縮小 甚至下載到本地文章來源地址http://www.zghlxwxcb.cn/news/detail-549467.html
到了這里,關(guān)于vue+relation-graph繪制關(guān)系圖實(shí)用組件的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!