JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
<svg></svg>
<div>
<button id="in">+</button>
<button id="out">-</button>
</div>
CSS
.domain {
fill: transparent;
stroke: #000;
}
.tick {
fill: transprent;
stroke: #000;
}
text {
stroke: none;
}
JavaScript
var width = 500,
height = 100,
zoomScale = 1,
margin = {top: 0, right: 0, bottom: 30, left: 0},
svg = d3.select('svg')
.attr({width: width, height: height}),
xScale = d3.scale.linear()
.domain([0, 1])
.range([0, width]),
xAxis = d3.svg.axis()
.scale(xScale),
brush = d3.svg.brush()
.x(xScale)
.extent([.1, .6]),
brushGroup = svg.append('g')
.attr('class', 'brush-group'),
xAxisGroup = svg.append('g')
.attr('classe', 'x-axis-group')
.attr('transform', 'translate(0,' + (height - margin.bottom) + ')');
// initialize axis
xAxisGroup
.call(xAxis);
// initialize brush
brushGroup
.call(brush)
.selectAll('.background')
.attr('height', height - margin.bottom)
.style('pointer-events', 'none');
brushGroup
.selectAll('.resize rect')
.attr('height', height - margin.bottom);
brushGroup
.selectAll('.extent')
.attr('height', height - margin.bottom)
.style('fill', 'rgba(0, 255, 255, .5)');
// event handling
document.getElementById('in').addEventListener('click', zoom.bind(null, .1));
document.getElementById('out').addEventListener('click', zoom.bind(null, -.1));
function zoom(step) {
var offset;
zoomScale += step;
if(zoomScale < 1)
zoomScale -= step;
offset = (zoomScale * width - width) / 2;
xScale
.range([-offset, width + offset]);
brushGroup
.call(brush);
xAxisGroup
.transition()
.call(xAxis);
}