前端关系图推荐-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声明在哪里写?

2026国家自然基金ai声明在哪里写? 下面图中 根据2026年国家自然科学基金(NSFC)最新要求,‌AI使用声明需在申请书中明确撰写并提交‌,具体位置和撰写方式如下: 声明撰写位置建议 * ‌推荐位置‌:将AI使用声明作为独立小节,置于“‌研究方案‌”或“‌研究基础‌”部分之后,也可放在“‌伦理合规与科研诚信‌”相关章节中。 * ‌标题建议‌:使用如“‌3.X 人工智能工具使用边界与研究诚信保障策略‌”等清晰标题,便于评审查阅‌4。 声明撰写原则(权威指引) 根据基金委最新导向及多位专家解读,声明应遵循以下原则: * ‌诚实透明,宜粗不宜细‌:无需逐段罗列AI在立项依据、技术路线等各部分的具体使用情况‌610。 ‌整体性说明即可‌:例如: “本项目申请书的撰写过程中,申请人使用[工具名称,

【AI编程】Qoder AI 编程工具从部署到深度使用实战详解

【AI编程】Qoder AI 编程工具从部署到深度使用实战详解

目录 一、前言 二、AI编程工具介绍 2.1 什么是AI编程 2.1 AI编程核心功能 2.3 AI编程应用场景 1. 智能代码补全与生成 2. 自然语言生成代码 3. 代码解释与文档生成 4. 错误检测与自动修复 5. 单元测试与自动化测试生成 6. 代码重构与优化 7. 跨语言代码转换 8. 低代码/无代码平台增强 三、几种主流AI编程工具介绍 3.1 Cursor 3.1.1 Cursor 核心功能 3.1.1 Cursor 优势 3.2 GitHub Copilot

人工智能多模态模型开发与应用:跨越文本、图像与语音的融合实践

人工智能多模态模型开发与应用:跨越文本、图像与语音的融合实践

一、人工智能多模态模型开发与应用:跨越文本、图像与语音的融合实践 1.1 本章学习目标与重点 💡 掌握多模态模型的核心概念与技术原理,理解文本、图像、语音等不同模态数据的融合逻辑; 💡 熟练运用主流多模态框架(Hugging Face Transformers、MMEngine、LangChain Multimodal),实现跨模态理解与生成任务; 💡 精通多模态模型的开发流程,包括数据预处理、模型选型、训练微调、部署落地等关键环节; 💡 通过真实场景案例(图文生成、跨模态问答、语音助手),掌握多模态技术从原型到产品的端到端落地能力。 ⚠️ 重点关注:多模态数据的对齐与预处理、模型训练的显存优化、生成内容的一致性与准确性、以及不同部署场景下的性能适配。 1.2 多模态模型基础:概念、技术与生态 随着人工智能技术的发展,单一模态(如纯文本、纯图像)模型已难以满足复杂场景需求。多模态模型通过融合文本、图像、语音、视频等多种模态数据,实现更全面的理解与更灵活的生成,成为当前

【OpenClaw从入门到精通】第41篇:2026年4月最新版——从零开始搭建你的第一个安全AI助理(保姆级实战教程)

【OpenClaw从入门到精通】第41篇:2026年4月最新版——从零开始搭建你的第一个安全AI助理(保姆级实战教程)

摘要:2026年3月CNCERT联合发布《OpenClaw安全使用实践指南》后,安全部署成为OpenClaw使用的核心前提。本文针对新手及进阶用户,基于官方安全指引,提供三套实战部署方案:阿里云一键部署(新手首选)、Docker容器隔离部署(进阶推荐)、本地安全安装(测试专用),并详解阿里云百炼Coding Plan API接入流程。全文涵盖环境准备、分步实操、安全加固、问题排查等全流程,所有命令可直接复制执行,无需依赖外部代码库。通过本文,读者可零基础搭建安全隔离的OpenClaw AI助理,兼顾实用性与安全性,最低成本仅38元/年即可实现7×24小时稳定运行。 优质专栏欢迎订阅! 【OpenClaw从入门到精通】【DeepSeek深度应用】【Python高阶开发:AI自动化与数据工程实战】 【YOLOv11工业级实战】【机器视觉:C# + HALCON】【大模型微调实战:平民级微调技术全解】 【人工智能之深度学习】【AI 赋能:Python 人工智能应用实战】【数字孪生与仿真技术实战指南】 【AI工程化落地与YOLOv8/v9实战】【C#