vue-tree-chart
flexible tree chart using Canvas and Svg, powered by D3.js
Using Tech
Canvas version
- use D3.js with Canvas to draw organizationChart more efficiently.
- Use
unique-color
manner to identify mouse click event in Canvas (you can refer to https://medium.com/@lverspohl/how-to-turn-d3-and-canvas-into-good-friends-b7a240a32915 to see detail)
Svg version
- use D3 to calculate node & link positon
- use Vue to handle dom element entring and leaving
- use Vue slot to let user easily use with their own data
How to use?
Svg version
1. install npm module
2. register vue-tree
component
3. use component
3.1 basic usage
See Code
3.2 show collapsed node in different style
See Code
3.3 render rich media data
See Code
4. API
4.1 props
type | default | description | |
---|---|---|---|
dataset | Object | null | nested tree data |
config | Object | { nodeWidth: 100, nodeHeight: 100, levelHeight: 200 } |
nodeWidth and nodeHeight config the tree node size. levelHeight is tree row height |
linkStyle | String | 'curve' | control link style, options: 'curve' or 'straight' |
direction | string | 'vertical' | control tree chart direction, options: 'vertical' or 'horizontal' |
4.2 slot
this component only support default slot.
a sample usage like this:
there are two slot params provided to render slot content:
slot param | type | description |
---|---|---|
node | Object | current node data to be rendered |
collapsed | Boolean | current node collapse status |
Canvas version
the canvas version is not published with npm module.
if you want to use this project's canvas version, please download the source code and edit with the following steps:
- replace the data in
/src/base/data-generator.js
with your own nested data. - add your data drawing logic in
/src/components/org-chart.js #drawShowCanvas