import React from 'react';
import {message} from 'antd'
import vis from 'vis';
import {api as http} from '../../fetch';
let relation = { nodes: [], edges: [] }; //设置关联图的数据(nodes为节点、edges为关联线)
const visDate={ //后端返回的数据格式
nodes:[
{
image:IconDomain,
label:'域名',
size:25,
id:1,
},
{
image:IconDomain,
label:'域名',
size:25,
id:2,
}
],edges:[
{
arrows:'to',
from:'1',
to:'2'
}
]
};
class Vis extends React.Component{
constructor(props) {
super(props);
this.state = {
relation: { nodes: [], edges: [] },
nodeheight:window.screen.height-326 //设置关联图高度为浏览器的高低减去顶部的高度
};
};
componentDidMount(){
this.props.onRef(this)
let nodeheight=window.screen.height-326;
this.setnode()
}
setnode=(url,name)=>{ //请求后端接口
http.get(url,{params:{name:name}})
.then(response=>{
if(response.code===1){
response.data.nodes.map((val,index)=>{
val.image=IconDomain;
val.is_root?val.size=70:val.size=150;
})
visDate.nodes=response.data.nodes
visDate.edges=response.data.organ
let container = document.getElementById("graph");
relation = { nodes: new vis.DataSet(), edges: new vis.DataSet() };
let data = this.findNode(visDate);
let option = {
// autoResize: true,
width: '100%',
height: this.state.nodeheight+'px',
nodes: {
shape: 'box',
// shape: 'image',
level:11,
font: {
size: 18,
color: 'red',
// margin:100
},
borderWidth: 2,
// widthConstraint:{
// minimum:150,
// maximum:150
// },
widthConstraint:150, //设置节点的宽度,超出换行
fixed:false, //设置节点固定,如果为真,则节点不会沿X方向移动
mass:2,
chosen:false,
labelHighlightBold:false
// margin:10
// physics: true,
},
edges: {
smooth: {
enabled: false, //设置线是否可弯曲
type: 'dynamic'
},
color: "#fff",
arrows: {
to: {
scaleFactor: 0.6 //箭头大小
}
}
},
layout:{
randomSeed:1,//配置每次生成的节点位置都一样,参数为数字1、2等
// hierarchical: {
// direction: 'UD',//UD:上下 DU:下上 LR:左右 RL:右左
// sortMethod: 'directed'
// }, //层级结构显示}
},
physics: {
enabled: true, //节点不能重叠,整体图回弹效果
solver: 'forceAtlas2Based',
barnesHut: {
gravitationalConstant: -4000,
centralGravity: 0.3,
springLength: 120,
springConstant: 0.04,
damping: 0.09,
avoidOverlap: 0
}
},
interaction: {
hover: true,//鼠标移过后加粗该节点和连接线
// dragNodes:false,//是否能拖动节点
selectable:false,//是否可以点击选择
hover:false,
// chosen:false,
// labelHighlightBold:false
}
};
let network = new vis.Network(container, data, option);
}else{
message.error(response.msg)
}
}).catch(error=>{
console.log(error)
})
}
findNode = (data, name) => { //根据名称调用后端接口根据自己的业务来
data.nodes.map((value, index) => {
relation.nodes.update({
chosen:false,
widthConstraint:value.size,
id: value.id,
// image: value.image,
label: value.label,
size: value.size,
// level:Number(index),
shape:value.is_root?'circle':'box'}); //区分根节点和普通节点,根节点为圆形,普通节点为长方形
return relation
});
relation.edges.update(data.edges);
return relation
};
render(){
return(
<div style={{display:'flex'}}>
<div id="graph" style={{justifyContent:'center',width:'100%'}}>
</div>
</div>
)
}
}
export default Vis;
- 在react中使用intro.js的的一些经验
react逐渐热了起来,但是新的东西毕竟前辈的经验少一些,前段时间自己在react中用到intro.js时,得到的资料甚少,摸索后便将一些心得记录下来了~ 1 intro.js的引入,这一点请看上一篇 ...
- React中jsx调用js例子
需求: 界面新增一个“导入项目”按钮,点击该按钮可以执行项目导入功能.按钮点击事件部分是jsx语法代码,而项目导入部分是封装的js语法代码,假设此处用alert("123")代替. ...
- Three.js 快速上手以及在 React 中运用[转]
https://juejin.im/post/5ca22692f265da30a53d6656 github 的地址 欢迎 star! 之前项目中用到了 3D 模型演示的问题,整理了一下之前学习总结以 ...
- 在 React Native 中使用 moment.js 無法載入語系檔案
moment.js 是很常見的日期時間 library,友善的 API 與極佳的執行效率是它的兩大賣點.例如 (new Date()).getFullYear(),如果使用 moment.js 我可以 ...
- vis.js没有中文文档,个人在项目中总结的一些中文配置
##vis.js var options = { nodes:{//节点配置 borderWidth: 1,//节点边框的宽度,单位为px borderWidthSelected: 2,节点被选中时边 ...
- Vis.js图表插件
Vis.js是一款基于JavaScript的可视化图表库,Vis.js不像其他的图表库那样仅仅支持几种常用的数据图表,比如线形图.柱状图.饼图等,Vis.js支持上百种不同类型的可视化图表类型,比如时 ...
- Immutable 详解及 React 中实践
本文转自:https://github.com/camsong/blog/issues/3 Shared mutable state is the root of all evil(共享的可变状态是万 ...
- React中使用CSSTransitionGroup插件实现轮播图
动画效果,是一个页面上必不可少的功能,学习一个新的东西,当然就要学习,如何用新的东西,用它的方法去实现以前的东西啦.今天呢,我就在这里介绍一个试用react-addons-css-transition ...
- 在React中使用Redux
这是Webpack+React系列配置过程记录的第六篇.其他内容请参考: 第一篇:使用webpack.babel.react.antdesign配置单页面应用开发环境 第二篇:使用react-rout ...
随机推荐
- [转] JS中的call()方法和apply()方法用法总结
//例1 <script> window.color = 'red'; document.color = 'yellow'; var s1 = {color: 'blue' }; func ...
- js实现回到顶部操作
<a href="javascript:;" id="btn" title="回到顶部"></a> 样式: #btn ...
- io.lettuce.core.RedisCommandTimeoutException: Command timed out
遇到的情况是 redis timeout时间设置过短(我设置成0了),默认多少也查不到
- UOJ#440. 【NOIP2018】填数游戏 动态规划
原文链接www.cnblogs.com/zhouzhendong/p/UOJ440.html 前言 菜鸡选手到省选了才做联赛题. 题解 首先我们分析一下性质: 1. 假如一个格子是 0,那么它的右上角 ...
- MyBatis sqlsession 简化 使用工具类创建
2019-04-09 @Test public void Test() throws Exception { // 1.读取配置文件 String resource = "mybatis-c ...
- UIImagePickerController照片选取器
记录于2013/7/4 加入框架: MobileCoreServices.framework MediaPlayer.framework 导入头文件: #import <MediaP ...
- echarts中的区域缩放组件dataZoom,主动触发选区缩放点击事件
options设置 toolbox: { // 工具栏 feature: { dataZoom : { // 选时间缩放功能 show : true, // show为true时,才能触发takeGl ...
- Android应用程序支持不同屏幕(尺寸、密度)
how to build a user interface using Android layouts for all types of devices 使用Android布局设计的UI接口用于不同的 ...
- Linux Kernel C语言编程范式
介绍 不同的编程语言具有不同的抽象原语(如下),有的原语抽象层次低,有的原语抽象层次高.其中函数式.DSL是这几年十分热门的编程语言概念. 过程式抽象原语:变量 对象式抽象原语:对象 函数式抽象原语: ...
- springmvc ajax tomcat简单配置实现跨域访问
发现一种改动最小也能实现跨域请求的方法 服务端 服务端修改web.xml配置文件, 增加过滤器 (不用导入任何jar包, 用的tomcat自带jar) <!-- 支持跨域请求 --> &l ...