Skip to content

Instantly share code, notes, and snippets.

@DeBraid
Created February 28, 2014 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeBraid/9262903 to your computer and use it in GitHub Desktop.
Save DeBraid/9262903 to your computer and use it in GitHub Desktop.
reusable API snippet
{"description":"reusable API snippet","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01}
// using datum to bind multiple array
// pattern allows us to create 1 section to draw the charts
// and pass it complex data (2, 3, n-element arrays)
// and it will just draw the chart
/*
Links:
http://bl.ocks.org/biovisualize/5372077
*/
var foo = [70, 30, 60];
var bar = [33, 44, 55];
var baz = [31,12,43];
var data = [foo, bar, baz];
var canvas = d3.select("svg").attr({"height", width});
canvas.selectAll('div')
.data().enter()
.datum(function(d){ return d})
.call(reusable chart function barChart(););
// combine the above with:
function exports (_selection) {
_selection.each(function (_data) {
// d3 charting code here
// ..
// margins, scales, axes, etc
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment