vue-treecharts
Tree chart component based on Vue 2.0
Introduction
高度可定制的树图表组件组件,支持 vue slot 特性自定义树节点 DOM,实现动态可编辑的树图表,如决策树。
实现思路:树节点(TreeChartNode)组件基于递归实现,先序遍历以自上向下(DOM)计算子树高度,自底向顶(树结构)计算子树宽度。随后用 svg path d 计算并绘制贝塞尔曲线以连接父子节点
Contact me for any questions: nerfthisan@163.com
Install
npm install vue-treecharts --save
Example
{{node.data.name}} append remove showChildren hideChildren
Document
props
-
data 数据源
type: Object
-
nodeKey 子节点数组中元素的唯一 key(如 ID)
type: String | Number | Function | Boolean
default: undefined
若为静态数据可无需设置该值,若需支持数据节点的增删改则必须为数组中每个元素设置唯一 key 值,否则可能导致 dom 更新错误,参考 Vue key
-
childrenKey 子节点数组所在的属性键名
type: String
default: "children"
-
transition 节点增删改动画时间
type: Number
default: 0
-
lineColor 父子节点连线颜色
type: String
default: "#666"
-
lineOffset 父子节点连线偏移量
type: Number
default: 20
-
lineWidth 父子节点连线宽度
type: Number
default: 2
slots
-
default 节点自定义内容
slotProps: { node, childrenVisible }
-
node: 数据节点对象
-
childrenVisible: Function,控制当前节点的子节点是否显示的函数,参数必须为
boolean
类型,返回值为子节点是否显示。
-