vue 拓扑组件_vue 集成 vis-network 实现网络拓扑图的方法

时间:2025-04-25 07:30:17

  网站

vs  code 下安装命令

npm install vis-network

在vue  下引入 vis-network组件

const vis = require("vis-network/dist/");

require("vis-network/dist/");

例子代码使用

let dir = "/jtopo/";

let nodes = [

{ id: 1, shape: "circularimage", image: dir + "" },

{ id: 2, shape: "circularimage", image: dir + "" },

{ id: 3, shape: "circularimage", image: dir + "" },

{

id: 4,

shape: "circularimage",

image: dir + "",

label: "pictures by this guy!"

},

{ id: 5, shape: "circularimage", image: dir + "" },

{ id: 6, shape: "circularimage", image: dir + "" },

{ id: 7, shape: "circularimage", image: dir + "" },

{ id: 8, shape: "circularimage", image: dir + "" },

{ id: 9, shape: "circularimage", image: dir + "" },

{ id: 10, shape: "circularimage", image: dir + "" }

// { id: 11, shape: "circularimage", image: dir + "" },

// { id: 12, shape: "circularimage", image: dir + "" },

// { id: 13, shape: "circularimage", image: dir + "" },

// { id: 14, shape: "circularimage", image: dir + "" },

// {

// id: 15,

// shape: "circularimage",

// image: dir + "",

// brokenimage: dir + "",

// label: "when images\nfail\nto load"

// },

// {

// id: 16,

// shape: "circularimage",

// image: dir + "",

// brokenimage: dir + "",

// label: "fallback image in action"

// }

];

let edges = [

{ from: 1, to: 4 },

{ from: 2, to: 4 },

{ from: 3, to: 4 },

{ from: 4, to: 5 },

{ from: 5, to: 6 },

{ from: 6, to: 7 },

{ from: 8, to: 7 },

{ from: 9, to: 8 },

{ from: 10, to: 9 }

// { from: 8, to: 10 },

// { from: 10, to: 11 },

// { from: 11, to: 12 },

// { from: 12, to: 13 },

// { from: 13, to: 14 },

// { from: 9, to: 16 }

];

for (let i = 1; i <= 100; i++) {

num = i + 10;

({

id: num,

label: ()

});

({ from: num, to: 10 });

}

let data = {

nodes: nodes,

edges: edges

};

let container = ("mynetwork");

//let options = {};

let options = {

nodes: {

font: {

color: "white", //字体的颜色

size: 30 //显示字体大小

},

scaling: {

min: 16,

max: 32 //缩放效果比例

},

borderwidth: 0,

color: {

border: "white",

background: "white" //若是引用图标,背景颜色

}

},

groups: {

ws: {

//系统定义的形状 dot等 这些官网都可以找到

shape: "dot",

color: "white"

}

},

edges: {

//连接线的样式

color: {

color: "white",

highlight: "white",

hover: "#848484",

inherit: "from",

opacity: 1.0

}

},

layout: {

randomseed: 1 //配置每次生成的节点位置都一样,参数为数字1、2等

},

physics: {

// barneshut: { gravitationalconstant: -30000 },

barneshut: {

gravitationalconstant: -80000,

springconstant: 0.001,

springlength: 200

},

stabilization: false

//{ iterations: 2500 }

},

interaction: {

// navigationbuttons: true,

hover: true, //鼠标移过后加粗该节点和连接线

selectconnectededges: false, //选择节点后是否显示连接线

hoverconnectededges: false, //鼠标滑动节点后是否显示连接线

tooltipdelay: 200,

zoomview: true //是否能缩放画布

},

edges: {

shadow: true, //连接线阴影配置

smooth: true //是否显示方向箭头

// arrows: {to : true }//箭头指向from节点

}

};

= new (container, data, options);

("click", function(params) {});

设置 stabilization: false  可以快速生成10000个节点

总结

以上所述是小编给大家介绍的vue 集成 vis-network 实现网络拓扑图的方法,希望对大家有所帮助

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!