Project Icon

react-force-graph

React力导向图可视化组件库

react-force-graph是一个用于创建交互式力导向图的React组件库。它支持2D、3D、VR和AR四种可视化模式,适用于大规模数据集。该库采用canvas/WebGL渲染,d3-force-3d作为物理引擎,提供缩放、平移、节点拖动等交互功能。丰富的自定义选项使其能满足各种复杂网络数据的可视化需求。

react-force-graph

[![NPM package][npm-img]][npm-url] [![NPM Downloads][npm-downloads-img]][npm-downloads-url]

React bindings for the force-graph suite of components: force-graph (2D HTML Canvas), 3d-force-graph (ThreeJS/WebGL), 3d-force-graph-vr (A-Frame) and 3d-force-graph-ar (AR.js).

This module exports 4 React components with identical interfaces: ForceGraph2D, ForceGraph3D, ForceGraphVR and ForceGraphAR. Each can be used to represent a graph data structure in a 2 or 3-dimensional space using a force-directed iterative layout.

For dependency convenience, all of the components are also available as stand-alone packages: react-force-graph-2d, react-force-graph-3d, react-force-graph-vr and react-force-graph-ar.

Uses canvas/WebGL for rendering and d3-force-3d for the underlying physics engine. Supports zooming/panning, node dragging and node/link hover/click interactions.

Examples

Quick start

import ForceGraph2D from 'react-force-graph-2d';
import ForceGraph3D from 'react-force-graph-3d';
import ForceGraphVR from 'react-force-graph-vr';
import ForceGraphAR from 'react-force-graph-ar';

or

import { ForceGraph2D, ForceGraph3D, ForceGraphVR, ForceGraphAR } from 'react-force-graph';

or using a script tag

<script src="//unpkg.com/react-force-graph-2d"></script>
<script src="//unpkg.com/react-force-graph-3d"></script>
<script src="//unpkg.com/react-force-graph-vr"></script>
<script src="//unpkg.com/react-force-graph-ar"></script>

then

<ForceGraph3D
  graphData={myData}
/>

API reference

Note that not all props listed below apply to all 4 components. The last 4 columns in these tables indicate the specific component availability of each prop/method.

Data input

PropTypeDefaultDescription2D3DVRAR
graphDataobject{ nodes: [], links: [] }Graph data structure (see below for syntax details). Can also be used to apply incremental updates.:heavy_check_mark::heavy_check_mark::heavy_check_mark::heavy_check_mark:
nodeIdstringidNode object accessor attribute for unique node id (used in link objects source/target).:heavy_check_mark::heavy_check_mark::heavy_check_mark::heavy_check_mark:
linkSourcestringsourceLink object accessor attribute referring to id of source node.:heavy_check_mark::heavy_check_mark::heavy_check_mark::heavy_check_mark:
linkTargetstringtargetLink object accessor attribute referring to id of target node.:heavy_check_mark::heavy_check_mark::heavy_check_mark::heavy_check_mark:

Container layout

PropTypeDefaultDescription2D3DVRAR
widthnumber<window width>Canvas width, in px.:heavy_check_mark::heavy_check_mark::heavy_check_mark::heavy_check_mark:
heightnumber<window height>Canvas height, in px.:heavy_check_mark::heavy_check_mark::heavy_check_mark::heavy_check_mark:
backgroundColorstring(2D - light / 3D - dark)Chart background color.:heavy_check_mark::heavy_check_mark::heavy_check_mark:
showNavInfobooltrueWhether to show the navigation controls footer info.:heavy_check_mark::heavy_check_mark:
yOffsetnumber1.5In AR mode, defines the offset distance above the marker where to place the center coordinates <0,0,0> of the force directed graph. Measured in terms of marker width units.:heavy_check_mark:
glScalenumber200In AR mode, defines the translation scale between real world distances and WebGL units, determining the overall size of the graph. Defined in terms of how many GL units fit in a full marker width.:heavy_check_mark:
markerAttrsobject{ preset: 'hiro' }Set of attributes that define the marker where the AR force directed graph is mounted, according to the a-marker specification. This prop only has an effect on component mount.:heavy_check_mark:

Node styling

