Skip to content

Commit 7424903

Browse files
committed
Minor adjustments for individual nodeSvgShape
Correct syntax in example snippet Ensure correct merge order of node styles Renames `nodeData.shape` -> `nodeData.nodeSvgShape` Avoids awkward `shape.shape` property access & unifies naming convention
1 parent 4118288 commit 7424903

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ This is to prevent breaking the legacy usage of `circleRadius` + styling via `no
141141

142142

143143
### Individual `shapeProps`
144-
`shapeProps` can be passed to a given node individually. The shape is optionally added as `shape` property to input data. This allows for setting style, shape and size of nodes independently (see [Styling](#styling)).
144+
`shapeProps` can be passed to a node individually by adding the `nodeSvgShape` property to the relevant node's data set. This allows setting each node's style, shape and size independently of the tree's overall `shapeProps` configuration (see [Styling](#styling)).
145145

146146
The usage example above can be extended to include individual `shapeProps`:
147147
```jsx
@@ -156,7 +156,7 @@ const myTreeData = [
156156
keyB: 'val B',
157157
keyC: 'val C',
158158
},
159-
shape: {
159+
nodeSvgShape: {
160160
shapeProps: {
161161
fill: 'blue',
162162
},
@@ -169,14 +169,14 @@ const myTreeData = [
169169
keyB: 'val B',
170170
keyC: 'val C',
171171
},
172-
shape: {
172+
nodeSvgShape: {
173173
shape: 'rect',
174174
shapeProps: {
175175
width: 20,
176176
height: 20,
177177
x: -10,
178178
y: -10,
179-
fill: red,
179+
fill: 'red',
180180
},
181181
},
182182
},

src/Node/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ export default class Node extends React.Component {
8484
return nodeSvgShape.shape === 'none'
8585
? null
8686
: React.createElement(nodeSvgShape.shape, {
87-
...nodeSvgShape.shapeProps,
8887
...nodeStyle.circle,
88+
...nodeSvgShape.shapeProps,
8989
});
9090
}
9191

src/Tree/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ export default class Tree extends React.Component {
385385
{nodes.map(nodeData => (
386386
<Node
387387
key={nodeData.id}
388-
nodeSvgShape={{ ...nodeSvgShape, ...nodeData.shape }}
388+
nodeSvgShape={{ ...nodeSvgShape, ...nodeData.nodeSvgShape }}
389389
nodeLabelComponent={nodeLabelComponent}
390390
nodeSize={nodeSize}
391391
orientation={orientation}

src/Tree/tests/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('<Tree />', () => {
3434

3535
it('passes individual `shapeProps` to the specified <Node /> only', () => {
3636
const svgShapeMock = {
37-
shape: 'circle',
37+
shape: 'rect',
3838
shapeProps: {
3939
r: 3,
4040
fill: 'red',
@@ -44,7 +44,7 @@ describe('<Tree />', () => {
4444
{
4545
name: 'Top Level',
4646
parent: 'null',
47-
shape: svgShapeMock,
47+
nodeSvgShape: svgShapeMock,
4848
children: [
4949
{
5050
name: 'Inner',

0 commit comments

Comments
 (0)