Utility to make working with d3 scales less painful
A simple utility to make working with d3 scales easier.
npm install d3-Mapping
Designed to be used node style:
var Mapping = require"d3-mapping"
Initialize a new mapping with a scale and an accessor function
xScale = d3scalelinearreturn dxx = xScale xAccessor
x has convenience methods for a number of common tasks. For example:
x.scaleholds the reference to the original scale.
x.domainprovide convenient access to
x.placewill map data points onto the screen. It does a little dance to prevent D3 from overwriting its
thisobject, so you can use it in d3 attribute setters.
x.compute_domain(data, ordinal)will compute the domain of
ordinal == trueto find the unique elements for the dimension rather than the extent
x.maxgive more flexibility in manipulating the domain of the mapping. If you provide one argument, the minimum (maximum) of the mapping domain is simply set to that argument. If you pass an array, they compute the minimum or maximum of the value returned by the accessor when applied to the array, and set the corresponding bound of the domain.