前端关系图推荐-relation-graph

前端关系图推荐-relation-graph

目录

一、前言

二、relation-graph官网地址

三、推荐relation-graph的原因

四、relation-graph的使用

1.Vue2使用

1.1、安装relation-graph

1.2、 可直接复制到vue文件中运行使用

2. Vue3使用

2.1、安装relation-graph

2.2、 可直接复制到vue文件中运行使用

3. React使用

1.1、安装relation-graph

1.2、 可直接复制到文件中运行使用

五、运行结果

六、下面是运行成果图


一、前言

Relation-Graph是一个开源的免费关系图谱组件,支持Vue2、Vue3和React框架。它提供开箱即用的体验,配置简单,文档清晰,并支持通过插槽自定义节点样式。文章详细介绍了在Vue2、Vue3和React中的安装和使用方法,包含完整的代码示例和运行效果图。该组件具有高度可定制性,支持节点点击事件等交互功能,适用于构建各种关系图谱应用。作者强烈推荐该工具,并分享了实际项目中的使用效果。

二、relation-graph官网地址

relation-graph - A Relationship Graph Component

三、推荐relation-graph的原因

  1. 超级容易上手,基本开箱即用
  2. 官方文档清晰明了,有在线示例、可自定义配置,配置完可直接复制配置的代码
  3. 完全支持 VUE2、VUE3、React 三种框架
  4. 关系节点可通过插槽完全自定义定制
  5. 免费!!!免费!!!免费!!!

四、relation-graph的使用

1.Vue2使用

1.1、安装relation-graph

npm install --save relation-graph

1.2、 可直接复制到vue文件中运行使用

<template>    <div>      <div>         <RelationGraph ref="graphRef" :options="graphOptions" :on-node-click="onNodeClick" :on-line-click="onLineClick" />      </div>    </div>  </template>  <script> // relation-graph也支持在main.js文件中使用Vue.use(RelationGraph);这样,你就不需要下面这一行代码来引入了。  import RelationGraph from 'relation-graph'  export default {    name: 'Demo',    components: { RelationGraph },    data() {      return {        graphOptions: {          defaultJunctionPoint: 'border'          // 这里可以参考"Graph 图谱"中的参数进行设置 https://www.relation-graph.com/#/docs/graph        }      }    },    mounted() {      this.showGraph()    },    methods: {      showGraph() {        const jsonData = {          rootId: 'a',          nodes: [            { 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: '关系1', color: '#43a2f1' },            { from: 'a', to: 'c', text: '关系2' },            { from: 'a', to: 'e', text: '关系3' },            { from: 'b', to: 'e', color: '#67C23A' }          ]        }        // 以上数据中的node和link可以参考"Node节点"和"Link关系"中的参数进行配置        this.$refs.graphRef.setJsonData(jsonData, (graphInstance) => {          // Called when the relation-graph is completed        })      },      onNodeClick(nodeObject, $event) {        console.log('onNodeClick:', nodeObject)      },      onLineClick(lineObject, $event) {        console.log('onLineClick:', lineObject)      }    }  }  </script>

2. Vue3使用

2.1、安装relation-graph

npm install --save relation-graph-vue3

2.2、 可直接复制到vue文件中运行使用

