Sha256: 3b64612619cff313e3f2059e70eaec2d882fe8961996d081352e762d27a77b58
Contents?: true
Size: 1.86 KB
Versions: 25
Compression:
Stored size: 1.86 KB
Contents
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Brush</title> <script type="text/javascript" src="../../d3.js"></script> <style type="text/css"> svg { font: 10px sans-serif; } circle { -webkit-transition: fill-opacity 250ms linear; } .selecting circle { fill-opacity: .2; } .selecting circle.selected { stroke: #f00; } .axis path, .axis line { fill: none; stroke: #000; shape-rendering: crispEdges; } .brush .extent { stroke: #fff; fill-opacity: .125; shape-rendering: crispEdges; } </style> </head> <body> <script type="text/javascript"> var data = d3.range(800).map(Math.random); var m = [10, 10, 20, 10], w = 960 - m[1] - m[3], h = 100 - m[0] - m[2]; var x = d3.scale.linear().range([0, w]), y = d3.random.normal(h / 2, h / 8); var svg = d3.select("body").append("svg") .attr("width", w + m[1] + m[3]) .attr("height", h + m[0] + m[2]) .append("g") .attr("transform", "translate(" + m[3] + "," + m[0] + ")"); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + h + ")") .call(d3.svg.axis().scale(x).orient("bottom")); var circle = svg.selectAll("circle") .data(data) .enter().append("circle") .attr("transform", function(d) { return "translate(" + x(d) + "," + y() + ")"; }) .attr("r", 3.5); svg.append("g") .attr("class", "brush") .call(d3.svg.brush().x(x) .on("brushstart", brushstart) .on("brush", brush) .on("brushend", brushend)) .selectAll("rect") .attr("height", h); function brushstart() { svg.classed("selecting", true); } function brush() { var s = d3.event.target.extent(); circle.classed("selected", function(d) { return s[0] <= d && d <= s[1]; }); } function brushend() { svg.classed("selecting", !d3.event.target.empty()); } </script> </body> </html>
Version data entries
25 entries across 25 versions & 1 rubygems