GithubHelp home page GithubHelp logo

seeksdream / relation-graph Goto Github PK

View Code? Open in Web Editor NEW
1.8K 12.0 481.0 14.81 MB

relation-graph is a relationship graph display component that supports Vue2, Vue3, React. Allowing you to fully customize the graphical elements using HTML/CSS and Vue or React components through slots. 支持Vue和React的 关联关系图谱组件,可以展示如组织机构图谱、股权架构图谱、集团关系图谱等知识图谱,可提供多种图谱布局,包括树状布局、中心布局、力学布局自动布局等。

Home Page: https://relation-graph.com

License: MIT License

JavaScript 0.26% Vue 23.27% HTML 0.31% TypeScript 72.69% SCSS 3.31% Shell 0.14% CSS 0.01%
graph relationship-graph vue vue3 react

relation-graph's Introduction

relation-graph

  • relation-graph 是支持Vue2、Vue3、React的关系数据展示组件,支持通过【插槽】让使用者使用"普通HTML元素、Vue组件、React组件"来完全自定义图形元素,并提供实用的API接口让使用者轻松构建可交互的图形应用。
  • 除了典型的关系数据展示功能,relation-graph还支持作为一个画板来使用,你可以在画板上放置任何内容,只需要为想要连接的元素设置id,同时定义"元素连线(Element Lines)"即可。轻松实现一个可任意创建连线、可缩放与拖动、支持通过API轻松实现动态交互的画板。
  • relation-graph is a relationship data display component that supports Vue 2, Vue 3, and React. It enables users to fully customize graphical elements using "common HTML elements, Vue components, React components" through slots, and provides practical API interfaces to facilitate the development of interactive graphical applications."
  • In addition to the typical relationship data display functionality, the relation-graph also supports being used as a drawing board. You can place any content on the drawing board, simply by setting an id for the elements you want to connect, and defining "element lines." This allows for the easy creation of a drawing board that supports the creation of arbitrary connections, zooming and dragging, and dynamic interactions through the API.

Docs & Examples 文档 & 示例:

上面的网站中包含使用文档、在线示例,以及可视化的配置工具。
The website above includes documentation, online demos, and a visual configuration tool for software developers.

Getting Started 快速使用:

npm install --save relation-graph
# 注意:relation-graph支持Vue2、Vue3、React, 引入的包名称都是"relation-graph" 但在使用时,根据你的环境,需要引入不同的名称
# Note: relation-graph supports Vue2, Vue3, React, but the package name for import is always "relation-graph".
# 
# Vue2: import RelationGraph from 'relation-graph'
# Vue3: import RelationGraph from 'relation-graph/vue3'
# React: import RelationGraph from 'relation-graph/react'
<template>
  <div>
    <div style="height:calc(100vh - 60px);"><!-- The size of the parent element determines the size of the graph. -->
      <RelationGraph
              ref="graphRef"
              :options="graphOptions"
              :on-node-click="onNodeClick"
              :on-line-click="onLineClick"
      />
    </div>
  </div>
</template>

