From 247ebda2dd2a4670e402be1232cd87a9cac94f84 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Tue, 19 Sep 2017 21:51:57 -0400 Subject: [PATCH] Hide elements beyond axis --- BUILD.md | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/BUILD.md b/BUILD.md index f2610d4..69e379c 100644 --- a/BUILD.md +++ b/BUILD.md @@ -23,6 +23,7 @@ 1. Update axes when zooming 1. Update click points after a transform 1. Avoid redrawing entire screen during render +1. Hide elements beyond axis ## Add link to d3 library @@ -767,3 +768,59 @@ circles.enter() circles.exit().remove(); ``` + +## Hide elements beyond axis + +To remove elements once they get beyond an axis, we can just add an outer SVG: + +```html + + + + + +``` + +Now replace all `d3.select('svg')` with `d3.select('#container')` + +```javascript +d3.select('#container') + .style('width', WIDTH) + .style('height', HEIGHT); +// +// ... +// +d3.select('#container') + .append('g') + .attr('id', 'x-axis') + .call(bottomAxis) + .attr('transform', 'translate(0,'+HEIGHT+')'); + +var leftAxis = d3.axisLeft(yScale); +d3.select('#container') + .append('g') + .attr('id', 'y-axis') + .call(leftAxis); +// +// ... +// +d3.select('#container').on('click', function(){ +// +// ... +// +}); +// +// ... +// +d3.select('#container').call(zoom); +``` + +And lastly, adjust css: + +```css +#container { + overflow: visible; + margin-bottom: 20px; + margin-left: 30px; + } +```