Skip to content

Commit 40c8534

Browse files
committed
docs(readme): adds pathFunc section
1 parent cf0eed4 commit 40c8534

File tree

1 file changed

+47
-15
lines changed

1 file changed

+47
-15
lines changed

README.md

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ React D3 Tree is a [React](http://facebook.github.io/react/) component that lets
3131
- [Installation](#installation)
3232
- [Usage](#usage)
3333
- [Props](#props)
34-
- [Up & Running](#up--running)
35-
- [Styling Nodes](#styling-nodes)
36-
- [Styling Links](#styling-links)
37-
- [Event Handlers](#event-handlers)
34+
- [Styling Nodes](#styling-nodes)
35+
- [Styling Links](#styling-links)
36+
- [Event Handlers](#event-handlers)
3837
- [Customizing the Tree](#customizing-the-tree)
3938
- [`renderCustomNodeElement`](#rendercustomnodeelement)
4039
- [`pathFunc`](#pathfunc)
40+
- [Providing your own `pathFunc`](#providing-your-own-pathfunc)
4141
- [Development](#development)
4242
- [Setup](#setup)
4343
- [Hot reloading](#hot-reloading)
@@ -104,18 +104,16 @@ export default function OrgChartTree() {
104104
```
105105

106106
## Props
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).
107+
For details on all props accepted by `Tree`, check out the [TreeProps reference docs](https://bkrem.github.io/react-d3-tree/docs/interfaces/_tree_types_.treeprops.html).
108108

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).
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 definition).
110110

111-
<!--(TODO: REVISE TITLE) -->
112-
## Up & Running
113-
### Styling Nodes
111+
## Styling Nodes
114112
`Tree` provides the following props to style different types of nodes, all of which use an SVG `circle` by default:
115113

116-
- `rootNodeClassName` - will be applied to the root node.
117-
- `branchNodeClassName` - will be applied to any node with 1+ children.
118-
- `leafNodeClassName` - will be applied to any node without children.
114+
- `rootNodeClassName` - applied to the root node.
115+
- `branchNodeClassName` - applied to any node with 1+ children.
116+
- `leafNodeClassName` - applied to any node without children.
119117

120118
To visually distinguish these three types of nodes from each other by color, we could provide each with their own class:
121119

@@ -161,7 +159,7 @@ export default function StyledNodesTree() {
161159
162160
<!-- For a full list of options of CSS properties that can be used for the default nodes, check the SVG circle [specification](TODO:) -->
163161

164-
### Styling Links
162+
## Styling Links
165163
`Tree` provides the `pathClassFunc` property to pass additional classNames to every link to be rendered.
166164

167165
Each link calls `pathClassFunc` with its own `TreeLinkDatum` and the tree's current `orientation`. `Tree` expects `pathClassFunc` to return a `className` string.
@@ -194,7 +192,7 @@ function StyledLinksTree() {
194192

195193
> For more details, see the `PathClassFunction` [reference docs](https://bkrem.github.io/react-d3-tree/docs/modules/_types_common_.html#pathclassfunction).
196194
197-
### Event Handlers
195+
## Event Handlers
198196
`Tree` exposes the following event handler callbacks by default:
199197

200198
- [onLinkClick](https://bkrem.github.io/react-d3-tree/docs/interfaces/_tree_types_.treeprops.html#onlinkclick)
@@ -220,7 +218,41 @@ Cases where you may find rendering your own `Node` element useful include:
220218
- Building **richer & more complex nodes/labels** by leveraging the `foreignObject` tag to render HTML inside the SVG namespace - [Example (codesandbox.io)](https://codesandbox.io/s/rd3t-v2-custom-with-foreignobject-0mfj8?file=/src/App.js)
221219

222220
### `pathFunc`
223-
TODO
221+
The [`pathFunc` prop](https://bkrem.github.io/react-d3-tree/docs/interfaces/_tree_types_.treeprops.html#pathfunc) accepts a predefined `PathFunctionOption` enum or a user-defined `PathFunction`.
222+
223+
By changing or providing your own `pathFunc`, you are able to change how links between nodes of the tree (which are SVG `path` tags under the hood) are drawn.
224+
225+
The currently [available enums](https://bkrem.github.io/react-d3-tree/docs/modules/_types_common_.html#pathfunctionoption) are:
226+
- `diagonal` (default)
227+
- `elbow`
228+
- `straight`
229+
- `step`
230+
231+
> Want to see how each option looks? [Try them out on the playground](https://bkrem.github.io/react-d3-tree).
232+
233+
#### Providing your own `pathFunc`
234+
If none of the available path functions suit your needs, you're also able to provide a custom `PathFunction`:
235+
236+
```jsx
237+
function CustomPathFuncTree() {
238+
const straightPathFunc = (linkDatum, orientation) => {
239+
const { source, target } = linkDatum;
240+
return orientation === 'horizontal'
241+
? `M${source.y},${source.x}L${target.y},${target.x}`
242+
: `M${source.x},${source.y}L${target.x},${target.y}`;
243+
};
244+
245+
return (
246+
<Tree
247+
data={data}
248+
// Passing `straight` function as a custom `PathFunction`.
249+
pathFunc={straightPathFunc}
250+
/>
251+
);
252+
}
253+
```
254+
255+
> For more details, see the [`PathFunction` reference docs](https://bkrem.github.io/react-d3-tree/docs/modules/_types_common_.html#pathfunction).
224256
225257
## Development
226258
### Setup

0 commit comments

Comments
 (0)