Class pv.Scale
Extends
function.
Represents a scale; a function that performs a transformation from
data domain to visual range. For quantitative and quantile scales, the domain
is expressed as numbers; for ordinal scales, the domain is expressed as
strings (or equivalently objects with unique string representations). The
"visual range" may correspond to pixel space, colors, font sizes, and the
like.
Note that scales are functions, and thus can be used as properties directly, assuming that the data associated with a mark is a number. While this is convenient for single-use scales, frequently it is desirable to define scales globally:
var y = pv.Scale.linear(0, 100).range(0, 640);The y scale can now be equivalently referenced within a property:
.height(function(d) y(d))Alternatively, if the data are not simple numbers, the appropriate value can be passed to the y scale (e.g., d.foo). The #by method similarly allows the data to be mapped to a numeric value before performing the linear transformation.
Defined in: Scale.js.
Constructor Attributes | Constructor Name and Description |
---|---|
pv.Scale()
Abstract; see the various scale implementations.
|
Method Attributes | Method Name and Description |
---|---|
by(f)
Returns a view of this scale by the specified accessor function f.
|
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().range(0, 480).by(function(d) d.score))This is equivalent to:
.height(function(d) d.score * 480)This method should be used judiciously; it is typically more clear to invoke the scale directly, passing in the value to be scaled.
- Parameters:
- {function} f
- an accessor function.
- Returns:
- {pv.Scale} a view of this scale by the specified accessor function.