public class Interpolators extends Object
Constructor and Description |
---|
Interpolators() |
Modifier and Type | Method and Description |
---|---|
static Interpolator<Array<?>> |
interpolateArray(Array<?> a,
Array<?> b)
Returns an array interpolator between the two arrays a and b.
|
static Interpolator<HSLColor> |
interpolateHsl(Color a,
Color b)
Returns an RGB color space interpolator between the two colors a and b.
|
static Interpolator<HSLColor> |
interpolateHsl(String a,
String b)
Returns an HSL color space interpolator between the two colors a and b.
|
static Interpolator<Double> |
interpolateNumber(byte a,
byte b)
See
#interpolate(double, double) . |
static Interpolator<Double> |
interpolateNumber(double a,
double b)
Returns a numeric interpolator between the two numbers a and b.
|
static Interpolator<Double> |
interpolateNumber(float a,
float b)
See
#interpolate(double, double) . |
static Interpolator<Double> |
interpolateNumber(int a,
int b)
|
static Interpolator<Double> |
interpolateNumber(long a,
long b)
See
#interpolate(double, double) . |
static Interpolator<Double> |
interpolateNumber(short a,
short b)
See
#interpolate(double, double) . |
static <T extends com.google.gwt.core.client.JavaScriptObject> |
interpolateObject(T a,
T b)
Returns an object interpolator between the two objects a and b.
|
static Interpolator<RGBColor> |
interpolateRgb(Color a,
Color b)
Returns an RGB color space interpolator between the two colors a and b.
|
static Interpolator<RGBColor> |
interpolateRgb(String a,
String b)
Returns an RGB color space interpolator between the two colors a and b.
|
static Interpolator<Byte> |
interpolateRound(byte a,
byte b)
|
static Interpolator<Character> |
interpolateRound(char a,
char b)
|
static Interpolator<Long> |
interpolateRound(double a,
double b)
Returns a numeric interpolator between the two numbers a and b; the
interpolator is similar to
#interpolate(double, double) , except
it will round the resulting value to the nearest integer. |
static Interpolator<Integer> |
interpolateRound(int a,
int b)
|
static Interpolator<Long> |
interpolateRound(long a,
long b)
|
static Interpolator<Short> |
interpolateRound(short a,
short b)
|
static Interpolator<String> |
interpolateString(String a,
String b)
Returns a string interpolator between the two strings a and b.
|
static Interpolator<Transform> |
interpolateTransform(Transform a,
Transform b)
Returns an interpolator between the two 2D affine transforms represented
by a and b.
|
static Interpolator<Array<Double>> |
interpolateZoom(Array<Double> a,
Array<Double> b)
Returns a smooth interpolator between the two views a and b of a
two-dimensional plane, based on “Smooth and efficient zooming and
panning” by Jarke J. van Wijk and Wim A.A.
|
static Array<InterpolatorFactory<?>> |
interpolators()
The array of built-in interpolator factories, as used by #interpolate().
|
public static final Interpolator<String> interpolateString(String a, String b)
The string interpolator finds numbers embedded in a and b, where each number is of the form:
/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g
For each number embedded in b, the interpolator will attempt to find a corresponding number in a. If a corresponding number is found, a numeric interpolator is created using interpolateNumber. The remaining parts of the string b are used as a template: the static parts of the string b remain constant for the interpolation, with the interpolated numeric values embedded in the template.
For example, if a is "300 12px sans-serif", and b is "500 36px Comic-Sans", two embedded numbers are found. The remaining static parts of the string are a space between the two numbers (" "), and the suffix ("px Comic-Sans"). The result of the interpolator at t = .5 is "400 24px Comic-Sans".
a
- the startb
- the endpublic static final Interpolator<RGBColor> interpolateRgb(String a, String b)
The colors a and b need not be in RGB, but they will be converted to RGB
using D3#rgb(String)
.
The red, green and blue channels are interpolated linearly in a manner equivalent to interpolateRound, as fractional channel values are not allowed.
Also note that the interpolator modifies the returned color instance, and thus a copy must be made if you wish to avoid modification.
a
- the start colorb
- the end colorpublic static final Interpolator<RGBColor> interpolateRgb(Color a, Color b)
The colors a and b need not be in RGB, but they will be converted to RGB
using D3#rgb(String)
.
The red, green and blue channels are interpolated linearly in a manner equivalent to interpolateRound, as fractional channel values are not allowed.
Also note that the interpolator modifies the returned color instance, and thus a copy must be made if you wish to avoid modification.
a
- the start colorb
- the end colorpublic static final Interpolator<HSLColor> interpolateHsl(String a, String b)
The colors a and b need not be in HSL, but they will be converted to HSL
using D3#hsl(String)
.
The hue, saturation and lightness are interpolated linearly in a manner equivalent to interpolateNumber. (The shortest path between the start and end hue is used.)
Also note that the interpolator modifies the returned color instance, and thus a copy must be made if you wish to avoid modification.
a
- the start colorb
- the end colorpublic static final Interpolator<HSLColor> interpolateHsl(Color a, Color b)
The colors a and b need not be in RGB, but they will be converted to RGB
using D3#rgb(String)
.
The red, green and blue channels are interpolated linearly in a manner equivalent to interpolateRound, as fractional channel values are not allowed.
Also note that the interpolator modifies the returned color instance, and thus a copy must be made if you wish to avoid modification.
a
- the start colorb
- the end colorpublic static final Interpolator<Double> interpolateNumber(double a, double b)
function interpolate(t) {
return a * (1 - t) + b * t;
}
Caution: avoid interpolating to or from the number zero when the interpolator is used to generate a string (such as with attr). Very small values, when stringified, may be converted to scientific notation and cause a temporarily invalid attribute or style property value. For example, the number 0.0000001 is converted to the string "1e-7". This is particularly noticeable when interpolating opacity values. To avoid scientific notation, start or end the transition at 1e-6, which is the smallest value that is not stringified in exponential notation.
a
- the startb
- the endpublic static final Interpolator<Array<?>> interpolateArray(Array<?> a, Array<?> b)
Internally, an array template is created that is the same length in b. For each element in b, if there exists a corresponding element in a, a generic interpolator is created for the two elements using interpolate. If there is no such element, the static value from b is used in the template. Then, for the given parameter t, the template's embedded interpolators are evaluated. The updated array template is then returned.
For example, if a is the array [0, 1] and b is the array [1, 10, 100], then the result of the interpolator for t = .5 is the array [.5, 5.5, 100].
Note: no defensive copy of the template array is created; modifications of the returned array may adversely affect subsequent evaluation of the interpolator. No copy is made because interpolators should be fast, as they are part of the inner loop of animation.
a
- the array ab
- the array bpublic static final <T extends com.google.gwt.core.client.JavaScriptObject> Interpolator<T> interpolateObject(T a, T b)
Internally, an object template is created that has the same properties as b.
For each property in b, if there exists a corresponding property in a, a generic interpolator is created for the two elements using interpolate.
If there is no such property, the static value from b is used in the template.
Then, for the given parameter t, the template's embedded interpolators are evaluated and the updated object template is then returned.
For example, if a is the object {x: 0, y: 1} and b is the object {x: 1, y: 10, z: 100}, the result of the interpolator for t = .5 is the object {x: .5, y: 5.5, z: 100}.
Object interpolation is particularly useful for dataspace interpolation, where data is interpolated rather than attribute values. For example, you can interpolate an object which describes an arc in a pie chart, and then use d3.svg.arc to compute the new SVG path data.
Note: no defensive copy of the template object is created; modifications of the returned object may adversely affect subsequent evaluation of the interpolator. No copy is made because interpolators should be fast, as they are part of the inner loop of animation.
a
- the object ab
- the object bpublic static final Interpolator<Transform> interpolateTransform(Transform a, Transform b)
a
- the object ab
- the object bpublic static final Interpolator<Double> interpolateNumber(int a, int b)
a
- the startb
- the endpublic static final Interpolator<Double> interpolateNumber(byte a, byte b)
#interpolate(double, double)
.a
- the startb
- the endpublic static final Interpolator<Double> interpolateNumber(float a, float b)
#interpolate(double, double)
.a
- the startb
- the endpublic static final Interpolator<Double> interpolateNumber(long a, long b)
#interpolate(double, double)
.a
- the startb
- the endpublic static final Interpolator<Double> interpolateNumber(short a, short b)
#interpolate(double, double)
.a
- the startb
- the endpublic static final Interpolator<Long> interpolateRound(double a, double b)
#interpolate(double, double)
, except
it will round the resulting value to the nearest integer.
a
- the startb
- the endpublic static final Interpolator<Byte> interpolateRound(byte a, byte b)
a
- the startb
- the endpublic static final Interpolator<Character> interpolateRound(char a, char b)
a
- the startb
- the endpublic static final Interpolator<Integer> interpolateRound(int a, int b)
a
- the startb
- the endpublic static final Interpolator<Long> interpolateRound(long a, long b)
a
- the startb
- the endpublic static final Interpolator<Short> interpolateRound(short a, short b)
a
- the startb
- the endpublic static final Interpolator<Array<Double>> interpolateZoom(Array<Double> a, Array<Double> b)
Each view is defined as an array of three numbers: cx, cy and width. The first two coordinates cx, cy represent the center of the viewport; the last coordinate width represents the size of the viewport.
The returned interpolator also has a duration property which encodes the recommended transition duration in milliseconds. This duration is based on the path length of the curved trajectory through x,y space. If you want to a slower or faster transition, multiply this by an arbitrary scale factor (V as described in the original paper).
a
- the startb
- the endpublic static final Array<InterpolatorFactory<?>> interpolators()
Additional interpolator factories may be pushed onto the end of this array.
Each factory may return an interpolator, if it supports interpolating the two specified input values; otherwise, the factory should return a falsey value and other interpolators will be tried.
Copyright © 2015 gwt-d3. All rights reserved.