Skip to content

Commit adecadb

Browse files
committed
Merge branch 'release/v0.4.0'
2 parents fd7a83b + d1c315d commit adecadb

File tree

13 files changed

+828
-15
lines changed

13 files changed

+828
-15
lines changed

.eslintrc.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,7 @@ module.exports = {
5858
"no-console": 1,
5959
"no-param-reassign": "warn",
6060
"no-use-before-define": 0,
61-
"no-underscore-dangle": [
62-
"error",
63-
{
64-
"allow": [
65-
"_children",
66-
"_collapsed"
67-
]
68-
}
69-
],
61+
"no-underscore-dangle": "off",
7062
"no-unused-expressions": "warn",
7163
"prefer-template": 2,
7264
"class-methods-use-this": 0,
@@ -79,5 +71,6 @@ module.exports = {
7971
"react/jsx-no-target-blank": 0,
8072
"react/require-extension": 0,
8173
"react/self-closing-comp": 0,
74+
"require-jsdoc": "warn"
8275
},
8376
};

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: node_js
22

33
node_js:
4+
- 8
45
- 7
56
- 6
67
- 5
@@ -18,4 +19,4 @@ after_success: 'npm run coveralls'
1819

1920
cache:
2021
directories:
21-
- node_modules
22+
- node_modules

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@
55

