public class TimeScale extends ContinuousQuantitativeScale<TimeScale>
LinearScale
that uses JavaScript
Date objects as the domain representation.
Thus, unlike the normal linear scale, domain values are coerced to dates
rather than numbers; similarly, the ContinuousQuantitativeScale.invert(double)
function returns
a date.
Most conveniently, the time scale also provides suitable ticks based on time intervals, taking the pain out of generating axes for nearly any time-based domain.
A scale object, such as that returned by d3.time.scale, is both an object and a function. That is: you can call the scale like any other function, and the scale has additional methods that change its behavior. Like other classes in D3, scales follow the method chaining pattern where setter methods return the scale itself, allowing multiple setters to be invoked in a concise statement.
The domain may be set as an array of two or more dates. If the elements in the given array are not dates, they will be coerced to dates; this coercion happens similarly when the scale is called.
Although time scales typically have just two dates in their domain, you can specify more than two dates for a polylinear scale. In this case, there must be an equivalent number of values in the output range.
Modifier | Constructor and Description |
---|---|
protected |
TimeScale() |
Modifier and Type | Method and Description |
---|---|
TimeScale |
nice(Interval interval)
Extends the domain so that it starts and ends on nice round values as
determined by the specified time interval.
|
TimeScale |
nice(Interval interval,
int step)
Extends the domain so that it starts and ends on nice round values as
determined by the specified time interval and step count.nd optional step
count.
|
Formatter |
tickFormat(int count)
Returns a time
Formatter function suitable for displaying a tick
value. |
<T> Array<T> |
ticks()
Alias for
ticks(10) . |
<T> Array<T> |
ticks(int count)
Returns representative dates from the scale's input domain.
|
<T> Array<T> |
ticks(Interval interval,
int steps)
Returns representative dates 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 TimeScale nice(Interval interval)
This method typically modifies the scale's domain, and may only extend the bounds to the nearest round value.
Nicing is useful if the domain is computed from data and may be irregular. For example, for a domain of [2009-07-13T00:02, 2009-07-13T23:48], the nice domain is [2009-07-13,2009-07-14].
If the domain has more than two values, nicing the domain only affects the first and last value.
interval
- public final TimeScale nice(Interval interval, int step)
This method typically modifies the scale's domain, and may only extend the bounds to the nearest round value.
Nicing is useful if the domain is computed from data and may be irregular. For example, for a domain of [2009-07-13T00:02, 2009-07-13T23:48], the nice domain is [2009-07-13,2009-07-14].
If the domain has more than two values, nicing the domain only affects the first and last value.
interval
- step
- public final <T> Array<T> ticks(int count)
The returned tick dates are uniformly spaced (modulo irregular time intervals, such as months and leap years), have human-readable values (such as midnights), 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.
Approximately count
ticks will be returned. The specified
count is only a hint; the scale may return more or fewer values depending
on the input domain.
For example, to create 10 default ticks, say:
scale.ticks(10);
count
- the number of ticks to be returned; it is only a hint; the
scale may return more or fewer values depending on the input
domainpublic final <T> Array<T> ticks(Interval interval, int steps)
The returned tick dates are uniformly spaced (modulo irregular time intervals, such as months and leap years), have human-readable values (such as midnights), 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.
To create ticks at 15-minute intervals, say:
scale.ticks(D3.time().minute().utc(), 15);
Note: for UTC scales, make sure to use the appropriate UTC range method
(such as d3.time.minutes.utc). The following time intervals are
considered for automatic ticks:
Time.second()
.
Time.minute()
.
Time.hour()
.
Time.day()
.
Time.week()
.
Time.month()
.
Time.year()
.
interval
- the interval of timesteps
- the number of interval between each tickpublic final Formatter tickFormat(int count)
Formatter
function suitable for displaying a tick
value.
The specified count should have the same value as the count that is used to generate the tick values. You don't have to use the scale's built-in tick format, but it automatically computes the appropriate display based on the input date.
The following time formats are considered:
For example, by showing the sequence [11 PM, Mon 07, 01 AM], the tick formatter reveals information about hours, dates, and day simultaneously—rather than just the hours.
If you'd prefer single-scale time formatting, you can always use your own d3.time.format. You can also roll your own custom multi-scale time format.
the
- number of ticks to take into account to create the
Formatter
.Copyright © 2016 gwt-d3. All Rights Reserved.