Skip to content

Instantly share code, notes, and snippets.

@makoto
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save makoto/fa797b32cbe3217a64bb to your computer and use it in GitHub Desktop.
Save makoto/fa797b32cbe3217a64bb to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
svg {
font: 10px sans-serif;
}
.border {
color: yellow;
}
.resize path {
fill: #666;
fill-opacity: .8;
stroke: #000;
stroke-width: 1.5px;
}
.e{
fill: red;
}
.w{
fill: green;
}
.axis path, .axis line {
fill: none;
stroke: #000;
/*shape-rendering: crispEdges;*/
}
.brush .extent {
fill-opacity: .125;
/*shape-rendering: crispEdges;*/
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var margin = {top: 194, right: 50, bottom: 214, left: 50},
width = 800 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var x = d3.scale.linear()
.domain([0,60])
.range([0, width]);
var brush = d3.svg.brush()
.x(x)
.extent([20,26])
.on("brush", brushmove)
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(d3.svg.axis().scale(x).orient("bottom"));
var brushg = svg.append("g")
.attr("class", "brush")
.call(brush)
brushg.selectAll(".resize").append("rect")
.attr("width", '20px')
.classed("border")
brushg.selectAll("rect")
.attr("height", height);
brushg.select(".background")
.on("mousedown.brush", nobrush)
.on("touchstart.brush", nobrush);
brushmove();
function brushmove() {
console.log(brush.extent())
var extent = brush.extent()
var diff = extent[1] - extent[0]
if (diff < 1) {
console.log("Brush should not be smaller than 1")
// Hoping to stop brush move with no luck.
d3.event.sourceEvent.stopPropagation()
};
}
function nobrush(a, b, c) {
console.log('brushcenter')
d3.event.stopPropagation()
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment