Skip to content

Commit

Permalink
start ResizeObserver example for #1596
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonwoodhull committed Oct 18, 2019
1 parent e069215 commit 10e9c2b
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions web/resizing/resizing-scatter-brushing.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
<script type="text/javascript">

const urlParams = new URLSearchParams(window.location.search),
useCanvas = !!urlParams.get('canvas');
useCanvas = !!urlParams.get('canvas'),
resizeObserver = !!urlParams.get('observer');

dc.constants.EVENT_DELAY = 0;

Expand Down Expand Up @@ -81,20 +82,30 @@
dc.renderAll();

// respond to browser resize (not necessary if width/height is static)
window.onresize = function() {
chart1
.width(window.innerWidth/2 - fudge)
.height(window.innerHeight - fudge)
.rescale();
if(resizeObserver) {
const callback = chart => entries => {
chart
.width(entries[0].target.offsetWidth)
.height(entries[0].target.offsetHeight)
.rescale();
};
new ResizeObserver(callback(chart1)).observe(d3.select('#test1').node());
new ResizeObserver(callback(chart2)).observe(d3.select('#test2').node());
} else {
window.onresize = function() {
chart1
.width(window.innerWidth/2 - fudge)
.height(window.innerHeight - fudge)
.rescale();

chart2
.width(window.innerWidth/2 - fudge)
.height(window.innerHeight - fudge)
.rescale();

dc.redrawAll();
};
chart2
.width(window.innerWidth/2 - fudge)
.height(window.innerHeight - fudge)
.rescale();

dc.redrawAll();
};
}
</script>

</div>
Expand Down

0 comments on commit 10e9c2b

Please sign in to comment.