Skip to content

Commit 7d53d10

Browse files
authored
Feature/graph component decoupling (#2)
* Add eslint to project * Start Node component * Small folder structure refactor * Rendering graph of Node components * Add Link component * Render nodes and links. Add helpers in Graph component * Refactor Graph component. Move init props to constructor * Add forceSimulation and apply tick via react forceUpdate * Huge refactor in Node component. Passing props * Small refactor in Link component * Fix pause/play simulation behavior * Move node and link build logic to graph helper file * Add zoom to graph. Add drag and drop all network * Removed unused react-redux dependency * Clean the house 🛀 * Remove css-loader * Small improvements * Remove render first time logic * Add node drag to Graph component * Move coords to static object. Some comments in Graph component * Drag & Drop sticky nodes behavior. Add button for reset nodes positions * Improve setState method calls. Use pseudo private syntax for methods in Graph component * Remove lodash dependency * Remove unused configs from webpack.config * Add node event handlers as callbacks * Add callback for Link click * Remove style file in Node * Remove style from Link component * Add arrange graph after node drag property to graph configs * Add node helper. Add node configurable symbol type * Pass on some more node properties * Fix callbacks reference now in props in Node component * Expose Link component style properties * Add fallback cases for x and y props in nodes * Graph properties config refactor * Merging configurations properly * Remove unused property. Remove lodash dependency * Add property conditionally render node label * Add configurable staticGraph property to disable graph forces and drag interactions * Remove unused property pause from Graph component * Remove path props from Node render method. Move hardcoded class names to const file * Add documentation.js. Add npm task to generate docs * Standardize imports order in js files * Transform Link and Node component into really dumb components * Add configurable highlight and opacity behavior to graph * Remove labelDx property. Add labelDx to Node constants file * Normalize config file to the default graph configuration * Add link highlight property. Add new demo config example * Delete unused coords. Delete buildCoords unused function * Pass callbacks onto Demo component. Remove forceUpdate calls * Move buttons for Demo component. Small fix in Node component class name * Implement pause, play and reset nodes positions in Demo component * Fix lint task. Fix lint errors * Small refactor on Graph constructor. Move code to GraphHelper * Unified ids. The id is always converted to string type for sake of consistency * Fix drag. Support many graph instances. Id for graph. Add error logging * Add Demo mock file miserables
1 parent baa31f2 commit 7d53d10

26 files changed

+2921
-945
lines changed

.eslintrc.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
"parser": "babel-eslint",
3+
"extends": [
4+
"eslint:recommended"
5+
],
6+
"plugins": [
7+
"standard",
8+
"promise",
9+
"react"
10+
],
11+
"parserOptions": {
12+
"ecmaFeatures": {
13+
"jsx": true
14+
}
15+
},
16+
"rules": {
17+
"react/jsx-uses-react": "error",
18+
"react/jsx-uses-vars": "error"
19+
},
20+
"globals": {
21+
"document": true,
22+
"Reflect": true,
23+
"window": true
24+
}
25+
};

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,7 @@ dist/
6767
# End of https://www.gitignore.io/api/node
6868

6969

70-
src/mock.js
71-
src/mock.xl.js
70+
src/mock/mock.js
71+
src/mock/mock.xl.js
72+
DOCUMENTATION.md
73+
docs

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# react-d3-graph
22
Interactive and configurable graphs with react and d3 effortlessly
3+
4+
## Tips
5+
- Obtain a cool node when set the fill property as white a other color for the border. It will seem like the node is more like a ring.

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
"babel-preset-es2015": "latest",
1616
"babel-preset-react": "latest",
1717
"babel-preset-stage-0": "latest",
18-
"css-loader": "latest",
1918
"d3": "^4.7.4",
19+
"documentation": "^4.0.0-beta.18",
20+
"eslint": "^3.18.0",
21+
"eslint-config-recommended": "^1.5.0",
22+
"eslint-plugin-promise": "^3.5.0",
23+
"eslint-plugin-standard": "^2.1.1",
2024
"html-webpack-plugin": "^2.28.0",
21-
"lodash": "latest",
2225
"react": "latest",
2326
"react-dom": "latest",
24-
"react-redux": "latest",
2527
"react-router-dom": "^4.0.0",
2628
"react-spinkit": "^2.1.1",
2729
"redux": "latest",
@@ -36,6 +38,8 @@
3638
"devDependencies": {},
3739
"scripts": {
3840
"dev": "./node_modules/.bin/webpack-dev-server -d --content-base src --inline --hot --port 3002",
41+
"docs": "node_modules/documentation/bin/documentation.js build src/**/*.js -f html -o docs && node_modules/documentation/bin/documentation.js build src/**/*.js -f md > DOCUMENTATION.md",
42+
"lint": "node_modules/eslint/bin/eslint.js --config=.eslintrc.js \"src/**/*.js\"",
3943
"test": "echo \"Error: no test specified\" && exit 1"
4044
}
4145
}

