Skip to content

Commit

Permalink
Refactor to expose standard reusable chart api
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwalley committed Nov 19, 2017
1 parent cc87448 commit f37377d
Show file tree
Hide file tree
Showing 21 changed files with 1,739 additions and 3,023 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2016 John Walley
Copyright 2017 John Walley
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ If you use NPM, `npm install d3-bumps-chart`. Otherwise, download the [latest re

<script>
var el = document.getElementById('bumps-chart');
var chart = d3.chart();
chart.setup(el);
var chart = d3.bumpsChart();
d3.json("./example/results.json", function(error, events) {
Expand All @@ -42,21 +41,17 @@ If you use NPM, `npm install d3-bumps-chart`. Otherwise, download the [latest re
windowWidth: window.width
};
chart.update(props);
d3.select(el).datum(props).call(chart);
});
</script>
```

## API Reference

<a name="chart" href="#chart">#</a> d3.<b>chart</b>() [<>](https://github.com/johnwalley/d3-bumps-chart/blob/master/src/chart.js "Source")
<a name="bumpsChart" href="#bumpsChart">#</a> d3.<b>bumpsChart</b>() [<>](https://github.com/johnwalley/d3-bumps-chart/blob/master/src/chart.js "Source")

Constructs a new bumps chart generator with the default settings.

<a name="chart_setup" href="#chart_setup">#</a> <i>chart</i>.<b>setup</b>(<i>element</i>) [<>](https://github.com/johnwalley/d3-bumps-chart/blob/master/src/chart.js#L16 "Source")
<a name="bumpsChart" href="#bumpsChart">#</a> <i>bumpsChart</i>(<i>selection</i>) [<>](https://github.com/johnwalley/d3-tube-map/blob/master/src/map.js#L32 "Source")

Sets up the svg elements which are independent of any data. Selects the *element* passed in.

<a name="chart_update" href="#chart_update">#</a> <i>chart</i>.<b>update</b>(<i>props</i>) [<>](https://github.com/johnwalley/d3-bumps-chart/blob/master/src/chart.js#L28 "Source")

Renders the bumps chart based on *props*.
Render the bumps chart to the given *selection*, which is a [selection](https://github.com/d3/d3-selection).
4 changes: 2 additions & 2 deletions example/bumps.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
body {
font-family: 'Roboto', sans-serif;
margin: 0;
font-family: 'Roboto', sans-serif;
margin: 0;
}
10 changes: 4 additions & 6 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
</svg>
</div>
<script>
var el = document.getElementById('bumps-chart');
var chart = d3.chart();

chart.setup(el);

d3.json("./results.json", function (error, events) {
var gender = "Women";
var set = "Town Bumps";
var el = document.getElementById('bumps-chart');

var chart = d3.bumpsChart();

var transformedEvents = events
.filter(e => e.gender.toLowerCase() === gender.toLowerCase())
Expand All @@ -41,7 +39,7 @@
windowWidth: window.document.body.clientWidth
};

chart.render(props);
d3.select(el).datum(props).call(chart);
});
</script>
</body>
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export {default as chart} from "./src/chart";
export * from "./src/util";
export { default as bumpsChart } from './src/chart';
export * from './src/util';
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"name": "d3-bumps-chart",
"version": "0.7.0",
"version": "0.8.0",
"description": "Draw bumps charts.",
"keywords": ["d3", "d3-module", "bumps"],
"keywords": [
"d3",
"d3-module",
"bumps"
],
"homepage": "https://github.com/johnwalley/d3-bumps-chart/",
"license": "BSD-3-Clause",
"author": {
Expand All @@ -17,19 +21,15 @@
"url": "https://github.com/johnwalley/d3-bumps-chart.git"
},
"scripts": {
"pretest":
"rm -rf build && mkdir build && rollup -c -f umd -n d3 -o build/d3-bumps-chart.js --extend -- index.js",
"pretest": "rm -rf build && mkdir build && rollup -c -f umd -n d3 -o build/d3-bumps-chart.js --extend -- index.js",
"test": "tape test/**/*-test.js && eslint index.js src",
"prepublish":
"npm run test && uglifyjs --preamble \"$(preamble)\" build/d3-bumps-chart.js -c -m -o build/d3-bumps-chart.min.js",
"postpublish":
"zip -j build/d3-bumps-chart.zip -- LICENSE README.md build/d3-bumps-chart.js build/d3-bumps-chart.min.js"
"prepublish": "npm run test && uglifyjs --preamble \"$(preamble)\" build/d3-bumps-chart.js -c -m -o build/d3-bumps-chart.min.js",
"postpublish": "zip -j build/d3-bumps-chart.zip -- LICENSE README.md build/d3-bumps-chart.js build/d3-bumps-chart.min.js"
},
"dependencies": {
"d3-array": "^1.2.0",
"d3-dsv": "^1.0.5",
"d3-scale": "^1.0.6",
"d3-selection": "^1.1.0",
"d3-shape": "^1.2.0",
"d3-transition": "^1.1.0",
"hammerjs": "^2.0.8",
Expand Down
8 changes: 4 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export default {
external: ['hammerjs'],
plugins: [
babel({
exclude: 'node_modules/**'
exclude: 'node_modules/**',
}),
nodeResolve({
jsnext: true,
main: true
main: true,
}),
]
};
],
};
2 changes: 1 addition & 1 deletion src/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
}
]
]
}
}
Loading

0 comments on commit f37377d

Please sign in to comment.