|
PvScale
pv.Scale: functions that map from domain to range.
ScalesScales are functions that map from domain to range. Quantitative scales map from a continuous domain to a continuous range (e.g., real numbers to pixel positions): Ordinal scales map from a discrete domain to a discrete range (e.g., names to colors): The by method: Scale ViewsThe by method is a shorthand way of binding an accessor function with the scale. Why is this useful? This method is provided for convenience, such that scales can be succinctly defined inline. For example, given an array of data elements that have a score attribute with the domain [0, 1], the height property could be specified as: .height(pv.Scale.linear(0, 1).range(0, 480).by(function(d) d.score)) This is shorthand for: var y = pv.Scale.linear(0, 1).range(0, 480); ... .height(function(d) y(d.score)) This method should be used judiciously; it is typically more clear to invoke the scale directly, passing in the value to be scaled. Most commonly, the by method is used in conjunction with categorical color scales. There are also several pre-defined accessor functions for convenience:
For example, the default fill color for bars is pv.Colors.category20().by(pv.parent) which causes bars to be filled with a unique color according to the parent panel index. Since the parent panel data is typically a two-dimensional array of each series of data, this causes bars of the same series to share a color by default. |
Sign in to add a comment