Code Monkey home page Code Monkey logo

x-flowchart-vue's Introduction

X-Flowchart-Vue

A visual graph editor based on G6 and Vue.

Version License NPM downloads Downloads GitHub issues GitHub closed issues GitHub repo size GitHub code size in bytes Lines of code GitHub Sponsors

预览

online

示例

# git clone https://github.com/OXOYO/X-Flowchart-Vue.git

# install dependencies
yarn install

### run dev
yarn run serve

功能

功能 默认启用 快捷键 工具栏 右键菜单 备注
logo Logo
undo ctrl + z 撤销
clearLog ctrl + shift + l 清空操作日志
history ctrl + shift + h 操作日志
redo ctrl + shift + z 重做
copy ctrl + c 复制
paste ctrl + v 粘贴
delete Delete 删除
clear ctrl + shift + c 清空画布
zoom 缩放
zoomIn ctrl + + 放大
zoomOut ctrl + - 缩小
fit ctrl + 0 适应屏幕
actualSize ctrl + 1 实际大小
canvasBackground 画布背景
fill 填充颜色
lineColor 线条颜色
lineWidth 线条宽度
lineDash 线条样式
lineType 线条类型
startArrow 起点
endArrow 终点
toFront 置于顶层
toBack 置于底层
selectAll ctrl + a 全选
edit 编辑模式
preview 预览模式
upload 上传
download 下载
fullscreen 全屏
language 语言
github Github
feedback 反馈
help 帮助
up up
down down
left left
right right

使用指南

起步

安装

npm i @oxoyo/xfc --save

引用

import xfc from '@oxoyo/xfc'
import '@oxoyo/xfc/dist/xfc.css'

// 初始化
const xfcEditor = xfc({
    el: '#xfc'
})

配置

在初始化 xfc 实例时,可以配置参数。

props

参数 说明 类型 可选值 默认值
tools 全量配置工具项,覆写系统默认工具项信息,详见全量配置tools Object - -
enableTools 【与tools互斥,配置后以此为主】设置要启用的系统工具项 Array - -
disableTools 【与tools、enableTools互斥,配置后以此为主】设置要禁用的系统工具项 Array - -
shortcutMap 【与tools互斥,配置后以此为主】设置自带的工具项的快捷键 Object - -
materials 全量配置物料列表,覆写系统默认物料,详见全量配置materials Array - -
enableMaterials 【与materials互斥,配置后以此为主】设置要启用的系统物料 Object - -
system 配置系统信息 Object - -
storage 配置本地存储信息 Object - -
i18n 配置多语言 Object - -
infoPanel 信息面板配置 Object - -

tools

全量配置工具项,覆写系统默认工具项信息,自定义程度高,无非必要不建议配置此项

tools数据结构 tools 下可以设置 toolListshortcutMap

xfc({
  el: '#xfc',
  props: {
    tools: {
      toolList: [...],
      shortcutMap: {...}
    }
  }
})

tools.toolList下单个工具配置字段说明:

{
      // 工具项名称,保持唯一性,便于区分工具项
      name: 'logo',
      // 文本,无lang时可取label值显示
      label: 'logo',
      // 多语言code码
      lang: 'L10000',
      // 工具项类型,不同的工具类型在ToolBar、ContextMenu里的表现不一样
      type: 'link',
      // 工具项图标
      icon: '',
      img: system.logo,
      // 跳转连接
      link: system.site,
      // 是否启用该工具项,用户控制是否启用该工具项
      enableTool: true,
      // 是否启用,用于动态控制是否在界面上创建该工具项
      enable: true,
      // 启用模式,用于控制在什么模式下启用该工具项
      enableMode: ['edit', 'preview'],
      // 是否禁用,用于控制界面上已创建的工具项是否处于禁用状态
      disabled: false,
      // 禁用模式,用于控制在什么模式下该工具项处于禁用状态,详见Editor/Index.vue 中的doSetMode方法
      disabledMode: ['edit', 'preview'],
      // 热键
      shortcuts: '',
      // 工具栏
      toolbar: {
        // 是否启用
        enable: true,
        // 位置
        position: 'left',
        // 样式
        style: {
          opacity: 1
        },
        // 分割线,是否在该工具项后显示分割线,ToolBar中为竖线,ContextMenu中为横线
        divider: false
      },
      // 右键菜单
      contextmenu: {
        // 是否启用
        enable: false,
        // 目标元素类型,用于控制在什么元素上可以显示该工具项
        target: [],
        style: {},
        // 分割线,是否在该工具项后显示分割线,ToolBar中为竖线,ContextMenu中为横线
        divider: false
      }
    }

