Created
September 5, 2013 07:44
-
-
Save samselikoff/6447128 to your computer and use it in GitHub Desktop.
Brush function for d3.js that redraws the vertical axis based on the range of data currently shown
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 brush() { | |
// Use x.domain to filter the data, then find the max and min duration of this new set, and set y.domain to that | |
x.domain(brush.empty() ? x2.domain() : brush.extent()); | |
var dataFiltered = data.filter(function(d, i) { | |
if ( (d.date >= x.domain()[0]) && (d.date <= x.domain()[1]) ) { | |
return this; | |
} | |
}) | |
var buildersFiltered = color.domain().map(function(name) { | |
return { | |
name: name, | |
values: dataFiltered.map(function(d) { | |
return {date: d.date, count: +d[name]}; | |
}) | |
}; | |
}); | |
y.domain([ | |
d3.min(buildersFiltered, function(c) { return d3.min(c.values, function(v) { return v.count; }); }), | |
d3.max(buildersFiltered, function(c) { return d3.max(c.values, function(v) { return v.count; }); }) | |
]); | |
focus.selectAll(".builder").select("path").attr("d", function(d) { return line(d.values); }) | |
focus.select(".x.axis").call(xAxis); | |
focus.select(".y.axis").call(yAxis); | |
// focus.select("path").attr("d", area); | |
// focus.select(".x.axis").call(xAxis); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment