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


Posted in Javascript onAugust 07, 2019

vis.js  网站

https://visjs.org/

vs  code 下安装命令

npm install vis-network

在vue  下引入 vis-network组件

const vis = require("vis-network/dist/vis-network.min.js");
require("vis-network/dist/vis-network.min.css");

例子代码使用

let DIR = "/jtopo/";
let nodes = [
{ id: 1, shape: "circularImage", image: DIR + "server.png" },
{ id: 2, shape: "circularImage", image: DIR + "server.png" },
{ id: 3, shape: "circularImage", image: DIR + "server.png" },
{
id: 4,
shape: "circularImage",
image: DIR + "gather.png",
label: "pictures by this guy!"
},
{ id: 5, shape: "circularImage", image: DIR + "wanjet.png" },
{ id: 6, shape: "circularImage", image: DIR + "center.png" },
{ id: 7, shape: "circularImage", image: DIR + "cloud.png" },
{ id: 8, shape: "circularImage", image: DIR + "center.png" },
{ id: 9, shape: "circularImage", image: DIR + "wanjet.png" },
{ id: 10, shape: "circularImage", image: DIR + "gather.png" }
// { id: 11, shape: "circularImage", image: DIR + "11.png" },
// { id: 12, shape: "circularImage", image: DIR + "12.png" },
// { id: 13, shape: "circularImage", image: DIR + "13.png" },
// { id: 14, shape: "circularImage", image: DIR + "14.png" },
// {
// id: 15,
// shape: "circularImage",
// image: DIR + "missing.png",
// brokenImage: DIR + "missingBrokenImage.png",
// label: "when images\nfail\nto load"
// },
// {
// id: 16,
// shape: "circularImage",
// image: DIR + "anotherMissing.png",
// brokenImage: DIR + "9.png",
// 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;
nodes.push({
id: num,
label: num.toString()
});
edges.push({ from: num, to: 10 });
}
let data = {
nodes: nodes,
edges: edges
};
let container = document.getElementById("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节点
}
};
that.network = new vis.Network(container, data, options);
that.network.on("click", function(params) {});

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

总结

以上所述是小编给大家介绍的vue 集成 vis-network 实现网络拓扑图的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

Javascript 相关文章推荐
jQuery Ajax使用 全解析
Dec 15 Javascript
jQuery图片滚动图片的效果(另类实现)
Jun 02 Javascript
javascript学习笔记(一)基础知识
Sep 30 Javascript
jQuery Masonry瀑布流插件使用详解
Nov 17 Javascript
jquery选择器需要注意的问题
Nov 26 Javascript
JavaScript中的关联数组问题
Mar 04 Javascript
JavaScript实现点击按钮就复制当前网址
Dec 14 Javascript
通过BootStrap实现轮播图的实际应用
Sep 26 Javascript
基于 Vue 实现一个酷炫的 menu插件
Nov 14 Javascript
Vue项目添加动态浏览器头部title的方法
Jul 11 Javascript
用JS实现一个简单的打砖块游戏
Dec 11 Javascript
通过vue刷新左侧菜单栏操作
Aug 06 Javascript
弱类型语言javascript开发中的一些坑实例小结【变量、函数、数组、对象、作用域等】
Aug 07 #Javascript
JS中getElementsByClassName与classList兼容性问题解决方案分析
Aug 07 #Javascript
javascript for循环性能测试示例
Aug 07 #Javascript
弱类型语言javascript中 a,b 的运算实例小结
Aug 07 #Javascript
解决一个微信号同时支持多个环境网页授权问题
Aug 07 #Javascript
vue+element项目中过滤输入框特殊字符小结
Aug 07 #Javascript
Vue.js项目实战之多语种网站的功能实现(租车)
Aug 07 #Javascript
You might like
全国FM电台频率大全 - 15 山东省
2020/03/11 无线电
php实现把数组按指定的个数分隔
2014/02/17 PHP
PHP使用GIFEncoder类处理gif图片实例
2014/07/01 PHP
php命令行(cli)模式下报require 加载路径错误的解决方法
2015/11/23 PHP
PHP排序算法之简单选择排序(Simple Selection Sort)实例分析
2018/04/20 PHP
php 使用 __call实现重载功能示例
2019/11/18 PHP
ASP.NET中AJAX 调用实例代码
2012/05/03 Javascript
jquery select动态加载选择(兼容各种浏览器)
2013/02/01 Javascript
javascript实现2048游戏示例
2014/05/04 Javascript
jQuery事件绑定on()、bind()与delegate() 方法详解
2015/06/03 Javascript
javascript实现查找数组中最大值方法汇总
2016/02/13 Javascript
详解JavaScript中数组和字符串的lastIndexOf()方法使用
2016/03/13 Javascript
Ubuntu 16.04 64位中搭建Node.js开发环境教程
2016/10/19 Javascript
浅谈jQuery中的$.extend方法来扩展JSON对象
2017/02/12 Javascript
nodeJS实现简单网页爬虫功能的实例(分享)
2017/06/08 NodeJs
jQuery实现视频展示效果
2020/05/30 jQuery
vue 在methods中调用mounted的实现操作
2020/08/07 Javascript
[01:57]2018年度DOTA2最具潜力解说-完美盛典
2018/12/16 DOTA
Python基于pygame实现的font游戏字体(附源码)
2015/11/11 Python
python多进程控制学习小结
2018/10/31 Python
python利用ffmpeg进行录制屏幕的方法
2019/01/10 Python
情人节快乐! python绘制漂亮玫瑰
2020/08/18 Python
解决pycharm 远程调试 上传 helpers 卡住的问题
2019/06/27 Python
python从list列表中选出一个数和其对应的坐标方法
2019/07/20 Python
Python实现序列化及csv文件读取
2020/01/19 Python
python 工具 字符串转numpy浮点数组的实现
2020/03/14 Python
使用Python pip怎么升级pip
2020/08/11 Python
华为c/c++笔试题
2016/01/25 面试题
如何整合JQuery和Prototype
2014/01/31 面试题
电气技术员岗位职责
2013/11/19 职场文书
参观监狱心得体会
2014/01/02 职场文书
应届生自荐书
2014/06/23 职场文书
学校感恩教育活动总结
2014/07/07 职场文书
语文教师求职信范文
2015/03/20 职场文书
2015年业务工作总结范文
2015/04/10 职场文书
mysql的单列多值存储实例详解
2022/04/05 MySQL