src/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<!DOCTYPE html>
22
<html>
3-
<head>
3+
<head>
44
<meta charset="utf-8">
55
<title>react-d3-graph</title>
6-
</head>
6+
</head>
77

8-
<body>
8+
<body>
99
<div id="app"></div>
1010
<script src="rd3g.bundle.js"></script>
11-
</body>
11+
</body>
1212
</html>

src/js/app.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import {
4+
BrowserRouter as Router,
5+
Route
6+
} from 'react-router-dom';
7+
8+
import Demo from './components/Demo';
9+
10+
const app = document.getElementById('app');
11+
12+
ReactDOM.render(
13+
<Router>
14+
<div>
15+
<Route path='/' component={Demo}/>
16+
</div>
17+
</Router>
18+
, app);

src/js/client.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/js/components/Demo.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import React from 'react';
2+
3+
import graphMock from '../../mock/miserables';
4+
5+
import Graph from './Graph/';
6+
7+
export default class Layout extends React.Component {
8+
9+
onClickNode = (id) => window.alert(`clicked node ${id}`);
10+
11+
onClickLink = (source, target) => window.alert(`clicked link between ${source} and ${target}`);
12+
13+
onMouseOverNode = () => {
14+
// Do something with the node identifier ...
15+
}
16+
17+
onMouseOutNode = () => {
18+
// Do something with the node identifier ...
19+
}
20+
21+
pauseGraphSimulation = () => this.refs.graph.pauseSimulation();
22+
23+
restartGraphSimulation = () => this.refs.graph.restartSimulation();
24+
25+
resetNodesPositions = () => this.refs.graph.resetNodesPositions();
26+
27+
render() {
28+
const width = window.innerWidth - 50;
29+
const graphProps = {
30+
id: 'graph',
31+
data: graphMock.graph || graphMock,
32+
config: {
33+
width,
34+
height: 600,
35+
highlightOpacity: 0.12,
36+
highlightBehavior: true,
37+
node: {
38+
color: '#4286f4',
39+
highlightFontSize: 14,
40+
highlightFontWeight: 'bold',
41+
highlightStrokeColor: '#8f41f4',
42+
highlightStrokeWidth: 2,
43+
labelProperty: 'uid',
44+
size: 100,
45+
strokeColor: 'white'
46+
},
47+
link: {
48+
highlightColor: '#8f41f4',
49+
strokeWidth: 1
50+
}
51+
},
52+
onClickNode: this.onClickNode,
53+
onClickLink: this.onClickLink,
54+
onMouseOverNode: this.onMouseOverNode,
55+
onMouseOutNode: this.onMouseOutNode
56+
};
57+
58+
const graphWrapperStyle = {
59+
border: '1px solid black',
60+
marginTop: '25px',
61+
width
62+
};
63+
64+
return (
65+
<div>
66+
<h1>react-d3-graph</h1>
67+
<h2>Work in progress <span>🔨👷</span></h2>
68+
<button onClick={this.restartGraphSimulation}>▶️</button>
69+
<button onClick={this.pauseGraphSimulation}></button>
70+
<button onClick={this.resetNodesPositions}>Unstick nodes</button>
71+
<div style={graphWrapperStyle}>
72+
<Graph ref='graph' {...graphProps}/>
73+
</div>
74+
</div>
75+
);
76+
}
77+
}

0 commit comments

Comments
 (0)