<template>   <div>     <div>       <relation-graph ref="graphRef$" :options="options" />     </div>   </div> </template> <script setup lang="ts"> import { onMounted, ref } from 'vue' import RelationGraph from 'relation-graph-vue3' const graphRef$ = ref<RelationGraph>() const options = {   defaultExpandHolderPosition: 'right' } onMounted(() => {   const jsonData = {     rootId: 'a',     nodes: [       { id: 'a', text: 'a', },       { id: 'b', text: 'b', },       { id: 'c', text: 'c', },       { id: 'd', text: 'd', },       { id: 'e', text: 'e', },       { id: 'f', text: 'f', },     ],     lines: [       { from: 'a', to: 'b', },       { from: 'a', to: 'c', },       { from: 'a', to: 'd', },       { from: 'a', to: 'e', },       { from: 'a', to: 'f', },     ],   }   // 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   graphRef$.value.setJsonData(jsonData)   // The graphRef$.value.setJsonData(jsonData, callback) method is a convenient method that is equivalent to the following code:   //  const graphInstance = graphRef$.value.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 }) </script>

3. React使用

1.1、安装relation-graph

npm install --save relation-graph-react

1.2、 可直接复制到文件中运行使用

import React, { useEffect, useRef } from 'react'; import RelationGraph, {RelationGraphInstance} from 'relation-graph-react'; import type { MutableRefObject} from 'react'; import type {   RGLine,   RGLink,   RGNode,   RGNodeSlotProps,   RGOptions,   RelationGraphExpose } from 'relation-graph-react'; const staticJsonData = {   rootId: '2',   nodes: [     { id: '1', text: '节点-1', myicon: 'el-icon-star-on' },     { id: '2', text: '节点-2', myicon: 'el-icon-setting', width: 100, height: 100 },     { id: '3', text: '节点-3', myicon: 'el-icon-setting' },     { id: '4', text: '节点-4', myicon: 'el-icon-star-on' },     { id: '6', text: '节点-6', myicon: 'el-icon-setting' },     { id: '7', text: '节点-7', myicon: 'el-icon-setting' },     { id: '8', text: '节点-8', myicon: 'el-icon-star-on' },     { id: '9', text: '节点-9', myicon: 'el-icon-headset' },     { id: '71', text: '节点-71', myicon: 'el-icon-headset' },     { id: '72', text: '节点-72', myicon: 'el-icon-s-tools' },     { id: '73', text: '节点-73', myicon: 'el-icon-star-on' },     { id: '81', text: '节点-81', myicon: 'el-icon-s-promotion' },     { id: '82', text: '节点-82', myicon: 'el-icon-s-promotion' },     { id: '83', text: '节点-83', myicon: 'el-icon-star-on' },     { id: '84', text: '节点-84', myicon: 'el-icon-s-promotion' },     { id: '85', text: '节点-85', myicon: 'el-icon-sunny' },     { id: '91', text: '节点-91', myicon: 'el-icon-sunny' },     { id: '92', text: '节点-82', myicon: 'el-icon-sunny' },     { id: '5', text: '节点-5', myicon: 'el-icon-sunny' }   ],   lines: [     { from: '7', to: '71', text: '投资' },     { from: '7', to: '72', text: '投资' },     { from: '7', to: '73', text: '投资' },     { from: '8', to: '81', text: '投资' },     { from: '8', to: '82', text: '投资' },     { from: '8', to: '83', text: '投资' },     { from: '8', to: '84', text: '投资' },     { from: '8', to: '85', text: '投资' },     { from: '9', to: '91', text: '投资' },     { from: '9', to: '92', text: '投资' },     { from: '1', to: '2', text: '投资' },     { from: '3', to: '1', text: '高管' },     { from: '4', to: '2', text: '高管' },     { from: '6', to: '2', text: '高管' },     { from: '7', to: '2', text: '高管' },     { from: '8', to: '2', text: '高管' },     { from: '9', to: '2', text: '高管' },     { from: '1', to: '5', text: '投资' }   ] }; const NodeSlot: React.FC<RGNodeSlotProps> = ({node}) => {   console.log('NodeSlot:');   if (node.id === '2') { // if rootNode     return <div style={{zIndex: 555, opacity: 0.5, lineHeight:'100px', width: '100px', height: '100px', color: '#000000', borderRadius:'50%', boxSizing: 'border-box', fontSize: '18px', textAlign: 'center', overflow: 'hidden'}}>       <div style={{width: '100%', height: (node.data!.percent * 100) + '%', marginTop: ((1-node.data!.percent) * 100) + '%', background: 'linear-gradient(to bottom, #00FFFF, #FF00FF)'}}>         {node.text}       </div>     </div>;   }   return <div style={{lineHeight: '80px', textAlign: 'center'}}>     <span>{node.text}</span>   </div> }; const SimpleGraph: React.FC = () => {   const graphRef = useRef() as MutableRefObject<RelationGraphExpose>;   useEffect(() => {     showGraph();   }, []);   const showGraph = async () => {     // 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     await graphRef.current.setJsonData(staticJsonData, (graphInstance) => {         // Do something when graph ready     });     // The graphRef.current.setJsonData(jsonData, callback) method is a convenient method that is equivalent to the following code:     //  const graphInstance = graphRef.current.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   }   const options:RGOptions = {     debug: true,     defaultLineShape: 1,     layout: {       layoutName: 'center',       maxLayoutTimes: 3000     },     defaultExpandHolderPosition: 'right'   };   const onNodeClick = (node: RGNode, _e: MouseEvent | TouchEvent) => {     console.log('onNodeClick:', node.text);     return true;   };   const onLineClick = (line: RGLine, _link: RGLink, _e: MouseEvent | TouchEvent) => {     console.log('onLineClick:', line.text, line.from, line.to);     return true;   };   return <div>     <div>ok</div>     <div style={{ height: 600, width: 900, border: '#efefef solid 1px' }}>       <RelationGraph         ref={graphRef}         options={options}         nodeSlot={NodeSlot}         onNodeClick={onNodeClick}         onLineClick={onLineClick}       />     </div>   </div>; }; export default SimpleGraph;

五、运行结果

因为我是Vue2项目,所以下面展示的是我在Vue2项目中的代码,可直接复制运行,需要注意的是我使用了less

<template>     <div>         <div>             <h3>设备联动图</h3>         </div>         <div>             <RelationGraph ref="graphRef" :options="graphOptions" :on-node-click="onNodeClick" :on-line-click="onLineClick">                 <template #node="{ node }">                     <div>                         <div>                             <div>                                 <span></span>                                 <strong>声光</strong>                                 <div>离线</div>                             </div>                             <div>                                 <span>4</span>                             </div>                         </div>                         <div>                             办公室1                         </div>                     </div>                 </template>             </RelationGraph>         </div>     </div> </template> <script> import RelationGraph from 'relation-graph' export default {     name: "DevLinkageDiagram",     components: { RelationGraph },     props: {},     data() {         return {             graphOptions: {                 defaultJunctionPoint: 'border',                 allowShowDownloadButton: false,                 defaultFocusRootNode: false,                 defaultNodeWidth: 1,                 defaultNodeHeight: 1,                 defaultShowLineLabel: false,                 allowShowRefreshButton: true,                 // 这里可以参考"Graph 图谱"中的参数进行设置 https://www.relation-graph.com/#/docs/graph             }         };     },     computed: {},     created() { },     mounted() {         this.showGraph()     },     methods: {         showGraph() {             const jsonData = {                 rootId: 'a',                 nodes: [                     { id: 'a', text: 'A', },                     { id: 'b', text: 'B', },                     { id: 'c', text: 'C', },                     { id: 'e', text: 'E', }                 ],                 lines: [                     { from: 'a', to: 'b', },                     { from: 'a', to: 'c', },                     { from: 'a', to: 'e', },                 ]             }             // 以上数据中的node和link可以参考"Node节点"和"Link关系"中的参数进行配置             this.$refs.graphRef.setJsonData(jsonData, (graphInstance) => {                 // Called when the relation-graph is completed             })         },         onNodeClick(nodeObject, $event) {             // console.log('onNodeClick:', nodeObject)         },         onLineClick(lineObject, $event) {             // console.log('onLineClick:', lineObject)         }     }, }; </script> <style scoped lang="less"> .dev-linkage-diagram {     padding: 15px;     background-color: #ffffff;     border-radius: 4px;     box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);     .header {         display: flex;         justify-content: space-between;         align-items: center;         margin-bottom: 15px;         padding-bottom: 10px;         border-bottom: 1px solid #eee;     }     .graphRefBox {         height: 580px;         background-color: #cfcece;     }     .rel-node-peel {         position: relative;         .c-my-rg-node {             position: absolute;             top: 50%;             left: 50%;             transform: translate(-50%, -50%);         }     }     .nodeBox {         width: 200px;         border-radius: 20px;         overflow: hidden;         >div {             padding: 0 16px;         }         .top {             display: flex;             justify-content: space-between;             align-items: center;             width: 100%;             height: 40px;             background-color: #deb922;             .left {                 display: flex;                 align-items: center;                 color: #fff;                 .state {                     padding: 1px 4px;                     margin-left: 4px;                     background-color: rgba(245, 245, 245, 0.3);                     border-radius: 4px;                 }             }             .num {                 display: flex;                 justify-content: center;                 align-items: center;                 width: 24px;                 height: 24px;                 background-color: rgba(226, 226, 226, 0.5);                 border: 1px solid #fff;                 border-radius: 50%;                 color: #fff;                 font-weight: 700;                 font-size: 14px;             }         }         .bottom {             display: flex;             align-items: center;             width: 100%;             height: 40px;             background-color: #72716d;             font-size: 14px;         }     } } </style>

六、下面是运行成果图

非常完美!!!真的很好用,真心推荐!!!如果觉得有用就请用发财的小手点点赞趴,谢谢啦!

Read more

2026年高薪就业赛道揭晓:AI大数据、大模型、AIGC与云计算,错过等五年!

2026年高薪就业赛道揭晓:AI大数据、大模型、AIGC与云计算,错过等五年!

2026年最好的就业赛道——AI大数据、大模型、云计算与AIGC 2026年的春招市场,只有两种人:懂AI的,和羡慕懂AI的。 春节刚过,当大多数人还沉浸在节日的余温中时,招聘市场已经迎来了“开门红”。据智联招聘数据显示,正月初八活跃职位数跃升至除夕的7倍 。而在这一轮招聘热潮中,一个 明显的赢家赛道已然清晰:以人工智能为代表的新质生产力。 如果你还在为“什么专业好就业”而焦虑,或者正在考虑职业转型,那么今年的市场数据给出了极其明确的指向:AI大数据、大模型、AIGC与云计算,正是当下乃至未来五年的黄金赛道。 一、AI人才“一将难求”:岗位暴涨12倍,平均月薪超6万 2026年的AI人才市场有多火?一组数据足以说明问题。 职场社区平台脉脉发布的《2026年1-2月中高端人才求职招聘洞察》显示,今年前两个月,AI岗位数量同比增长了惊人的12倍,其在新经济行业中的岗位占比从去年同期的2.29%飙升至 26.23% 。 与其相对应的是令人艳羡的薪资水平。AI新发岗位的平均月薪达到 60,738元,比新经济行业平均水平高出约26% 。其中,

云开发 Copilot ——让开发变得更简单

云开发 Copilot ——让开发变得更简单

声明:本篇博客为云开发 Copilot体验文章,非广告 目录 前言: 游客体验 云开发 Copilot实战: 一、图片生成需求 二、云开发 Copilot实现需求 三、AI生成低代码页面 Copilot 的亮点功能 使用场景 云开发 Copilot开发的前景展望 前言: 在云开发AI+中,腾讯云提供一系列与 AI 相关的功能,如大模型接入、 Agent 等,帮助开发者为自己的小程序、web 或者应用快速接入 AI 能力,同时也提供了云开发 Copilot,来加速用户的开发,帮助用户更快构建自己的应用。下面博主将会为大家实战使用云开发 Copilot来助力开发。 云开发 Copilot是云开发推出的一款 AI 开发辅助工具,可以帮助用户快速生成多种类型的应用功能,包括低代码应用、页面、组件、数据模型、

核心期刊AIGC检测太严?SCI投稿降AI完整攻略

核心期刊AIGC检测太严?SCI投稿降AI完整攻略 TL;DR(太长不看):核心期刊和SCI对AI率要求极严,部分顶刊要求低于10%。完整攻略:投稿前用Turnitin检测→用AIGCleaner(英文首选)或嘎嘎降AI(中英通用)处理→人工检查术语和引用→用目标期刊的检测平台验证。AIGCleaner可将Turnitin AI率从95%降到5%以下,英文论文AI率建议控制在15%以下。 核心期刊和SCI对AI率要求有多严? 如果你正在准备投稿核心期刊或SCI,AI率问题必须提前重视。2026年各大期刊对AI生成内容的审查越来越严格,部分顶刊(比如Nature子刊、Science系列)明确要求AI率低于10%,普通SCI期刊一般要求低于20%。Turnitin、iThenticate这些检测系统也在不断升级算法,能够识别ChatGPT、Claude、DeepSeek等主流大模型的写作特征。我有个同事投Nature Communications,论文质量没问题,就因为AI率超标被编辑直接desk reject,几个月的心血付诸东流。所以投稿前一定要检测并处理AI率。 核心期刊

VsCode 远程连服务器后,Github Copilot 突然用不了?3 步定位问题

VS Code远程连接服务器后Github Copilot失效的3步排查法 步骤1:验证基础连接状态 * 检查扩展安装: 在远程服务器上打开VS Code扩展面板(Ctrl+Shift+X),确认GitHub Copilot扩展是否显示 已在远程安装。若显示"在SSH:xxx上安装",需点击安装。 网络连通性测试: 在远程终端执行: curl -v https://api.githubcopilot.com 正常响应应返回HTTP/2 403(权限拒绝),若出现连接超时或DNS错误,说明存在网络隔离。 步骤2:排查认证同步问题 * 检查令牌状态: 1. 本地VS Code执行 Ctrl+Shift+P > GitHub Copilot: Sign In 2. 远程连接后执行