public class LinearScale extends ContinuousQuantitativeScale<LinearScale>
The mapping is linear in that the output range value y can be expressed as a linear function of the input domain value x: y = mx + b.
The input domain is typically a dimension of the data that you want to visualize, such as the height of students (measured in meters) in a sample population.
The output range is typically a dimension of the desired output visualization, such as the height of bars (measured in pixels) in a histogram.
The default linear scale has a default domain of [0,1] and the default range [0,1]. Thus, the default linear scale is equivalent to the identity function for numbers; for example linear(0.5) returns 0.5.
Although linear scales typically have just two numeric values in their domain, you can specify more than two values for a polylinear scale.
In this case, there must be an equivalent number of values in the output range. A polylinear scale represents multiple piecewise linear scales that divide a continuous domain and range. This is particularly useful for defining diverging quantitative scales. For example, to interpolate between white and red for negative values, and white and green for positive values, say:
Scale color = d3.scale.linear().domain([-1, 0, 1]).range(["red","white", "green"]);
The resulting value of color(-.5) is rgb(255, 128, 128), and the value of
color(.5) is rgb(128, 192, 128).
Internally, polylinear scales perform a binary search for the output interpolator corresponding to the given domain value. By repeating values in both the domain and range, you can also force a chunk of the input domain to map to a constant in the output range.
The output range must contain two or more values, to match the cardinality of the input domain, otherwise the longer of the two is truncated to match the other.
The elements in the output range array need not be numbers; any value that is supported by the underlying interpolator will work.
However, numeric ranges are required for the ContinuousQuantitativeScale.invert(double)
operator.
Modifier | Constructor and Description |
---|---|
protected |
LinearScale() |
Modifier and Type | Method and Description |
---|---|
LinearScale |
nice()
Extends the domain so that it starts and ends on nice round values.
|
LinearScale |
nice(int count)
Same as
nice() but with more control. |
Formatter |
tickFormat(int count)
Returns a number format function suitable for displaying a tick value.
|
Formatter |
tickFormat(int count,
String formatSpecifier)
Returns a number format function suitable for displaying a tick value.
|
<T> Array<T> |
ticks()
Alias for
ticks(10) . |
<T> Array<T> |
ticks(int count)
Returns approximately count representative values from the scale's input
domain.
|
clamp, clamp, invert, rangeRound, rangeRound, rangeRound
apply, apply, apply, copy, domain, domain, domain, domain, range, range, range, range
public final <T> Array<T> ticks(int count)
The returned tick values are uniformly spaced, have human-readable values (such as multiples of powers of 10), and are guaranteed to be within the extent of the input domain.
Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data. The specified count is only a hint; the scale may return more or fewer values depending on the input domain.
public final Formatter tickFormat(int count)
The specified count should have the same value as the count that is used to generate the tick values you want to display.
You don't have to use the scale's built-in tick format, but it automatically computes the appropriate precision based on the fixed interval between tick values.
the
- number of ticks to take into account to create the
Formatter
.public final Formatter tickFormat(int count, String formatSpecifier)
This is the same as tickFormat(int)
, except that the format
argument allows a format specifier to be specified.
If the format specifier doesn’t have a defined precision, the precision will be set automatically by the scale, returning the appropriate format.
This provides a convenient, declarative way of specifying a format whose precision will be automatically set by the scale.
public final LinearScale nice()
This method typically modifies the scale's domain, and may only extend the bounds to the nearest round value.
The precision of the round value is dependent on the extent of the domain dx according to the following formula: exp(round(log(*dx*)) - 1).
Nicing is useful if the domain is computed from data and may be irregular.
For example, for a domain of [0.20147987687960267, 0.996679553296417], the nice domain is [0.2, 1]. If the domain has more than two values, nicing the domain only affects the first and last value.
public final LinearScale nice(int count)
nice()
but with more control.
The tick count argument allows greater control over the step size used to
extend the bounds, guaranteeing that the ticks returned by
ticks(int)
will exactly cover the domain.
Copyright © 2015 gwt-d3. All rights reserved.