当前位置: 首页 > news >正文

初探G6, 切换数据时保证图位置不变

 const data = {
  nodes: [{
    id: '收集日志',
    label: 'aaa',
  }, {
    id: '入 es 集群',
    label: 'bbb',
  }, {
    id: '入 hdfs',
    label: 'ccc',
  }, {
    id: 'hive 计算',
    label: 'ddd',
  }, {
    id: 'report',
    label: 'eee',
  }],
  edges: [{
    source: '收集日志',
    target: '入 es 集群'
  }, {
    source: '收集日志',
    target: '入 hdfs'
  }, {
    source: '入 hdfs',
    target: 'hive 计算'
  }, {
    source: '入 es 集群',
    target: 'hive 计算'
  }, {
    source: 'hive 计算',
    target: 'report'
  }]
};
       const datas = {
  nodes: [{
    id: '收集日志',
    label: 111,
  }, {
    id: '入 es 集群',
    label: 222,
  }, {
    id: '入 hdfs',
    label: 333,
  }, {
    id: 'hive 计算',
    label: 444,
  }, {
    id: 'report',
    label: 555,
  }],
  edges: [{
    source: '收集日志',
    target: '入 es 集群'
  }, {
    source: '收集日志',
    target: '入 hdfs'
  }, {
    source: '入 hdfs',
    target: 'hive 计算'
  }, {
    source: '入 es 集群',
    target: 'hive 计算'
  }, {
    source: 'hive 计算',
    target: 'report'
  }]
};
class IntroCard extends React.Component {
  constructor(props) {
        super(props);
        this.state = {
            showImage: true,
        };
        this.graph = null;
    }
  componentDidMount() {
      this.rendeG6(data);
    }
    rendeG6 = (data) => {
  this.graph= new G6.Graph({
  container: 'mountNode',
  // fitView: 'cc',
  height: window.innerHeight, // 画布高
  plugins: [new G6.Plugins['layout.dagre']()],
  defaultIntersectBox: 'rect' // 使用矩形包围盒
});

this.graph.node({
  shape: 'rect',
  label: function label(model) {
    return model.label;
  },

  style: {
    stroke: '#00C0A5',
    fill: '#92949F',
    fillOpacity: 0.45,
    lineWidth: 2
  }
});
this.graph.edge({
  style: {
    endArrow: true
  }
});
      let lastPoint = 0;
        this.graph.on('drag', (ev) => {
          this.graph.css({
            cursor: 'pointer',
          });
          if (lastPoint) {
            this.graph.translate(ev.domX - lastPoint.x, ev.domY - lastPoint.y);
          }
          lastPoint = {
            x: ev.domX,
            y: ev.domY,
          };
        });
        this.graph.on('dragend', () => {
          this.graph.css({
            cursor: 'default',
          });
          lastPoint = undefined;
        });
this.graph.read(data);
    }
    onload = () => {
      this.graph.read(datas);
    }
    onback = () => {
       this.graph.read(data);
    }
  render() {
    return (
      <div>
        <button onClick={this.onload}>切换数据</button>
        <button onClick={this.onback}>元数据</button>
        <div id="mountNode"></div>
       </div>
    )
  }

};
复制代码

codepen地址

转载于:https://juejin.im/post/5c1a0f3ce51d45255514a24d

相关文章:

  • 常见div+css网页布局(float,absolute)
  • 用PyTorch创建一个图像分类器?So easy!(Part 1)
  • 【Leetcode】Path Sum II
  • docker学习笔记
  • 3、开启debug调试模式
  • 为什么BAT公司使用微服务架构,资深架构师来告诉你原因!
  • mysql学习【第4篇】:数据库之数据类型
  • python字典操作总结
  • hadoop Hive(9)
  • 启动和测试oracle是否安装成功
  • Java初始化顺序
  • linux 生成随机密码
  • 线程创建
  • 测者的测试技术手册:智能化测试框架EvoSuite的一个坑以及填坑方法
  • cookie和session
  • 《Javascript高级程序设计 (第三版)》第五章 引用类型
  • 2018天猫双11|这就是阿里云!不止有新技术,更有温暖的社会力量
  • electron原来这么简单----打包你的react、VUE桌面应用程序
  • Js基础——数据类型之Null和Undefined
  • Linux中的硬链接与软链接
  • node 版本过低
  • PhantomJS 安装
  • Redis中的lru算法实现
  • 创建一种深思熟虑的文化
  • 从 Android Sample ApiDemos 中学习 android.animation API 的用法
  • 当SetTimeout遇到了字符串
  • 思否第一天
  • 机器人开始自主学习,是人类福祉,还是定时炸弹? ...
  • 如何通过报表单元格右键控制报表跳转到不同链接地址 ...
  • 数据库巡检项
  • ​MPV,汽车产品里一个特殊品类的进化过程
  • ###C语言程序设计-----C语言学习(3)#
  • ( 10 )MySQL中的外键
  • (04)odoo视图操作
  • (14)目标检测_SSD训练代码基于pytorch搭建代码
  • (js)循环条件满足时终止循环
  • (附源码)spring boot球鞋文化交流论坛 毕业设计 141436
  • (附源码)springboot金融新闻信息服务系统 毕业设计651450
  • (附源码)springboot掌上博客系统 毕业设计063131
  • (剑指Offer)面试题41:和为s的连续正数序列
  • (接口自动化)Python3操作MySQL数据库
  • (一)Spring Cloud 直击微服务作用、架构应用、hystrix降级
  • (转) Face-Resources
  • ****** 二十三 ******、软设笔记【数据库】-数据操作-常用关系操作、关系运算
  • **登录+JWT+异常处理+拦截器+ThreadLocal-开发思想与代码实现**
  • .bat批处理(二):%0 %1——给批处理脚本传递参数
  • .NET WebClient 类下载部分文件会错误?可能是解压缩的锅
  • .net 流——流的类型体系简单介绍
  • .NET 命令行参数包含应用程序路径吗?
  • .net 提取注释生成API文档 帮助文档
  • .NET 中让 Task 支持带超时的异步等待
  • .NET/ASP.NETMVC 深入剖析 Model元数据、HtmlHelper、自定义模板、模板的装饰者模式(二)...
  • .net访问oracle数据库性能问题
  • .NET企业级应用架构设计系列之结尾篇
  • .net与java建立WebService再互相调用