Skip to main content
100%

Axes with Model.js

✓ Published0🌍 Public
CCurran Kelleher
Last edited Nov 20, 2015
Created on Sep 25, 2015

This example demonstrates how to encapsulate the D3 Margin Convention using Model.js, with axes that respond to resizing. It shows three reusable functions—margin handling, background rectangles, and clip paths—each managing separate visual behavior. The code uses `d3.svg.axis()` for the x-axis, `d3.scale.linear()` for scaling, and Model.js’s `when` method to coordinate dynamic updates. The visualization renders sample data points in an SVG container, with the margin convention adjusting the inner plot area and axis positions on resize.

AI-generated description

This example shows one way to encapsulate the D3 Margin Convention using Model.js.

Check out the resize behavior in full screen mode.

More generally, this example is an experiment in how to generalize self-contained pieces of dynamic graphical behavior. Note that the following three pieces of this visualization are each implemented in separate functions:

  • The margin convention, which
    • resizes the SVG element by setting width and height
    • translates the G element by the margin top and left
    • assigns values to the model properties width and height, which represent the dimensions of the rectangle inside the margin.
  • The background X.
  • The clip rectangle, which will clip the corners of the background X to be within the rectangle inside the margin.

Draws from:

forked from <a href='http://bl.ocks.org/curran/'>curran</a>'s block: <a href='http://bl.ocks.org/curran/2c736a99c2f57bfac7e4'>Margin Convention with Model.js</a>

Similar vizzes