Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

d3-react-force

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-react-force

react版d3-force封装,简化d3-force配置。

latest
Source
npmnpm
Version
1.0.15
Version published
Weekly downloads
19
-9.52%
Maintainers
1
Weekly downloads
 
Created
Source

d3-react-force

react版d3-force封装,简化d3-force配置。

安装

npm install d3-react-force
// yarn add d3-react-force

在线演示

https://yacan8.github.io/d3-react-force/

props参数

参数说明类型默认值
width容器宽度number800
height容器高度number800
nodeIdKey节点表示键值string'id'
velocityDecay节点速度衰减系数,可理解为摩擦力,0~1之间number0.1
linkDistance连线长度number或(link) => number0.1
collideRadius节点碰撞半径number或(node) => number0
collideStrength节点碰撞强度,0~1之间number0.5
chargeStrength节点之间作用力,整数为引力,负数为斥力number-10
staticLayout是否为静态布局(需要事先使用/simulation.js计算节点位置)booleanfalse
XYCenter是否添加x、y作用力,居中效果,避免不连通图游离boolean或Object{x: 0, y: 0}
tick动画回调,每一帧function(alpah)noop
endtick结束回调functionnoop
NodeElement节点React.Element或(node)=> React.Elementcircle
LinkElement(link, addRef) => React.Element或objectlink
nodeClick节点点击事件function(node, d3.event)noop
nodeDbClick节点双击事件function(node, d3.event)noop
nodeMouseover节点mouseover事件function(node, d3.event)noop
nodeMouseout节点mouseout事件function(node, d3.event)noop
linkClick边点击事件function(link, d3.event)noop
linkMouseover边mouseover事件function(link, d3.event)noop
linkMouseout边mouseout事件function(link, d3.event)noop
dragEvent节点拖拽事件,start、isDrag、drag、end四个事件函数 isDrag判断是否拖拽,返回booleanObject{}
zoomEvent缩放事件,start、isZoom、zoom、end四个事件函数,isZoom判断是否缩放,返回booleanObject{}

API

通过ref方式获取组件示例,使用下列API:

adaption(animate)

视图居中,animate表示是否动画移动。

transform(translate, scale, animate)

缩放平移,translate为数组,数组第一个值为x偏移量,第二个值为y偏移量,scale为缩放比例,animate表示是否动画,默认不使用动画。如果不传任何参数,则返回偏移量与缩放比例。

forceEndTick()

强制停止tick动画动画。

addLayout(layout, options)

添加布局,layout分为圆形布局circle、阿基米德螺旋布局archimeddeanSpiral、栅格布局grid、分层布局dagre,options为布局参数,返回包含执行布局函数对象。如component.addLayout('circle').execute(),或者使用component.executeLayout('circle',{beforeExecute:() =>{}})

free()

布局释放,布局layout后节点x、y固定,使用free方法释放节点,变成力导向布局。

execute()

同步执行里导向布局至静止,注意:不会更新视图,需要手动执行tick更新视图。

Keywords

d3

FAQs

Package last updated on 26 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts