ReactiveModel Resize
This example demonstrates a D3 v4 visualization that dynamically resizes to fill its container using ReactiveModel. The code renders two diagonal lines forming an X, with stroke widths and positions updated on window resize events. ReactiveModel orchestrates reactive properties for width, height, and the SVG element, while d3.selection.merge efficiently handles enter and update selections. The visualization responds to container size changes by reading clientWidth and clientHeight, redrawing the lines each animation frame.
AI-generated descriptionThis example shows how to make a dynamic graphic using D3 4.0 and ReactiveModel that fills its containing element and responds to resize. This is useful when, for example, you want to be able to load your visualization "full screen" and give users the ability to size the window however they want to. It's also useful when you want to use CSS to define the size of a visualization container, then have the visualization automatically fit inside it.
To experience the resize behavior, run this example full-screen and resize the browser.
Part of a series of examples demonstrating ReactiveModel.
Notes:
- This is using an alpha version of D3 4.0. The main difference in this example from D3 3.5 is the use of selection.merge, which merges enter with update.
- The call to
addPropertiesinstantiates instances of reactive-property with the given defaults. These behave similarly to the getter-setter functions described in Towards Reusable Charts. - The function that takes (svg, width, height) as input becomes a reactive-function. This will be invoked once all inputs are defined, and when any inputs change. It is invoked at most once every animation frame, so there are no unnecessary DOM updates. In other words, even if there are many resize events fired per animation frame, the DOM will only be updated with the most recent width and height values each frame (at most 60 times per second, synchronized with the display).
forked from <a href='http://bl.ocks.org/curran/'>curran</a>'s block: <a href='http://bl.ocks.org/curran/3a68b0c81991e2e94b19'>Responding to Resize</a>
Built with blockbuilder.org
<!-- Start of SimpleHitCounter Code --> <div align="center"><img src="http://simplehitcounter.com/hit.php?uid=2072503&f=16777215&b=0" border="0" height="18" width="83"></div> <!-- End of SimpleHitCounter Code -->