IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> JavaScript知识库 -> @antv/x6、@antv/x6-react-components X6 图编辑引擎在 react typescript 项目中实践 -> 正文阅读

[JavaScript知识库]@antv/x6、@antv/x6-react-components X6 图编辑引擎在 react typescript 项目中实践

X6 图编辑引擎

X6 是 AntV 旗下的图编辑引擎,提供了一系列开箱即用的交互组件和简单易用的节点定制能力,方便我们快速搭建 DAG 图、ER 图、流程图等应用。

说明文档:https://x6.antv.vision/zh/docs/tutorial/about

?

源码

import React, { useEffect, useState } from 'react'
import './index.scss'
import { GithubOutlined, UserOutlined } from '@ant-design/icons'
import ToolBar from './components/ToolBar'
import RightDrawer from './components/RightDrawer'
import FlowGraph from './Graph'
import { useHistory } from 'react-router-dom'

const Index = () => {
  const history = useHistory();
  const [ isReady, setIsReady ] = useState(false) // 是否初始化完成,渲染 toolbar
  const [ isRightDrawer, setIsRightDrawer ] = useState(false)
  const [ selectCell, setSelectCell ] = useState({})

  useEffect(() => {
    const graph = FlowGraph.init()
    setIsReady(true)

    // 节点选中事件
    graph.on('selection:changed', (args) => {
      args.added.forEach((cell: any) => {
        const shape = cell.store.data.shape

        if (shape !== 'edge') {
          setSelectCell(cell)
          setIsRightDrawer(true)
        }
      })
    })
    graph.on('blank:click', () => {
      setIsRightDrawer(false)
    })

    const resizeFn = () => {
      const { width, height } = getContainerSize()
      graph.resize(width, height)
    }
    resizeFn()

    window.addEventListener('resize', resizeFn)
    return () => {
      window.removeEventListener('resize', resizeFn)
    }
  }, [])

  const getContainerSize = () => {
    return {
      width: document.body.offsetWidth - 214,
      height: document.body.offsetHeight - 95,
    }
  }

  const openGithub = () => {
    window.open(
      'https://www.ifrontend.net/',
      '_blank',
    )
  }

  const openUser = () => {
    history.push('/about')
  }

  const closeRightDrawer = () => {
    setIsRightDrawer(false)
  }

  return (
    <div className="antv-x6">
      <div className="header">
        <span className="txt">React-AntvX6-App</span>
        <span className="icon">
          <UserOutlined onClick={openUser} title="关于我们"></UserOutlined>
          <GithubOutlined onClick={openGithub} title="Github"></GithubOutlined>
        </span>
      </div>
      <div className="toolbar">
        {isReady && <ToolBar />}
      </div>
      {isRightDrawer && <RightDrawer selectCell={selectCell} close={closeRightDrawer} />}
      <div className="content">
        <div id="stencil" className="shapes"></div>
        <div id="container"></div>
        <div id="minimap" className="minimap"></div>
      </div>
    </div>
  )
}

export default Index

详细Github地址 :https://gitee.com/tangweiwei/vue-antvx6-app

前端开发那点事

微信公众号搜索“前端开发那点事”

  JavaScript知识库 最新文章
ES6的相关知识点
react 函数式组件 & react其他一些总结
Vue基础超详细
前端JS也可以连点成线(Vue中运用 AntVG6)
Vue事件处理的基本使用
Vue后台项目的记录 (一)
前后端分离vue跨域,devServer配置proxy代理
TypeScript
初识vuex
vue项目安装包指令收集
上一篇文章      下一篇文章      查看所有文章
加:2021-07-29 11:32:24  更:2021-07-29 11:33:03 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/9 0:13:37-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码