<script>
// relation-graph also supports usage in the main.js file with Vue.use(RelationGraph); this way, you don't need the following line of code for import.
import RelationGraph from 'relation-graph'
export default {
  name: 'Demo',
  components: { RelationGraph },
  data() {
    return {
      graphOptions: {
        defaultJunctionPoint: 'border'
        // Here you can refer to the options in "Graph" for setting: 
        // https://www.relation-graph.com/#/docs/graph
        // You can also use this GUI tool to generate configuration content.
        // https://www.relation-graph.com/#/options-tools
      }
    }
  },
  mounted() {
    this.showGraph()
  },
  methods: {
    showGraph() {
      const jsonData = {
        rootId: 'a',
        nodes: [
          // You can also use slots directly without defining these cumbersome attributes and use CSS styles to define the appearance of your nodes.
          // Example of using slots: https://www.relation-graph.com/#/demo/node-style
          { id: 'a', text: 'A', borderColor: 'yellow' },
          { id: 'b', text: 'B', color: '#43a2f1', fontColor: 'yellow' },
          { id: 'c', text: 'C', nodeShape: 1, width: 80, height: 60 },
          { id: 'e', text: 'E', nodeShape: 0, width: 150, height: 150 }
        ],
        lines: [
          { from: 'a', to: 'b', text: 'line1', color: '#43a2f1' },
          { from: 'a', to: 'c', text: 'line2' },
          { from: 'a', to: 'e', text: 'line3' },
          { from: 'b', to: 'e', color: '#67C23A' }
        ]
      }
      // The node and line in the above data can refer to the options in "Node" and "Link & Line" for configuration.
      // Node: https://www.relation-graph.com/#/docs/node
      // Link & Line: https://www.relation-graph.com/#/docs/link

      this.$refs.graphRef.setJsonData(jsonData, (graphInstance) => {
        // Called when the relation-graph is completed
      });
      // The this.refs.graphRef.setJsonData(jsonData, callback) method is a convenient method that is equivalent to the following code:
      //  const graphInstance = this.refs.graphRef.getInstance();
      //  graphInstance.addNodes(jsonData.nodes);
      //  graphInstance.addLines(jsonData.lines);
      //  graphInstance.rootNode = graphInstance.getNodeById(jsonData.rootId);
      //  await graphInstance.doLayout(); // Layout using the layouter set in graphOptions
      //  await graphInstance.moveToCenter(); // Find the center based on node distribution and center the view
      //  await graphInstance.zoomToFit(); // Zoom to fit, so that all nodes can be displayed in the visible area
    },
    onNodeClick(nodeObject, $event) {
      console.log('onNodeClick:', nodeObject)
    },
    onLineClick(lineObject, $event) {
      console.log('onLineClick:', lineObject)
    }
  }
}
</script>

Sample code effects 上面代码的效果:

简单示例效果图

Example Projects 完整的示例代码:

More Examples 更多示例:

relation-graph

center-层级距离设置 力学布局(force) 节点展开/收缩的用法 节点筛选 & 关系筛选 节点/连线点击效果2 展开/收缩 时动画效果 展开/关闭所有 布局切换事件

The complete sample project 完整的、可运行的示例项目:

More info 更多效果及使用方法:

Contact me 与我联系:

  • 我的QQ:3235808353

  • My WhatsApp:

relation-graph's People

Contributors

192114 avatar corelli359 avatar flybooks avatar seeksdream avatar thoughtworks-caihu avatar tianbiao avatar zhangshuo1991 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

relation-graph's Issues

mac 上 zoom 的方向很奇怪

https://github.com/seeksdream/relation-graph/blob/master/src/index.vue#L425-L436

目前是

向上滚动:放大
双指拉开:缩小

https://github.com/seeksdream/relation-graph/blob/master/src/index.vue#L431 这一行的 1-1 交换位置(其实就是不需要对 mac 特殊对待),则会

向上滚动:缩小
双指拉开:放大

上下滚动 到底是缩小还是放大,它区别不明显,但是 双指拉开 这种 用户期望的肯定是 放大。所以似乎根本不应该对 mac 做特殊处理。

存在无关联节点时 节点重叠的变通修复方法

如题, 例如有1-10个节点, 1->2, 2->3, 1->4->5->6, 7,8,9 无关联. 此时会有节点重叠.
变通修复的方法就是添加一个节点0, 然后0->1, 0->7, 0->8, 0->9, 所有没有父节点的节点都以0为父节点. 然后隐藏0节点以及延申出来的连接线即可.
PS: 这个 issue 欠了好久了, 年底太忙了.

图加载之后links丢失from和to字段