tools.shortcutMap下单个工具配置字段说明:

shortcutMap: {
  // 工具名
  undo: {
    // 工具名 
    tool: 'undo',
    // 快捷键
    key: 'mod+z',
    // 快捷键文本
    label: 'Ctrl + Z',
    // 快捷键描述
    description: '' 
  }
}

enableTools

【与tools互斥,配置后以此为主】设置要启用的工具项。

xfc({
  el: '#xfc',
  props: {
    enableTools: [
      // 日志相关
      'undo',
      'clearLog',
      'history',
      'redo',
      // 复制、粘贴
      'copy',
      'paste',
      // 删除
      'delete',
      // 清空画布
      'clear',
      // 缩放
      'zoom',
      'zoomIn',
      'zoomOut',
      'fit',
      'actualSize',
      // 画布背景
      'canvasBackground',
      // 元素基本操作
      'fill',
      'lineColor',
      'lineWidth',
      'lineDash',
      'lineType',
      'startArrow',
      'endArrow',
      'toFront',
      'toBack',
      'selectAll',
      'marquee',
      'group',
      'ungroup',
      'edit',
      'preview',
      'upload',
      'download',
      'layout',
      'fullscreen',
      'language',
      'github',
      'feedback',
      'help',
      // 纯快捷键
      'up',
      'down',
      'left',
      'right'
    ]
  }
})

disableTools

【与tools、enableTools互斥,配置后以此为主】设置要禁用的系统工具项

xfc({
  el: '#xfc',
  props: {
    'logo',
    'language',
    'help'
  }
})

shortcutMap

【与tools互斥,配置后以此为主】设置自带的工具项的快捷键

xfc({
  el: '#xfc',
  props: {
    shortcutMap: {
      // 工具名
      undo: {
        // 工具名 
        tool: 'undo',
        // 快捷键
        key: 'mod+z',
        // 快捷键文本
        label: 'Ctrl + Z',
        // 快捷键描述
        description: '' 
      }
    }
  }
})

materials

全量配置物料列表,覆写系统默认物料,自定义程度高,无非必要不建议配置此项

xfc({
  el: '#xfc',
  props: {
    materials: [
        ...
    ]
  }
})

enableMaterials

【与materials互斥,配置后以此为主】设置要启用的系统物料

xfc({
  el: '#xfc',
  props: {
    enableMaterials: {
        // 启用的物料分类
        general: [
            // 启用的分类下图形
            'rectangle', 
            'rounded-rectangle'
        ]  
    }
  }
})

system

配置系统信息

xfc({
  el: '#xfc',
  props: {
    system: {
        version: '1.0.0',
        name: 'xfc',
        author: 'OXOYO',
        description: 'A visual graph editor based on G6 and Vue.',
        title: 'XFC',
        logo: require('@/assets/images/logo.png'),
        github: 'https://github.com/OXOYO/X-Flowchart-Vue',
        site: 'http://oxoyo.co/X-Flowchart-Vue/',
        feedback: 'https://github.com/OXOYO/X-Flowchart-Vue/issues/new',
        copyright: '©2019 - 2020 OXOYO All Rights Reserved.'
    }
  }
})

storage

配置本地存储信息

xfc({
  el: '#xfc',
  props: {
    storage: {
        // 本地存储前缀
        prefix: 'xfc'
    }
  }
})

i18n

配置多语言

xfc({
  el: '#xfc',
  props: {
    i18n: {
        // 默认语言包
        defLocale: 'zh-CN',
        // 自定义语音包或覆写系统语音包
        locales: {
            ...
        }
    }
  }
})

infoPanel

配置信息面板

xfc({
  el: '#xfc',
  props: {
    infoPanel: {
        // 配置信息
        options: {
            enable: true
        },
        // 导航器
        navigator: {
            enable: true,
            // minimap插件配置
            config: {
                type: 'delegate',
                delegateStyle: {
                    fill: '#ffffff',
                    stroke: '#000000'
                }
            }
        }
    }
  }
})

API

read (data, isActualSize)

接收数据,并进行渲染。

参数

名称 类型 是否必选 描述
data Object true 初始化的图数据,是一个包括 nodes 和 edges 的对象

用法

const data = {
  nodes: [
    {
      id: 'node1',
      label: 'node1',
    },
    {
      id: 'node2',
      label: 'node2',
    },
  ],
  edges: [
    {
      source: 'node1',
      target: 'node2',
    },
  ],
};

xfcEditor.read(data)

save()

获取图数据。

该方法无参数。

返回值

  • 返回值类型:Object;
  • 返回值包括所有节点和边,数据结构如下下所示:
{
    nodes: [],
    edges: []
}

用法

xfcEditor.save()

getNodes()

获取图中所有节点的实例。

⚠️ 注意: 这里返回的是节点的实例,而不是节点的数据项。

返回值

  • 返回值类型:Array;
  • 返回值表示图中所有节点的实例。

用法

const nodes = xfcEditor.getNodes()

getEdges()

获取图中所有边的实例。

⚠️ 注意: 这里返回的是边的实例,而不是边的数据项。

返回值

  • 返回值类型:Array;
  • 返回值表示图中所有边的实例。

用法

const edges = xfcEditor.getEdges()

downloadImage (name, type, backgroundColor)

将画布上的元素导出为图片。

参数

名称 类型 是否必选 描述
name String false 图片的名称,不指定则为 'graph'
type 'image/png' / 'image/jpeg' / 'image/webp' / 'image/bmp' false 图片的类型。图的 renderer 为默认的 'canvas' 时生效,图的 renderer'svg' 时将导出 svg 文件
backgroundColor String false 图片的背景色,可选,不传值时将导出透明背景的图片

用法

xfcEditor.downloadImage()

toDataURL (type, backgroundColor)

将画布上元素生成为图片的 URL。

参数

名称 类型 是否必选 描述
type 'image/png' / 'image/jpeg' / 'image/webp' / 'image/bmp' false 图片的类型。图的 renderer 为默认的 'canvas' 时生效,图的 renderer'svg' 时将导出 svg 文件
backgroundColor String false 图片的背景色,可选,不传值时将导出透明背景的图片

返回值

  • 返回值类型:String;
  • 返回值表示生成的图片的 URL。

用法

const dataURL = xfcEditor.toDataURL()

Reference

@antvis/g6

@alibaba/GGEditor

@guozhaolong/wfd

grapheditor

Thank

guozhaolong

Contribution

我们目前接受 GitHub Pull Request ,并且所有开发提交的合并均通过 Pull Request 进行,故你可以直接点击该项目的 Fork 按钮得到你自己的 Fork ,在其上进行提交,并在修改完毕后直接通过 GitHub 网页发起 Pull Request 即可。对于 Pull Request 的介绍和使用方式,可以参阅 GitHub 帮助文档中的 “关于 Pull Request” 部分

感谢所有为此项目做出贡献的人们!

curiosity-hyf

lzygit18

License

MIT

Copyright (c) 2019-present, OXOYO

Contact

点击链接加入群【Web全栈QQ群 333765077】:https://jq.qq.com/?_wv=1027&k=53iWbrr

Star History

Stargazers over time

x-flowchart-vue's People

Contributors

curiosity-hyf avatar lzygit18 avatar oxoyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

x-flowchart-vue's Issues

大佬 啥时在更新一版啊

buglist 的 bug依然很多,而且都是比较关键的bug,例如,撤回、上传json、写入文字就卡顿等等

在Editor的index.vue中引入G6出现的问题

大神,您好!我在尝试将您的组件嵌入我自己的项目的时候,出现了一些问题。
当我在Editor文件夹下的index.vue里import G6 from '@/global/g6/index'时,此时代码运行会出现
‘Model parse failed:Unexpected token
You may need an appropriate loader to handle this file type
return{rotate:rad,...result}’
我一开始以为是babel-loader版本落后的原因,将其更新至8.0.0后,仍然出现这种情况,而注释掉import G6 from '@/global/g6/index’代码就能正常运行,我想问一下,引入这个封装的包的时候是否要安装别的loader,或是改其他的配置文件。

master分支版本 关于自定义图片迷惑的地方

1.gif

上面的情况,是使用源代码,添加节点类型为图片的 不能正常展示

但是如果把 createNode 方法中的 style 属性删除掉 就是正常的,很疑惑这部分渲染跟图片有神魔关系吗

【谁在使用】

如果您和您的的公司或组织正在使用 XFC,非常感谢您的支持,希望可以在这里留下您的公司信息。您的回复将成为维护者、社区用户和观望者的信心来源。
回复格式示例如下:

公司或组织:OXOYO
链接:http://oxoyo.co/X-Flowchart-Vue/

