Skip to content

Instantly share code, notes, and snippets.

@mattbaker
Last active December 16, 2015 08:49
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 mattbaker/c3040fd5e0768fb1c684 to your computer and use it in GitHub Desktop.
Save mattbaker/c3040fd5e0768fb1c684 to your computer and use it in GitHub Desktop.
Ex. 4 in Reactive Bar Chart Article
function BarChart(svg) {
this.width = $R.state(200);
this.height = $R.state(200);
this.data = $R.state([]);
var y = $R(BarChart.y, this).bindTo(this.height, this.data);
var x = $R(BarChart.x, this).bindTo(this.width, this.data);
}
BarChart.y = function (height, data) {
return d3.scale.linear()
.domain([0, d3.max(data, function(d) { return d.value })])
.range([height, 0]);
}
BarChart.x = function (width, data) {
return d3.scale.ordinal()
.domain(d3.range(0, data.length))
.rangeRoundBands([0, width], .1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment