-
-
Save mattbaker/c3040fd5e0768fb1c684 to your computer and use it in GitHub Desktop.
Ex. 4 in Reactive Bar Chart Article
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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