方便的话,可以晒一晒截图
无关回复将会定期删除

怎么自定义节点

我想用iconfont上的图标作为节点,但是path是这样的
image
怎么才能弄成这样的:
image

撤销 重做 清空操作日志BUG

1 撤销时 会出现清空画布的情况
重现方式:添加一个node节点,清空操作日志,再添加一个node节点,撤销,两个都不见了
2 清空操作日志
清空操作日志,应该清空操作记录,但是需要保留当前画布内容,并且不可撤销
3 撤销 和 重做 使用时 容易出现错乱
操作5条记录后,撤销2条记录,在操作一条记录(这个记录应该先清除撤销的两条,在家这一条(第条))

升级到G6最新版本3.5.3后,绘制锚点方法报错问题。

目前在学习使用G6,大佬的项目功能强大,但是使用版本较老,G6更新较快,后续版本较3.1版本有变化。在将项目升级至3.5.3版本后,解决了运行报错,成功启动项目,但是拖动图标至画布时,图标的锚点计算方法报错( shape.isPointInPath is not a function,将渲染方式改为svg后,可以出现锚点,但锚点显示有问题),未升级前尝试新增了几个svg图标,新增图标在画布中不绘制锚点,也不响应事件。看关闭的issue,大佬有更新G6版本的计划,想请教下怎么解决这些问题。

【资料】

基础库

flowchart.js Draws simple SVG flow chart diagrams from textual

GoJS JavaScript diagramming library for interactive flowcharts, org charts, design tools, planning tools, visual languages.

jointjs Create Flowchart, BPMN and many other unique diagramming editors with ease.

jsplumb Visual connectivity for webapps

bpmn-js A BPMN 2.0 rendering toolkit and web modeler.

mxGraph

D3

kityminder

实现

Topology 乐吾乐Topology - 基于开源的免费可视化绘图工具

@antv/G6最佳实践

资料

mxgraph 架构分析与 mxgraph-editor 编辑器开发

X6-Editor 架构脑图

交流

temp_qrcode_share_333765077
temp_qrcode_share_737234848
b5cb0579-65c8-4720-980d-16db244e4092
image

求更新

作者你好,我觉得你的东西很好,但是那个demo好像不能用,能更新下吗?谢谢啦

是否有办法画出父子关系?

是否有办法做出元素中包含元素的图,父元素拖动的时候子元素会一起动,如果需要修改代码的话是否有办法?

辅助网格错位

image
1920*1080
chrome 版本 87.0.4280.88(正式版本) (64 位)

image
jin'yong禁用g6的inset后正常

【v4.x讨论区】

经过很长一段时间的蛰伏,决定重启迭代计划。欢迎大家讨论。。。

目标:

阶段一:
1.底层库替换,@antv/G6 => @antv/X6。
2.配置优化,从新设计的自定义配置实现。
3.扩展设计,支持自定义图形。
4.数据结构优化,结构数据与描述数据分离。

阶段二:
1.vue2 升级 vue3

鼠标拖动 node 的速度如果太快,导致鼠标先离开了 node 区域,会导致拖动过程终止

重现方式:

  1. 鼠标拖动一个 node
  2. 快速移动鼠标
  3. 会发现 node 停止在了中间位置,而且拖动过程停止了

很多时候鼠标的移动速度比系统处理 mousemove 的速度要快,所以快速拖动的时候,鼠标指针会瞬间离开 node 所在的区域范围。

如果把拖动事件的处理,挂在更上层的 html 元素上,是不是可以解决快速拖动过程中断的问题。

【需求收集】

如果你有什么好的想法、好的实现、需要的功能欢迎在此记录,我们会在综合评估后在未来的迭代中实现。

已收集需求:

自定义节点为图片时,图片的大小不能拉伸或者缩小

Q:节点/边更新时,没有按照在 nodeDefinition 中自定义实现的 draw 或 drawShape 逻辑更新。例如,有些图形没有被更新,增加了没有在 draw 或 drawShape 方法中定义的图形等。
A:由于继承了 extendedTypeName,且在 nodeDefinition 中没有复写 update 方法,导致节点/边更新时执行了 extendedTypeName 中的 update 方法,从而与自定义的 draw 或 drawShape 有出入。可以通过复写 update 方法为 undefined 解决。当 update 方法为 undefined 时,节点/边的更新将会执行 draw 或 drawShape 进行重绘。

文字

有操作图形内文字的API吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.