Index: packages/charted/lib/core/scales/time_scale.dart |
diff --git a/packages/charted/lib/core/scales/time_scale.dart b/packages/charted/lib/core/scales/time_scale.dart |
index 8fba314aad972840a764e92919ac282e4f75d8c7..d1b439bca3b63f6853c7bd86d0cf378a183f6973 100644 |
--- a/packages/charted/lib/core/scales/time_scale.dart |
+++ b/packages/charted/lib/core/scales/time_scale.dart |
@@ -11,19 +11,19 @@ part of charted.core.scales; |
/// TimeScale is a linear scale that operates on time. |
class TimeScale extends LinearScale { |
static const _scaleSteps = const [ |
- 1e3, // 1-second |
- 5e3, // 5-second |
- 15e3, // 15-second |
- 3e4, // 30-second |
- 6e4, // 1-minute |
- 3e5, // 5-minute |
- 9e5, // 15-minute |
- 18e5, // 30-minute |
- 36e5, // 1-hour |
- 108e5, // 3-hour |
- 216e5, // 6-hour |
- 432e5, // 12-hour |
- 864e5, // 1-day |
+ 1e3, // 1-second |
+ 5e3, // 5-second |
+ 15e3, // 15-second |
+ 3e4, // 30-second |
+ 6e4, // 1-minute |
+ 3e5, // 5-minute |
+ 9e5, // 15-minute |
+ 18e5, // 30-minute |
+ 36e5, // 1-hour |
+ 108e5, // 3-hour |
+ 216e5, // 6-hour |
+ 432e5, // 12-hour |
+ 864e5, // 1-day |
1728e5, // 2-day |
6048e5, // 1-week |
2592e6, // 1-month |
@@ -40,27 +40,27 @@ class TimeScale extends LinearScale { |
[TimeInterval.minute, 5], |
[TimeInterval.minute, 15], |
[TimeInterval.minute, 30], |
- [TimeInterval.hour, 1], |
- [TimeInterval.hour, 3], |
- [TimeInterval.hour, 6], |
- [TimeInterval.hour, 12], |
- [TimeInterval.day, 1], |
- [TimeInterval.day, 2], |
- [TimeInterval.week, 1], |
- [TimeInterval.month, 1], |
- [TimeInterval.month, 3], |
- [TimeInterval.year, 1] |
+ [TimeInterval.hour, 1], |
+ [TimeInterval.hour, 3], |
+ [TimeInterval.hour, 6], |
+ [TimeInterval.hour, 12], |
+ [TimeInterval.day, 1], |
+ [TimeInterval.day, 2], |
+ [TimeInterval.week, 1], |
+ [TimeInterval.month, 1], |
+ [TimeInterval.month, 3], |
+ [TimeInterval.year, 1] |
]; |
static TimeFormatFunction _scaleLocalFormat = new TimeFormat().multi([ |
- [".%L", (DateTime d) => d.millisecond > 0], |
- [":%S", (DateTime d) => d.second > 0], |
- ["%I:%M", (DateTime d) => d.minute > 0], |
- ["%I %p", (DateTime d) => d.hour > 0], |
- ["%a %d", (DateTime d) => (d.weekday % 7) > 0 && d.day != 1], |
- ["%b %d", (DateTime d) => d.day != 1], |
- ["%B", (DateTime d) => d.month > 1], |
- ["%Y", (d) => true] |
+ [".%L", (DateTime d) => d.millisecond > 0], |
+ [":%S", (DateTime d) => d.second > 0], |
+ ["%I:%M", (DateTime d) => d.minute > 0], |
+ ["%I %p", (DateTime d) => d.hour > 0], |
+ ["%a %d", (DateTime d) => (d.weekday % 7) > 0 && d.day != 1], |
+ ["%b %d", (DateTime d) => d.day != 1], |
+ ["%B", (DateTime d) => d.month > 1], |
+ ["%Y", (d) => true] |
]); |
TimeScale(); |
@@ -72,8 +72,8 @@ class TimeScale extends LinearScale { |
@override |
set domain(Iterable value) { |
- super.domain = value.map( |
- (d) => d is DateTime ? d.millisecondsSinceEpoch : d).toList(); |
+ super.domain = |
+ value.map((d) => d is DateTime ? d.millisecondsSinceEpoch : d).toList(); |
} |
@override |
@@ -83,16 +83,19 @@ class TimeScale extends LinearScale { |
TimeScale clone() => new TimeScale._clone(this); |
List _getTickMethod(Extent extent, int count) { |
- var target = (extent.max - extent.min) / count, |
+ var target = (extent.max - extent.min) / count, |
i = ScaleUtils.bisect(_scaleSteps, target); |
return i == _scaleSteps.length |
- ? [ TimeInterval.year, _linearTickRange( |
- new Extent(extent.min / 31536e6, extent.max / 31536e6)).step ] |
+ ? [ |
+ TimeInterval.year, |
+ _linearTickRange( |
+ new Extent(extent.min / 31536e6, extent.max / 31536e6)).step |
+ ] |
: i == 0 |
- ? [ new ScaleMilliSeconds(), _linearTickRange(extent).step ] |
- : _scaleLocalMethods[ |
- target / _scaleSteps[i - 1] < _scaleSteps[i] / target ? i - 1 : i]; |
+ ? [new ScaleMilliSeconds(), _linearTickRange(extent).step] |
+ : _scaleLocalMethods[target / _scaleSteps[i - 1] < |
+ _scaleSteps[i] / target ? i - 1 : i]; |
} |
List niceInterval(int ticksCount, [int skip = 1]) { |
@@ -107,30 +110,29 @@ class TimeScale extends LinearScale { |
bool skipped(var date) { |
if (date is DateTime) date = date.millisecondsSinceEpoch; |
- return (interval as TimeInterval) |
- .range(date, date + 1, skip).length == 0; |
+ return (interval as TimeInterval).range(date, date + 1, skip).length == 0; |
} |
if (skip > 1) { |
- domain = ScaleUtils.nice(domain, new RoundingFunctions( |
- (date) { |
- while (skipped(date = (interval as TimeInterval).floor(date))) { |
- date = new DateTime.fromMillisecondsSinceEpoch( |
- date.millisecondsSinceEpoch - 1); |
- } |
- return date.millisecondsSinceEpoch; |
- }, |
- (date) { |
- while (skipped(date = (interval as TimeInterval).ceil(date))) { |
- date = new DateTime.fromMillisecondsSinceEpoch( |
- date.millisecondsSinceEpoch + 1); |
- } |
- return date.millisecondsSinceEpoch; |
- } |
- )); |
+ domain = ScaleUtils.nice( |
+ domain, |
+ new RoundingFunctions((date) { |
+ while (skipped(date = (interval as TimeInterval).floor(date))) { |
+ date = new DateTime.fromMillisecondsSinceEpoch( |
+ date.millisecondsSinceEpoch - 1); |
+ } |
+ return date.millisecondsSinceEpoch; |
+ }, (date) { |
+ while (skipped(date = (interval as TimeInterval).ceil(date))) { |
+ date = new DateTime.fromMillisecondsSinceEpoch( |
+ date.millisecondsSinceEpoch + 1); |
+ } |
+ return date.millisecondsSinceEpoch; |
+ })); |
} else { |
domain = ScaleUtils.nice( |
- domain, new RoundingFunctions( |
+ domain, |
+ new RoundingFunctions( |
(date) => interval.floor(date).millisecondsSinceEpoch, |
(date) => interval.ceil(date).millisecondsSinceEpoch)); |
} |
@@ -163,9 +165,10 @@ class TimeScale extends LinearScale { |
class ScaleMilliSeconds implements TimeInterval { |
DateTime _toDateTime(x) { |
- assert (x is int || x is DateTime); |
+ assert(x is int || x is DateTime); |
return x is num ? new DateTime.fromMillisecondsSinceEpoch(x) : x; |
} |
+ |
DateTime floor(dynamic val) => _toDateTime(val); |
DateTime ceil(dynamic val) => _toDateTime(val); |
DateTime round(dynamic val) => _toDateTime(val); |
@@ -179,7 +182,8 @@ class ScaleMilliSeconds implements TimeInterval { |
List range(var t0, var t1, int step) { |
int start = t0 is DateTime ? t0.millisecondsSinceEpoch : t0, |
stop = t1 is DateTime ? t1.millisecondsSinceEpoch : t1; |
- return new Range((start / step).ceil() * step, stop, step).map( |
- (d) => new DateTime.fromMillisecondsSinceEpoch(d)).toList(); |
+ return new Range((start / step).ceil() * step, stop, step) |
+ .map((d) => new DateTime.fromMillisecondsSinceEpoch(d)) |
+ .toList(); |
} |
} |