Skip to content

Instantly share code, notes, and snippets.

@trtg
Created December 29, 2012 09:45
Show Gist options
  • Save trtg/4405796 to your computer and use it in GitHub Desktop.
Save trtg/4405796 to your computer and use it in GitHub Desktop.
using d3 brush feature for region selection
{"description":"using d3 brush feature for region selection","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"tab":"edit","display_percent":0.6040622299049263,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"hidepanel":false}
//this can be used to select/brush
//a particular region in a scatterplot
//like for linked plots
var svg = d3.select("svg");
var xscale = d3.scale.linear()
.domain([0,1])
.range([0,300]);
var yscale = d3.scale.linear()
.domain([0,1])
.range([0,300]);
var brush = d3.svg.brush()
.x(xscale)
.y(yscale);
var slider = svg.append("g")
.attr("transform","translate("+[100,100]+")");
brush.extent([0.4,0.6]);
brush(slider);
slider.selectAll("rect.background").attr("height",300);
.background {
visibility: visible !important;
}
.extent{
visibility: visible !important;
fill:#C200A3;
}
.resize rect{
visibility: visible !important;
fill: #0089e7;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment