You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -103,9 +106,11 @@ export default function OrgChartTree() {
103
106
## Props
104
107
For details on the props accepted by `Tree`, check out the [TreeProps reference docs](https://bkrem.github.io/react-d3-tree/docs/interfaces/_tree_types_.treeprops.html).
105
108
109
+
The only required prop is [data](https://bkrem.github.io/react-d3-tree/docs/interfaces/_tree_types_.treeprops.html#data), all other props on `Tree` are optional/pre-defined (see "Default value" on each prop).
110
+
106
111
<!--(TODO: REVISE TITLE) -->
107
112
## Up & Running
108
-
### Styling nodes
113
+
### Styling Nodes
109
114
`Tree` provides the following props to style different types of nodes, all of which use an SVG `circle` by default:
110
115
111
116
-`rootNodeClassName` - will be applied to the root node.
@@ -117,14 +122,17 @@ To visually distinguish these three types of nodes from each other by color, we
117
122
```css
118
123
/* custom-tree.css */
119
124
120
-
.node__root {
125
+
.node__root>circle{
121
126
fill: red;
122
127
}
123
-
.node__branch {
124
-
fill: yellow
128
+
129
+
.node__branch>circle {
130
+
fill: yellow;
125
131
}
126
-
.node__leaf {
127
-
fill: green;
132
+
133
+
.node__leaf>circle {
134
+
/* Let's make the radius of leaf nodes larger */
135
+
r: 40;
128
136
}
129
137
```
130
138
@@ -153,7 +161,7 @@ export default function StyledNodesTree() {
153
161
154
162
<!-- For a full list of options of CSS properties that can be used for the default nodes, check the SVG circle [specification](TODO:) -->
155
163
156
-
### Styling links
164
+
### Styling Links
157
165
`Tree` provides the `pathClassFunc` property to pass additional classNames to every link to be rendered.
158
166
159
167
Each link calls `pathClassFunc` with its own `TreeLinkDatum` and the tree's current `orientation`. `Tree` expects `pathClassFunc` to return a `className` string.
@@ -186,8 +194,35 @@ function StyledLinksTree() {
186
194
187
195
> For more details, see the `PathClassFunction`[reference docs](https://bkrem.github.io/react-d3-tree/docs/modules/_types_common_.html#pathclassfunction).
188
196
189
-
## Rendering custom nodes
190
-
TODO:
197
+
### Event Handlers
198
+
`Tree` exposes the following event handler callbacks by default:
> **Note:** Nodes are expanded/collapsed whenever `onNodeClick` fires. To prevent this, set the [`collapsible` prop](https://bkrem.github.io/react-d3-tree/docs/interfaces/_tree_types_.treeprops.html#collapsible) to `false`.
208
+
> `onNodeClick` will still fire, but it will not change the target node's expanded/collapsed state.
209
+
210
+
## Customizing the Tree
211
+
<!-- Using the `<nodeType>NodeClassName` and `pathClassFunc` approaches above should give -->
212
+
213
+
### `renderCustomNodeElement`
214
+
The [`renderCustomNodeElement` prop](https://bkrem.github.io/react-d3-tree/docs/interfaces/_tree_types_.treeprops.html#rendercustomnodeelement) accepts a **custom render function that will be used for every node in the tree.**
215
+
216
+
Cases where you may find rendering your own `Node` element useful include:
217
+
218
+
<!-- TODO: attach examples for each use case -->
219
+
220
+
- Using a **different SVG tag for your nodes** (instead of the default `<circle>`).
221
+
- Gaining **fine-grained control over event handling** (e.g. to implement events not covered by the default API).
222
+
- Building **richer & more complex nodes/labels** by leveraging the `foreignObject` tag to render HTML inside the SVG namespace.
0 commit comments