|
|
|
@ -1236,11 +1236,11 @@ Now clicking on the middle circle should work correctly.
|
|
|
|
|
|
|
|
|
|
|
|
## Hide elements beyond axis
|
|
|
|
## Hide elements beyond axis
|
|
|
|
|
|
|
|
|
|
|
|
Check out our graph when you pan:
|
|
|
|
If you pan or zoom extensively, you'll notice that the circles are visible beyond the bounds of the axes:
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
To remove elements once they get beyond an axis, we can just add an outer SVG:
|
|
|
|
To hide elements once they get beyond an axis, we can just add an outer SVG with `id="container"` around our current `<svg>` element in `index.html`:
|
|
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
```html
|
|
|
|
<svg id="container">
|
|
|
|
<svg id="container">
|
|
|
|
@ -1250,15 +1250,16 @@ To remove elements once they get beyond an axis, we can just add an outer SVG:
|
|
|
|
</svg>
|
|
|
|
</svg>
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
Now replace all `d3.select('svg')` with `d3.select('#container')`
|
|
|
|
Now replace all `d3.select('svg')` code with `d3.select('#container')`. You can do a find replace. There should be five instances to change:
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
```javascript
|
|
|
|
d3.select('#container')
|
|
|
|
d3.select('#container')
|
|
|
|
.style('width', WIDTH)
|
|
|
|
.style('width', WIDTH)
|
|
|
|
.style('height', HEIGHT);
|
|
|
|
.style('height', HEIGHT);
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// ...
|
|
|
|
// lots of code omitted here, including render() declaration...
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
var bottomAxis = d3.axisBottom(xScale);
|
|
|
|
d3.select('#container')
|
|
|
|
d3.select('#container')
|
|
|
|
.append('g')
|
|
|
|
.append('g')
|
|
|
|
.attr('id', 'x-axis')
|
|
|
|
.attr('id', 'x-axis')
|
|
|
|
@ -1271,29 +1272,32 @@ d3.select('#container')
|
|
|
|
.attr('id', 'y-axis')
|
|
|
|
.attr('id', 'y-axis')
|
|
|
|
.call(leftAxis);
|
|
|
|
.call(leftAxis);
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// ...
|
|
|
|
// code for create table omitted here...
|
|
|
|
//
|
|
|
|
//
|
|
|
|
d3.select('#container').on('click', function(){
|
|
|
|
d3.select('#container').on('click', function(){
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// ...
|
|
|
|
// click handler functionality omitted
|
|
|
|
//
|
|
|
|
//
|
|
|
|
});
|
|
|
|
});
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// ...
|
|
|
|
// zoomCallback code omitted here
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
var zoom = d3.zoom()
|
|
|
|
|
|
|
|
.on('zoom', zoomCallback);
|
|
|
|
d3.select('#container').call(zoom);
|
|
|
|
d3.select('#container').call(zoom);
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
And lastly, adjust css:
|
|
|
|
And lastly, adjust css to replace `svg {` with `#container {`:
|
|
|
|
|
|
|
|
|
|
|
|
```css
|
|
|
|
```css
|
|
|
|
/* replace the rule for svg */
|
|
|
|
|
|
|
|
#container {
|
|
|
|
#container {
|
|
|
|
overflow: visible;
|
|
|
|
overflow: visible;
|
|
|
|
margin-bottom: 50px;
|
|
|
|
margin-bottom: 50px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Now circles should be hidden once they move beyond the bounds of the inner `<svg>` element:
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|