Skip to content
This repository was archived by the owner on Aug 5, 2020. It is now read-only.

Commit e089c62

Browse files
committed
0.0.1
0 parents  commit e089c62

14 files changed

+249
-0
lines changed

.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"stage": 0
3+
}

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
lib
2+
**/node_modules
3+
**/webpack.config.js
4+
examples/**/server.js

.eslintrc

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": "eslint-config-airbnb",
3+
"env": {
4+
"browser": true,
5+
"mocha": true,
6+
"node": true
7+
},
8+
"rules": {
9+
"react/jsx-uses-react": 2,
10+
"react/jsx-uses-vars": 2,
11+
"react/react-in-jsx-scope": 2,
12+
"no-unused-vars": 0
13+
},
14+
"plugins": [
15+
"react"
16+
]
17+
}

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
*.log
3+
.DS_Store
4+
dist
5+
lib
6+
coverage
7+
.idea

.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
*.log
3+
src
4+
test
5+
examples
6+
coverage

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: node_js
2+
node_js:
3+
- "iojs"

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Change log
2+
3+
All notable changes to this project will be documented in this file.
4+
This project adheres to [Semantic Versioning](http://semver.org/).

CODE_OF_CONDUCT.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Contributor Code of Conduct
2+
3+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4+
5+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6+
7+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8+
9+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10+
11+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12+
13+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
14+

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Romain Séguy
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
d3-state-visualizer
2+
=========================

package.json

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "d3-state-visualizer",
3+
"version": "0.0.1",
4+
"description": "Visualize your app state with a range of reusable charts",
5+
"main": "lib/index.js",
6+
"scripts": {
7+
"clean": "rimraf lib dist",
8+
"build": "babel src --out-dir lib",
9+
"build:umd": "webpack src/index.js dist/d3-state-visualizer.js && NODE_ENV=production webpack src/index.js dist/d3-state-visualizer.min.js",
10+
"lint": "eslint src test examples",
11+
"test": "NODE_ENV=test mocha",
12+
"test:watch": "NODE_ENV=test mocha --watch",
13+
"test:cov": "babel-node ./node_modules/.bin/isparta cover ./node_modules/.bin/_mocha",
14+
"prepublish": "npm run lint && npm run clean && npm run build && npm run build:umd"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/romseguy/d3-state-visualizer.git"
19+
},
20+
"keywords": [
21+
"d3",
22+
"state",
23+
"store",
24+
"visualization"
25+
],
26+
"author": "romseguy",
27+
"license": "MIT",
28+
"bugs": {
29+
"url": "https://github.com/romseguy/d3-state-visualizer/issues"
30+
},
31+
"homepage": "https://github.com/romseguy/d3-state-visualizer",
32+
"devDependencies": {
33+
"babel": "^5.5.8",
34+
"babel-core": "^5.6.18",
35+
"babel-eslint": "^3.1.15",
36+
"babel-loader": "^5.1.4",
37+
"eslint": "^0.23",
38+
"eslint-config-airbnb": "0.0.6",
39+
"eslint-plugin-react": "^2.3.0",
40+
"expect": "^1.6.0",
41+
"isparta": "^3.0.3",
42+
"mocha": "^2.2.5",
43+
"rimraf": "^2.3.4",
44+
"webpack": "^1.9.6",
45+
"webpack-dev-server": "^1.8.2"
46+
},
47+
"dependencies": {
48+
"invariant": "^2.0.0",
49+
"lodash": "^3.10.1"
50+
}
51+
}

src/charts/forceGraph.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { isArray } from 'lodash/lang/isArray';
2+
3+
export default function() {
4+
return function graphChart(d3, DOMNode, props) {
5+
const { data, id, size, aspectRatio, charge, linkDistance, maxNodeSize } = props;
6+
const margin = {
7+
top: size / 100,
8+
right: size / 50,
9+
bottom: size / 100,
10+
left: 40
11+
};
12+
const width = size - margin.left - margin.right;
13+
const height = size * aspectRatio - margin.top - margin.bottom;
14+
const fullWidth = size;
15+
const fullHeight = size * aspectRatio;
16+
17+
const root = d3.select(DOMNode);
18+
const vis = root.append('svg')
19+
.attr('id', id)
20+
.attr('preserveAspectRatio', 'xMinYMin slice')
21+
.attr('viewBox', `0 0 ${fullWidth} ${fullHeight}`)
22+
.append('g')
23+
.attr('transform', `translate(${margin.left}, ${margin.top})`);
24+
25+
let node = vis.selectAll('circle');
26+
27+
const force = d3.layout.force()
28+
.size([width, height])
29+
.nodes(data)
30+
.linkDistance(linkDistance)
31+
.charge(charge)
32+
.on('tick', function tick() {
33+
node.attr({
34+
cx: d => Math.round(d.x),
35+
cy: d => Math.round(d.y)
36+
});
37+
});
38+
39+
let nodes = force.nodes();
40+
41+
return function renderChart(nextNodes) {
42+
if (nextNodes) {
43+
nodes = [...nodes, ...nextNodes];
44+
force.nodes(nodes);
45+
}
46+
47+
node = node.data(nodes);
48+
node.enter()
49+
.insert('circle')
50+
.attr({
51+
r: d => {
52+
const datum = d[d.key];
53+
if (!isArray(datum)) return 10;
54+
const radius = 10 + 2 * d[d.key].length;
55+
return radius > maxNodeSize ? 10 : radius;
56+
},
57+
fill: d => isArray(d[d.key]) ? 'blue' : 'red'
58+
})
59+
.on({
60+
mouseover: function nodeMouseover() {
61+
d3.select(this).style('fill-opacity', '0.5');
62+
},
63+
mouseout: function nodeMouseout() {
64+
d3.select(this).style('fill-opacity', '1');
65+
}
66+
})
67+
.call(force.drag);
68+
node.exit().remove();
69+
70+
force.start();
71+
};
72+
};
73+
}

src/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import forceGraph from './charts/forceGraph';
2+
3+
export default {
4+
forceGraph
5+
};

webpack.config.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
var webpack = require('webpack');
4+
5+
var plugins = [
6+
new webpack.optimize.OccurenceOrderPlugin(),
7+
new webpack.DefinePlugin({
8+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
9+
})
10+
];
11+
12+
if (process.env.NODE_ENV === 'production') {
13+
plugins.push(
14+
new webpack.optimize.UglifyJsPlugin({
15+
compressor: {
16+
screw_ie8: true,
17+
warnings: false
18+
}
19+
})
20+
);
21+
}
22+
23+
module.exports = {
24+
module: {
25+
loaders: [{
26+
test: /\.js$/,
27+
loaders: ['babel-loader'],
28+
exclude: /node_modules/
29+
}]
30+
},
31+
output: {
32+
library: 'd3-state-visualizer',
33+
libraryTarget: 'umd'
34+
},
35+
plugins: plugins,
36+
resolve: {
37+
extensions: ['', '.js']
38+
}
39+
};

0 commit comments

Comments
 (0)