Is there a way to limit the size of the brush, although the size is larger?
I only assembled a brush with size x, which can be moved and resized. I would like to be able to limit the extent to which it can be changed by the user (basically only to a certain point).
In the following example, the brush function stops updating when the brush becomes more than half the maximum. However, the brush itself can still be expanded. Is there any way to prevent this? Or is there a better way to handle this?
Thank you very much!
See this code in action here: http://bl.ocks.org/3691274 ( EDIT : this demo now works)
bar = function(range) { var x_range = d3.scale.linear() .domain([0, range.length]) .range([0, width]); svg.selectAll("rect.items").remove(); svg.selectAll("rect.items") .data(range) .enter().append("svg:rect") .attr("class", "items") .attr("x", function(d, i) {return x_range(i);}) .attr("y", 0) .attr("width", width/range.length-2) .attr("height", 100) .attr("fill", function(d) {return d}) .attr("title", function(d) {return d}); } var start = 21; bar(data.slice(0, start), true); var control_x_range = d3.scale.linear() .domain([0, data.length]) .range([0, width]); controlBar = svg.selectAll("rect.itemsControl") .data(data) .enter().append("svg:rect") .attr("class", "itemsControl") .attr("x", function(d, i) {return control_x_range(i);}) .attr("y", 110) .attr("width", width/data.length-2) .attr("height", 20) .attr("fill", function(d) {return d}); svg.append("g") .attr("class", "brush") .call(d3.svg.brush().x(d3.scale.linear().range([0, width])) .extent([0,1*start/data.length]) .on("brush", brush)) .selectAll("rect") .attr("y", 110) .attr("height", 20); function brush() { var s = d3.event.target.extent(); if (s[1]-s[0] < 0.5) { var start = Math.round((data.length-1)*s[0]); var end = Math.round((data.length-1)*s[1]); bar(data.slice(start,end)); }; }