public class Arrays extends Object
Constructor and Description |
---|
Arrays() |
Modifier and Type | Method and Description |
---|---|
static Sort |
ascending()
Compare two values for sorting.
|
static Sort |
descending()
Compare two values for sorting.
|
static com.google.gwt.core.client.JsArrayMixed |
extent(com.google.gwt.core.client.JavaScriptObject array)
Find the minimum and maximum value in an array.
|
static <D,R> com.google.gwt.core.client.JsArrayMixed |
extent(com.google.gwt.core.client.JavaScriptObject array,
ObjectAccessor<D,R> accessor)
Find the minimum and maximum value in an array.
|
static Value |
max(com.google.gwt.core.client.JavaScriptObject array)
Returns the maximum value in the given array using natural order.
|
static Value |
max(com.google.gwt.core.client.JavaScriptObject array,
ForEachCallback<?> accessor)
Transform the values in the given array using the specified
ForEachCallback and returns the maximum value
in the transformed
values using natural order. |
static Value |
max(com.google.gwt.core.client.JavaScriptObject array,
NumericForEachCallback accessor)
Transform the values in the given array using the specified
ForEachCallback and returns the maximum value
in the transformed
values using natural order. |
static Value |
min(com.google.gwt.core.client.JavaScriptObject array)
Returns the minimum value in the given array using natural order.
|
static Value |
min(com.google.gwt.core.client.JavaScriptObject array,
ForEachCallback<?> accessor)
Transform the values in the given array using the specified
ForEachCallback and returns the minimum value
in the transformed
values using natural order. |
static Value |
min(com.google.gwt.core.client.JavaScriptObject array,
NumericForEachCallback accessor)
Transform the values in the given array using the specified
ForEachCallback and returns the minimum value
in the transformed
values using numeric order. |
static <T> Array<Array<T>> |
pairs(Array<T> array)
For each adjacent pair of elements in the specified array, returns a new
array of tuples of element i and element i - 1.
|
static Array<Integer> |
range(double stop)
Generate a range of
stop-1 numeric values, stored in an
array, going from 0 to stop (excluded). |
static Array<?> |
range(double stop,
double step)
Generate a range of numeric values, stored in an array, going from 0 to
stop (exluded), separated by step (>0).
|
static com.google.gwt.core.client.JavaScriptObject |
range(double start,
double stop,
double step)
Generate a range of numeric values.
|
public static final <T> Array<Array<T>> pairs(Array<T> array)
d3.pairs([1, 2, 3, 4]); // returns [[1, 2], [2, 3], [3, 4]]
If the specified array has fewer than two elements, returns the empty array.
array
- public static final Value max(com.google.gwt.core.client.JavaScriptObject array)
If the array is empty, returns undefined.
Unlike the built-in Math.max(int, int)
, this method ignores undefined values; this is useful for computing the
domain of a scale while only considering the defined region of the data.
In addition, elements are compared using natural order rather than numeric order. For example, the maximum of ["20", "3"] is "3", while the maximum of [20, 3] is 20.
array
- the array to be evaluatedValue
objectpublic static final Value max(com.google.gwt.core.client.JavaScriptObject array, ForEachCallback<?> accessor)
ForEachCallback
and returns the maximum value
in the transformed
values using natural order. For example, the maximum of ["20", "3"] is
"3", while the maximum of [20, 3] is 20. If you want to ensure the
numeric order, please consider using max(JavaScriptObject, NumericForEachCallback)
.
The given ForEachCallback
is equivalent to calling array.map(accessor) before computing the maximum
value.
If the array is empty, returns undefined.
Unlike the built-in Math.max(int, int)
, this method ignores undefined values; this is useful for computing the
domain of a scale while only considering the defined region of the data.
array
- the array to be transformedaccessor
- the function used to convert each element in the original
array to a transformed valueValue
objectpublic static final Value max(com.google.gwt.core.client.JavaScriptObject array, NumericForEachCallback accessor)
ForEachCallback
and returns the maximum value
in the transformed
values using natural order.
The given NumericForEachCallback
is equivalent to calling array.map(accessor) before computing the
maximum value.
If the array is empty, returns undefined.
Unlike the built-in Math.max(int, int)
, this method ignores undefined values; this is useful for computing the
domain of a scale while only considering the defined region of the data.
In addition, elements are compared using numeric order.
array
- the array to be transformedaccessor
- the function used to convert each element in the original
array to a transformed valueValue
objectpublic static final Value min(com.google.gwt.core.client.JavaScriptObject array)
If the array is empty, returns undefined.
Unlike the built-in Math.min(int, int)
, this method ignores undefined values; this is useful for computing the
domain of a scale while only considering the defined region of the data.
In addition, elements are compared using natural order rather than numeric order. For example, the minimum of ["20", "3"] is "20", while the minimum of [20, 3] is 3.
array
- the array to be evaluatedValue
objectpublic static final Value min(com.google.gwt.core.client.JavaScriptObject array, ForEachCallback<?> accessor)
ForEachCallback
and returns the minimum value
in the transformed
values using natural order. For example, the minimum of ["20", "3"] is
"20", while the minimum of [20, 3] is 3. If you want to ensure the
numeric order, please consider using max(JavaScriptObject, NumericForEachCallback)
.
The given ForEachCallback
is equivalent to calling array.map(accessor) before computing the minimum
value.
If the array is empty, returns undefined.
Unlike the built-in Math.min(int, int)
, this method ignores undefined values; this is useful for computing the
domain of a scale while only considering the defined region of the data.
In addition, elements are compared using natural order rather than numeric order.
array
- the array to be transformedaccessor
- the function used to convert each element in the original
array to a transformed valueValue
objectpublic static final Value min(com.google.gwt.core.client.JavaScriptObject array, NumericForEachCallback accessor)
ForEachCallback
and returns the minimum value
in the transformed
values using numeric order.
The given NumericForEachCallback
is equivalent to calling array.map(accessor) before computing the
minimum value.
If the array is empty, returns undefined.
Unlike the built-in Math.min(int, int)
, this method ignores undefined values; this is useful for computing the
domain of a scale while only considering the defined region of the data.
array
- the array to be transformedaccessor
- the function used to convert each element in the original
array to a transformed valueValue
objectpublic static final com.google.gwt.core.client.JsArrayMixed extent(com.google.gwt.core.client.JavaScriptObject array)
array
- the given array.public static final <D,R> com.google.gwt.core.client.JsArrayMixed extent(com.google.gwt.core.client.JavaScriptObject array, ObjectAccessor<D,R> accessor)
array
- the given array.public static final Sort ascending()
This is the comparator function for natural order.
public static final Sort descending()
This is the comparator function for reverse natural order.
public static final Array<Integer> range(double stop)
stop-1
numeric values, stored in an
array, going from 0 to stop (excluded).stop
- the maximum value (excluded)D3#range(double, double, double)
public static final Array<?> range(double stop, double step)
For instance, range(10, 3) would produce the array [0,3,6,9].
stop
- the maximum value (excluded)step
- the step between each valueD3#range(double, double, double)
public static final com.google.gwt.core.client.JavaScriptObject range(double start, double stop, double step)
Generates an array containing an arithmetic progression, similar to the Python built-in range. This method is often used to iterate over a sequence of numeric or integer values, such as the indexes into an array. Unlike the Python version, the arguments are not required to be integers, though the results are more predictable if they are due to floating point precision. If step is omitted, it defaults to 1. If start is omitted, it defaults to 0. The stop value is not included in the result. The full form returns an array of numbers [*start*, start + step, start + 2 * step, ...]. If step is positive, the last element is the largest start + i * step less than stop; if step is negative, the last element is the smallest start + i * step greater than stop. If the returned array would contain an infinite number of values, an error is thrown rather than causing an infinite loop.
start
- the first value-stop
- the maximum value (excluded)step
- the step between each valueCopyright © 2015 gwt-d3. All rights reserved.