66
React D3 Tree is a [React](http://facebook.github.io/react/) component that lets you represent hierarchical data (e.g. ancestor trees, organisational structure, package dependencies) as an animated & interactive tree graph by leveraging [D3](https://d3js.org/)'s `tree` layout.
77

8+
89
## Contents
910
- [Demo](#demo)
1011
- [Installation](#installation)
1112
- [Minimal example](#minimal-example)
1213
- [Props](#props)
1314

15+
1416
## Demo
1517
- Current release (stable): https://bkrem.github.io/react-d3-tree/
1618

19+
1720
## Installation
1821
To install via NPM, run:
1922
```bash
2023
npm i --save react-d3-tree
2124
```
2225

26+
2327
## Minimal example
2428
```jsx
2529
import Tree from 'react-d3-tree';
@@ -65,6 +69,7 @@ class MyComponent extends Component {
6569
}
6670
```
6771

72+
6873
## Props
6974
| Property | Type | Options | Required? | Default | Description |
7075
|----------------|-----------------|-------------------------|-----------|-------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -77,3 +82,46 @@ class MyComponent extends Component {
7782
| `zoomable` | `bool` | | | `true` | Toggles ability to zoom in/out on the Tree by scaling the SVG element according to `props.scaleExtent`. |
7883
| `scaleExtent` | `object` | | | `{min: 0.1, max: 1}` | Sets the minimum/maximum extent to which the tree can be scaled if `props.zoomable` is true. |
7984
| `depthFactor` | `number` | `-n..0..n` | | `undefined` | Ensures the tree takes up a fixed amount of space (`node.y = node.depth * depthFactor`), regardless of tree depth. <br /> **TIP**: Negative values invert the tree's direction. |
85+
86+
87+
## External data sources
88+
Statically hosted JSON or CSV files can be used as data sources via the additional `treeUtil` module.
89+
90+
### Example
91+
92+
```jsx
93+
import { Tree, treeUtil } from 'react-d3-tree';
94+
95+
const csvSource = 'https://raw.githubusercontent.com/bkrem/react-d3-tree/feature/add-csv-to-json-transform/examples/data/csv-example.csv';
96+
97+
constructor() {
98+
super();
99+
100+
this.state = {
101+
data: undefined,
102+
};
103+
104+
componentWillMount() {
105+
treeUtil.parseCSV(csvSource)
106+
.then((data) => {
107+
this.setState({ data })
108+
})
109+
.catch((err) => console.error(err));
110+
}
111+
112+
class MyComponent extends Component {
113+
render() {
114+
return (
115+
     {/* <Tree /> will fill width/height of its container; in this case `#treeWrapper` */}
116+
<div id="treeWrapper" style={{width: '50em', height: '20em'}}>
117+
118+
<Tree data={this.state.data} />
119+
120+
</div>
121+
);
122+
}
123+
}
124+
```
125+
126+
For details regarding the `treeUtil` module, please check the module's [API docs](docs/util/util.md).
127+
For examples of each data type that can be parsed with `treeUtil`, please check the [data source examples](docs/examples/data).

docs/components/Node.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ defaultValue: `{
2222
}`
2323

2424

25+
### `depthFactor`
26+
27+
type: `number`
28+
29+
2530
### `leafCircleStyle`
2631

2732
type: `object`

docs/components/Tree.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ defaultValue: `true`
1717
type: `array`
1818

1919

20+
### `depthFactor`
21+
22+
type: `number`
23+
defaultValue: `undefined`
24+
25+
2026
### `initialDepth`
2127

2228
type: `number`
@@ -35,8 +41,20 @@ type: `enum('diagonal'|'elbow')`
3541
defaultValue: `'diagonal'`
3642

3743

44+
### `scaleExtent`
45+
46+
type: `shape[object Object]`
47+
defaultValue: `{ min: 0.1, max: 1 }`
48+
49+
3850
### `translate`
3951

4052
type: `shape[object Object]`
4153
defaultValue: `{ x: 0, y: 0 }`
4254

55+
56+
### `zoomable`
57+
58+
type: `bool`
59+
defaultValue: `true`
60+

docs/examples/data/csv-example.csv

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
parent,child,CSV Attribute A,CSV Attribute B
2+
"CSVNode1","CSVNode2",22,someValue
3+
"CSVNode1","CSVNode3",23,someValue
4+
"CSVNode2","CSVNode4",1,someValue
5+
"CSVNode2","CSVNode5",2,someValue
6+
"CSVNode2","CSVNode6",3,someValue
7+
"CSVNode2","CSVNode7",4,someValue
8+
"CSVNode2","CSVNode8",5,someValue
9+
"CSVNode2","CSVNode9",6,someValue
10+
"CSVNode2","CSVNode10",7,someValue
11+
"CSVNode4","CSVNode11",8,someValue
12+
"CSVNode7","CSVNode12",9,someValue
13+
"CSVNode9","CSVNode13",10,someValue
14+
"CSVNode10","CSVNode14",11,someValue
15+
"CSVNode11","CSVNode15",12,someValue
16+
"CSVNode3","CSVNode16",13,someValue
17+
"CSVNode16","CSVNode17",14,someValue
18+
"CSVNode16","CSVNode18",15,someValue
19+
"CSVNode16","CSVNode19",16,someValue
20+
"CSVNode16","CSVNode20",17,someValue
21+
"CSVNode17","CSVNode21",18,someValue
22+
"CSVNode18","CSVNode22",19,someValue
23+
"CSVNode19","CSVNode23",20,someValue
24+
"CSVNode20","CSVNode24",21,someValue
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
[{
2+
"parent": "CSVNode1",
3+
"child": "CSVNode2",
4+
"FlatJSON Attribute A": "22",
5+
"FlatJSON Attribute B": "someValue"
6+
}, {
7+
"parent": "CSVNode1",
8+
"child": "CSVNode3",
9+
"FlatJSON Attribute A": "23",
10+
"FlatJSON Attribute B": "someValue"
11+
}, {
12+
"parent": "CSVNode2",
13+
"child": "CSVNode4",
14+
"FlatJSON Attribute A": "1",
15+
"FlatJSON Attribute B": "someValue"
16+
}, {
17+
"parent": "CSVNode2",
18+
"child": "CSVNode5",
19+
"FlatJSON Attribute A": "2",
20+
"FlatJSON Attribute B": "someValue"
21+
}, {
22+
"parent": "CSVNode2",
23+
"child": "CSVNode6",
24+
"FlatJSON Attribute A": "3",
25+
"FlatJSON Attribute B": "someValue"
26+
}, {
27+
"parent": "CSVNode2",
28+
"child": "CSVNode7",
29+
"FlatJSON Attribute A": "4",
30+
"FlatJSON Attribute B": "someValue"
31+
}, {
32+
"parent": "CSVNode2",
33+
"child": "CSVNode8",
34+
"FlatJSON Attribute A": "5",
35+
"FlatJSON Attribute B": "someValue"
36+
}, {
37+
"parent": "CSVNode2",
38+
"child": "CSVNode9",
39+
"FlatJSON Attribute A": "6",
40+
"FlatJSON Attribute B": "someValue"
41+
}, {
42+
"parent": "CSVNode2",
43+
"child": "CSVNode10",
44+
"FlatJSON Attribute A": "7",
45+
"FlatJSON Attribute B": "someValue"
46+
}, {
47+
"parent": "CSVNode4",
48+
"child": "CSVNode11",
49+
"FlatJSON Attribute A": "8",
50+
"FlatJSON Attribute B": "someValue"
51+
}, {
52+
"parent": "CSVNode7",
53+
"child": "CSVNode12",
54+
"FlatJSON Attribute A": "9",
55+
"FlatJSON Attribute B": "someValue"
56+
}, {
57+
"parent": "CSVNode9",
58+
"child": "CSVNode13",
59+
"FlatJSON Attribute A": "10",
60+
"FlatJSON Attribute B": "someValue"
61+
}, {
62+
"parent": "CSVNode10",
63+
"child": "CSVNode14",
64+
"FlatJSON Attribute A": "11",
65+
"FlatJSON Attribute B": "someValue"
66+
}, {
67+
"parent": "CSVNode11",
68+
"child": "CSVNode15",
69+
"FlatJSON Attribute A": "12",
70+
"FlatJSON Attribute B": "someValue"
71+
}, {
72+
"parent": "CSVNode3",
73+
"child": "CSVNode16",
74+
"FlatJSON Attribute A": "13",
75+
"FlatJSON Attribute B": "someValue"
76+
}, {
77+
"parent": "CSVNode16",
78+
"child": "CSVNode17",
79+
"FlatJSON Attribute A": "14",
80+
"FlatJSON Attribute B": "someValue"
81+
}, {
82+
"parent": "CSVNode16",
83+
"child": "CSVNode18",
84+
"FlatJSON Attribute A": "15",
85+
"FlatJSON Attribute B": "someValue"
86+
}, {
87+
"parent": "CSVNode16",
88+
"child": "CSVNode19",
89+
"FlatJSON Attribute A": "16",
90+
"FlatJSON Attribute B": "someValue"
91+
}, {
92+
"parent": "CSVNode16",
93+
"child": "CSVNode20",
94+
"FlatJSON Attribute A": "17",
95+
"FlatJSON Attribute B": "someValue"
96+
}, {
97+
"parent": "CSVNode17",
98+
"child": "CSVNode21",
99+
"FlatJSON Attribute A": "18",
100+
"FlatJSON Attribute B": "someValue"
101+
}, {
102+
"parent": "CSVNode18",
103+
"child": "CSVNode22",
104+
"FlatJSON Attribute A": "19",
105+
"FlatJSON Attribute B": "someValue"
106+
}, {
107+
"parent": "CSVNode19",
108+
"child": "CSVNode23",
109+
"FlatJSON Attribute A": "20",
110+
"FlatJSON Attribute B": "someValue"
111+
}, {
112+
"parent": "CSVNode20",
113+
"child": "CSVNode24",
114+
"FlatJSON Attribute A": "21",
115+
"FlatJSON Attribute B": "someValue"
116+
}]

0 commit comments

Comments
 (0)