Skip to content

Commit 772f39e

Browse files
committed
Merge branch 'hotfix/v0.3.1' into develop
2 parents ce57518 + d650e4e commit 772f39e

File tree

5 files changed

+42
-18
lines changed

5 files changed

+42
-18
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
insert_final_newline = true
9+
indent_style = space
10+
indent_size = 2
11+
trim_trailing_whitespace = true
12+
13+
[*.md]
14+
trim_trailing_whitespace = false

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
# React D3 Tree
22
[![Build Status](https://travis-ci.org/bkrem/react-d3-tree.svg?branch=master)](https://travis-ci.org/bkrem/react-d3-tree)
3-
[![Coverage Status](https://coveralls.io/repos/github/bkrem/react-d3-tree/badge.svg?branch=master)](https://coveralls.io/github/bkrem/react-d3-tree?branch=master)
3+
[![Coverage Status](https://coveralls.io/repos/github/bkrem/react-d3-tree/badge.svg?branch=master)](https://coveralls.io/github/bkrem/react-d3-tree?branch=master)
4+
[![npm](https://img.shields.io/npm/v/react-d3-tree.svg)](https://www.npmjs.com/package/react-d3-tree)
45

56
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.
67

8+
## Contents
9+
- [Demo](#demo)
10+
- [Installation](#installation)
11+
- [Minimal example](#minimal-example)
12+
- [Props](#props)
13+
714
## Demo
815
- Current release (stable): https://bkrem.github.io/react-d3-tree/
916

lib/react-d3-tree.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-d3-tree",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"description": "React component to create interactive D3 tree hierarchies",
55
"main": "lib/react-d3-tree.min.js",
66
"scripts": {

src/Tree/index.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class Tree extends React.Component {
1616
data: this.assignInternalProperties(clone(this.props.data)),
1717
zoom: undefined,
1818
};
19-
this.findTargetNode = this.findTargetNode.bind(this);
19+
this.findNodesById = this.findNodesById.bind(this);
2020
this.collapseNode = this.collapseNode.bind(this);
2121
this.handleNodeToggle = this.handleNodeToggle.bind(this);
2222
}
@@ -100,29 +100,31 @@ export default class Tree extends React.Component {
100100

101101

102102
/**
103-
* findTargetNode - Recursively walks a set of nodes (`nodeSet`) and its
104-
* children until a `node.id` that matches `nodeId` param is found.
103+
* findNodesById - Description
105104
*
106-
* @param {string} nodeId The `node.id` being searched for
105+
* @param {string} nodeId The `node.id` being searched for
107106
* @param {array} nodeSet Array of `node` objects
107+
* @param {array} hits Accumulator for matches, passed between recursive calls
108108
*
109-
* @return {object} Returns the targeted `node` object
109+
* @return {array} Set of nodes matching `nodeId`
110110
*/
111111
// TODO Refactor this into a more readable/reasonable recursive depth-first walk.
112-
findTargetNode(nodeId, nodeSet) {
113-
const hits = nodeSet.filter((node) => node.id === nodeId);
114-
112+
findNodesById(nodeId, nodeSet, hits) {
115113
if (hits.length > 0) {
116-
const targetNode = hits[0];
117-
return targetNode;
114+
return hits;
118115
}
119116

120-
return nodeSet.map((node) => {
117+
hits = hits.concat(nodeSet.filter((node) => node.id === nodeId));
118+
119+
nodeSet.forEach((node) => {
121120
if (node._children && node._children.length > 0) {
122-
return this.findTargetNode(nodeId, node._children);
121+
hits = this.findNodesById(nodeId, node._children, hits);
122+
return hits;
123123
}
124-
return null;
125-
})[0];
124+
return hits;
125+
});
126+
127+
return hits;
126128
}
127129

128130

@@ -169,7 +171,8 @@ export default class Tree extends React.Component {
169171
handleNodeToggle(nodeId) {
170172
if (this.props.collapsible) {
171173
const data = clone(this.state.data);
172-
const targetNode = this.findTargetNode(nodeId, data);
174+
const matches = this.findNodesById(nodeId, data, []);
175+
const targetNode = matches[0];
173176
targetNode._collapsed
174177
? this.expandNode(targetNode)
175178
: this.collapseNode(targetNode);

0 commit comments

Comments
 (0)