D3 has a notion of “scales”, transformations of data from a domain to a range. Say your data is percentages (0% to 100%) and you want to draw them as bars of length 10-20. You can easily construct a linear scale to map your domain [0,100] to a range [10,20]:

If that use of `s`

seems magic, equivalents would be

D3 provides various useful scales. Numeric scales like `linear`

, `log`

, and `pow`

, also discrete scales like `quantize`

and `ordinal`

.

One thing you can set on a scale is the interpolate function. It’s invoked when mapping the domain to the range and lets you make the range be something other than the usual numeric range.

There are pre-defined interpolation functions for numbers, colours, strings, objects, etc. I believe they’re also used by D3’s transition animations, specifically to automatically warp complex things like SVG paths from one shape…

View original post 68 more words

## Leave a Reply