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
|`nodeSvgShape`|`object`| see [Node shapes](#node-shapes)||`{shape: 'circle', shapeProps: r: 10}`| Sets a specific SVG shape element + shapeProps to be used for each node. |
87
+
|`nodeLabelComponent`|`object`| see [Using foreignObjects](#using-foreignobjects)||`null`| Allows using a React component as a node label; requires `allowForeignObjects` to be set. |
85
88
|`onClick`|`func`|||`undefined`| Callback function to be called when a node is clicked. <br /><br /> The clicked node's data object is passed to the callback function. |
86
89
|`onMouseOver`|`func`|||`undefined`| Callback function to be called when mouse enters the space belonging to a node. <br /><br /> The node's data object is passed to the callback. |
87
90
|`onMouseOut`|`func`|||`undefined`| Callback function to be called when mouse leaves the space belonging to a node. <br /><br /> The node's data object is passed to the callback. |
@@ -98,6 +101,7 @@ class MyComponent extends React.Component {
98
101
|`transitionDuration`|`number`|`0..n`||`500`| Sets the animation duration (in ms) of each expansion/collapse of a tree node. <br /><br /> Set this to `0` to deactivate animations completely. |
99
102
|`textLayout`|`object`|`{textAnchor: enum, x: -n..0..n, y: -n..0..n, transform: string}`||`{textAnchor: "start", x: 10, y: -10, transform: undefined }`| Configures the positioning of each node's text (name & attributes) relative to the node itself.<br/><br/>`textAnchor` enums mirror the [`text-anchor` spec](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/text-anchor).<br/><br/>`x` & `y` accept integers denoting `px` values.<br/><br/> `transform` mirrors the [svg `transform` spec](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform). |
100
103
|`styles`|`object`| see [Styling](#styling)||`Node`/`Link` CSS files | Overrides and/or enhances the tree's default styling. |
104
+
|`allowForeignObjects`|`bool`| see [Using foreignObjects](#using-foreignobjects)||`false`| Allows use of partially supported `<foreignObject />` elements. |
101
105
|`circleRadius` (legacy) |`number`|`0..n`||`undefined`| Sets the radius of each node's `<circle>` element.<br /><br /> **Will be deprecated in v2, please use `nodeSvgShape` instead.**|
102
106
103
107
@@ -131,6 +135,7 @@ This is to prevent breaking the legacy usage of `circleRadius` + styling via `no
131
135
132
136
**From v1.5.x onwards, it is therefore recommended to pass all node styling properties through `shapeProps`**.
133
137
138
+
134
139
## Styling
135
140
The tree's `styles` prop may be used to override any of the tree's default styling.
136
141
The following object shape is expected by `styles`:
@@ -207,5 +212,63 @@ For details regarding the `treeUtil` module, please check the module's [API docs
207
212
For examples of each data type that can be parsed with `treeUtil`, please check the [data source examples](docs/examples/data).
208
213
209
214
215
+
## Using foreignObjects
216
+
> ⚠️ Requires `allowForeignObjects` prop to be set due to limited browser support: [IE does not currently support `foreignObject` elements](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/foreignObject#Browser_compatibility).
217
+
218
+
The SVG spec's `foreignObject` element allows foreign XML content to be rendered into the SVG namespace, unlocking the ability to use regular React components for elements of the tree graph.
219
+
220
+
### `nodeLabelComponent`
221
+
The `nodeLabelComponent` prop provides a way to use a React component for each node's label. It accepts an object with the following signature:
222
+
```ts
223
+
{
224
+
render: ReactElement,
225
+
foreignObjectWrapper?:object
226
+
}
227
+
```
228
+
*`render` is the XML React-D3-Tree will use to render each node's label.
229
+
*`foreignObjectWrapper` contains a set of attributes that should be passed to the `<foreignObject />` that wraps `nodeLabelComponent`. For possible attributes please check the [spec](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/foreignObject#Global_attributes).
230
+
231
+
**Note: `foreignObjectWrapper` will set its width and height attributes to whatever values `nodeSize.x` and `nodeSize.y` return by default.**
232
+
To override this behaviour for each attribute, specify `width` and/or `height` properties for your `foreignObjectWrapper`.
233
+
234
+
**Note:** The ReactElement passed to `render` is cloned with its existing props and **receives an additional `nodeData` object prop, containing information about the current node.**
235
+
236
+
#### Example
237
+
Assuming we have a React component `NodeLabel` and we want to avoid node's label overlapping with the node itself by moving its position along the Y-axis, we could implement `nodeLabelComponent` like so:
0 commit comments