PropTypeDefaultDescription2D3DVRAR
nodeRelSizenumber4Ratio of node circle area (square px) [2D] or sphere volume (cubic px) [3D] per value unit.:heavy_check_mark::heavy_check_mark::heavy_check_mark::heavy_check_mark:
nodeValnumber, string or funcvalNode object accessor function, attribute or a numeric constant for the node numeric value (affects node size).:heavy_check_mark::heavy_check_mark::heavy_check_mark::heavy_check_mark:
nodeLabelstring or funcnameNode object accessor function or attribute for name (shown in label). Supports plain text or HTML content (except in VR).:heavy_check_mark::heavy_check_mark::heavy_check_mark:
nodeDescstring or funcdescFor VR only. Node object accessor function or attribute for description (shown under label).:heavy_check_mark:
nodeVisibilitybool, string or functrueNode object accessor function, attribute or a boolean constant for whether to display the node.:heavy_check_mark::heavy_check_mark::heavy_check_mark::heavy_check_mark:
nodeColorstring or funccolorNode object accessor function or attribute for node color.:heavy_check_mark::heavy_check_mark::heavy_check_mark::heavy_check_mark:
nodeAutoColorBystring or funcNode object accessor function or attribute to automatically group colors by. Only affects nodes without a color attribute.:heavy_check_mark::heavy_check_mark::heavy_check_mark::heavy_check_mark:
nodeOpacitynumber0.75Nodes sphere opacity, between [0,1].:heavy_check_mark::heavy_check_mark::heavy_check_mark:
nodeResolutionnumber8Geometric resolution of each node's sphere, expressed in how many slice segments to divide the circumference. Higher values yield smoother spheres. Only applicable to 3D modes.:heavy_check_mark::heavy_check_mark::heavy_check_mark:
nodeCanvasObjectfuncdefault 2D node object is a circle, sized according to val and styled according to color.Callback function for painting a custom 2D canvas object to represent graph nodes. Should use the provided canvas context attribute to perform drawing operations for each node. The callback function will be called for each node at every frame, and has the signature: nodeCanvasObject(<node>, <canvas context>, <current global scale>).:heavy_check_mark:
nodeCanvasObjectModestring or func() => 'replace'Node object accessor function or attribute for the custom drawing mode. Use in combination with nodeCanvasObject to specify how to customize nodes painting. Possible values are:
  • replace: the node is rendered using just nodeCanvasObject.
  • before: the node is rendered by invoking nodeCanvasObject and then proceeding with the default node painting.
  • after: nodeCanvasObject is applied after the default node painting takes place.
Any other value will be ignored and the default drawing will be applied.
:heavy_check_mark:
nodeThreeObjectObject3d, string or funcdefault 3D node object is a sphere, sized according to val and styled according to color.Node object accessor function or attribute for generating a custom 3d object to render as graph nodes. Should return an instance of ThreeJS Object3d. If a falsy value is returned, the default 3d object type will be used instead for that node.:heavy_check_mark::heavy_check_mark::heavy_check_mark:
nodeThreeObjectExtendbool, string or funcfalseNode object accessor function, attribute or a boolean value for whether to replace the default node when using a custom nodeThreeObject (false) or to extend it (true).:heavy_check_mark::heavy_check_mark::heavy_check_mark:

Link styling

PropTypeDefaultDescription2D3DVRAR
linkLabelstring or funcnameLink object accessor function or attribute for name (shown in label). Supports plain text or HTML content (except in VR).:heavy_check_mark::heavy_check_mark::heavy_check_mark:
项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

Kimi

Kimi AI助手提供多语言对话支持,能够阅读和理解用户上传的文件内容,解析网页信息,并结合搜索结果为用户提供详尽的答案。无论是日常咨询还是专业问题,Kimi都能以友好、专业的方式提供帮助。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

吐司

探索Tensor.Art平台的独特AI模型,免费访问各种图像生成与AI训练工具,从Stable Diffusion等基础模型开始,轻松实现创新图像生成。体验前沿的AI技术,推动个人和企业的创新发展。

Project Cover

SubCat字幕猫

SubCat字幕猫APP是一款创新的视频播放器,它将改变您观看视频的方式!SubCat结合了先进的人工智能技术,为您提供即时视频字幕翻译,无论是本地视频还是网络流媒体,让您轻松享受各种语言的内容。

Project Cover

美间AI

美间AI创意设计平台,利用前沿AI技术,为设计师和营销人员提供一站式设计解决方案。从智能海报到3D效果图,再到文案生成,美间让创意设计更简单、更高效。

Project Cover

AIWritePaper论文写作

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号