this.$refs.seeksRelationGraph.setJsonData(graph, (seeksRGGraph) => {
// 这些写上当图谱初始化完成后需要执行的代码
});
执行上述代码之后打印图的数据
console.log(this.$refs.seeksRelationGraph.getGraphJsonData());

结果links丢失from和to字段
image

是我用法不对吗?

开发建议

因为看到目前已经可以实现了拖拽的效果,但是还不能更改子节点与父节点、子节点与子节点的关系,无法改变to、from的对象
另外,无法在配置里设置渲染结构的百分比,比如我想一打开就是70%大小展示(虽然可以缩放,但是有的时候图太大,一上来显示完整的要好一些)

相同的数据节点会变少

第一次进入页面正常,第二次进入的时候
节点数据会变少
image
需要布局的节点数量: 7
与第一个比数量减少

将数据使用axios会报错

我将渲染之后的graph_json_data数据,使用axios请求,会报错
image
,我排查了下是nodes的数据会引起报错,可以看下这是什么问题吗

如何设置树状图的初始布局居中?

现在初始化时是这样的
image
但我希望所有节点能够自动居中,排列整齐
image
大致是变成这样
另外还想请问下,树状图层级之间的间距可以设置吗?比如我希望两层之间可以更加紧凑一些

自动布局force拖拽

自动布局force拖拽,过几秒拖拽动画效果消失了,这个这么设置的呢

not supported for VUE3?

使用vue3 按照文档导入了组件,页面就变空白了,报错:Uncaught (in promise) TypeError: selfHook.bind is not a function

请问是不支持vue3吗

双向树

双向树中,设置线 isReverse: false 或 true 对箭头无影响

节点名称没有渲染

image

如图,节点名称没有。
代码就是官网上的“快速上手”那里的示例代码:
image

是我哪里配置错了吗?

多个子图时显示异常

在使用这个组件创建图谱时,当一张图中有两个互不连通的子图时,只有包含root节点的子图能够正常显示,其他的结点会全部重叠在左上角,如 1 to 2,3 to4 时,节点3和节点4会重叠,请问是否能通过设置多个Root节点,使用每一个root节点对应一个非联通子图的方式来解决?
微信图片_20210628180133

提供图形化操作界面

建议开发图形化操作界面,拖动创建节点和连线,自动生成数据。
类似百度脑图,非常感谢!!!

当只有根节点时,根节点快速闪现

当我收起根节点时,根节点的位置一直在闪烁不定,
const childNodes = this.currentNode.lot.childs || [] if (childNodes && childNodes.length) { childNodes.forEach(item => { item.isHide = true // 隐藏该节点的子节点,前提是该节点不需要从服务器获取子节点 // this.$refs.seeksRelationGraph.removeNodeById(item.id) }) }
收起自己写的,就是隐藏子节点

文档缺少 zoom() 方法

在源码里能找到 zoom 方法,也能调用,文档里却没有写 graph 对象下有 zoom 方法

线条的长度

连接节点的线条长度可以设置吗?怎么设置呢?

移动画布使画布上的某一点居中

看 graph 对象上有 文档中没有的 api : graph.animateGoto(x, y, time, callback) 以及 graph.animateToZoom(zoom, time, callback), 可是用它跟 节点的 xy 去做操作,怎么操作都不能让节点居中,不懂这个函数的逻辑。

有这个函数的使用讲解吗?还是说 relation-graph 不支持 移动画布使画布上的某一点居中 ?

npm install --save relation-graph

报错信息:
npm WARN saveError ENOENT: no such file or directory, open '/data/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/data/package.json'

树图如何初始自适应居中且自动调整Zoom使画布包含所有节点?

使用时遇到一些问题想请教,如下:
1.如何设置根节点初始化是自动居中?
2.如何初始化时自适应zoom使画布包含所有节点?
3.子节点展开或收起点击时,为了使节点布局正常,使用refresh()总是会重置画布,有没有优化方案,使点击子节点时节点重绘但不改变当前位置?

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.