OLD | NEW |
1 // | 1 // |
2 // Copyright 2014 Google Inc. All rights reserved. | 2 // Copyright 2014 Google Inc. All rights reserved. |
3 // | 3 // |
4 // Use of this source code is governed by a BSD-style | 4 // Use of this source code is governed by a BSD-style |
5 // license that can be found in the LICENSE file or at | 5 // license that can be found in the LICENSE file or at |
6 // https://developers.google.com/open-source/licenses/bsd | 6 // https://developers.google.com/open-source/licenses/bsd |
7 // | 7 // |
8 | 8 |
9 part of charted.core.scales; | 9 part of charted.core.scales; |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 ["%a %d", (DateTime d) => (d.weekday % 7) > 0 && d.day != 1], | 60 ["%a %d", (DateTime d) => (d.weekday % 7) > 0 && d.day != 1], |
61 ["%b %d", (DateTime d) => d.day != 1], | 61 ["%b %d", (DateTime d) => d.day != 1], |
62 ["%B", (DateTime d) => d.month > 1], | 62 ["%B", (DateTime d) => d.month > 1], |
63 ["%Y", (d) => true] | 63 ["%Y", (d) => true] |
64 ]); | 64 ]); |
65 | 65 |
66 TimeScale(); | 66 TimeScale(); |
67 TimeScale._clone(TimeScale source) : super._clone(source); | 67 TimeScale._clone(TimeScale source) : super._clone(source); |
68 | 68 |
69 @override | 69 @override |
70 scale(dynamic val) => | 70 scale(Object val) => |
71 super.scale(val is DateTime ? val.millisecondsSinceEpoch : val); | 71 super.scale(val is DateTime ? val.millisecondsSinceEpoch : val); |
72 | 72 |
73 @override | 73 @override |
74 set domain(Iterable value) { | 74 set domain(Iterable value) { |
75 super.domain = | 75 super.domain = |
76 value.map((d) => d is DateTime ? d.millisecondsSinceEpoch : d).toList(); | 76 value.map((d) => d is DateTime ? d.millisecondsSinceEpoch : d).toList(); |
77 } | 77 } |
78 | 78 |
79 @override | 79 @override |
80 FormatFunction createTickFormatter([String format]) => _scaleLocalFormat; | 80 FormatFunction createTickFormatter([String format]) => _scaleLocalFormat; |
(...skipping 28 matching lines...) Expand all Loading... |
109 } | 109 } |
110 | 110 |
111 bool skipped(var date) { | 111 bool skipped(var date) { |
112 if (date is DateTime) date = date.millisecondsSinceEpoch; | 112 if (date is DateTime) date = date.millisecondsSinceEpoch; |
113 return (interval as TimeInterval).range(date, date + 1, skip).length == 0; | 113 return (interval as TimeInterval).range(date, date + 1, skip).length == 0; |
114 } | 114 } |
115 | 115 |
116 if (skip > 1) { | 116 if (skip > 1) { |
117 domain = ScaleUtils.nice( | 117 domain = ScaleUtils.nice( |
118 domain, | 118 domain, |
119 new RoundingFunctions((date) { | 119 new RoundingFunctions((dateMillis) { |
| 120 var date = new DateTime.fromMillisecondsSinceEpoch(dateMillis); |
120 while (skipped(date = (interval as TimeInterval).floor(date))) { | 121 while (skipped(date = (interval as TimeInterval).floor(date))) { |
121 date = new DateTime.fromMillisecondsSinceEpoch( | 122 date = new DateTime.fromMillisecondsSinceEpoch( |
122 date.millisecondsSinceEpoch - 1); | 123 date.millisecondsSinceEpoch - 1); |
123 } | 124 } |
124 return date.millisecondsSinceEpoch; | 125 return date.millisecondsSinceEpoch; |
125 }, (date) { | 126 }, (dateMillis) { |
| 127 var date = new DateTime.fromMillisecondsSinceEpoch(dateMillis); |
126 while (skipped(date = (interval as TimeInterval).ceil(date))) { | 128 while (skipped(date = (interval as TimeInterval).ceil(date))) { |
127 date = new DateTime.fromMillisecondsSinceEpoch( | 129 date = new DateTime.fromMillisecondsSinceEpoch( |
128 date.millisecondsSinceEpoch + 1); | 130 date.millisecondsSinceEpoch + 1); |
129 } | 131 } |
130 return date.millisecondsSinceEpoch; | 132 return date.millisecondsSinceEpoch; |
131 })); | 133 })); |
132 } else { | 134 } else { |
133 domain = ScaleUtils.nice( | 135 domain = ScaleUtils.nice( |
134 domain, | 136 domain, |
135 new RoundingFunctions( | 137 new RoundingFunctions( |
(...skipping 30 matching lines...) Expand all Loading... |
166 class ScaleMilliSeconds implements TimeInterval { | 168 class ScaleMilliSeconds implements TimeInterval { |
167 DateTime _toDateTime(x) { | 169 DateTime _toDateTime(x) { |
168 assert(x is int || x is DateTime); | 170 assert(x is int || x is DateTime); |
169 return x is num ? new DateTime.fromMillisecondsSinceEpoch(x) : x; | 171 return x is num ? new DateTime.fromMillisecondsSinceEpoch(x) : x; |
170 } | 172 } |
171 | 173 |
172 DateTime floor(dynamic val) => _toDateTime(val); | 174 DateTime floor(dynamic val) => _toDateTime(val); |
173 DateTime ceil(dynamic val) => _toDateTime(val); | 175 DateTime ceil(dynamic val) => _toDateTime(val); |
174 DateTime round(dynamic val) => _toDateTime(val); | 176 DateTime round(dynamic val) => _toDateTime(val); |
175 | 177 |
176 DateTime offset(dynamic val, num dt) { | 178 DateTime offset(Object val, num dt) { |
177 assert(val is int || val is DateTime); | 179 assert(val is int || val is DateTime); |
178 return new DateTime.fromMillisecondsSinceEpoch( | 180 return new DateTime.fromMillisecondsSinceEpoch( |
179 val is int ? val + dt : (val as DateTime).millisecondsSinceEpoch + dt); | 181 val is int ? val + dt : (val as DateTime).millisecondsSinceEpoch + dt); |
180 } | 182 } |
181 | 183 |
182 List range(var t0, var t1, int step) { | 184 List<DateTime> range(var t0, var t1, int step) { |
183 int start = t0 is DateTime ? t0.millisecondsSinceEpoch : t0, | 185 int start = t0 is DateTime ? t0.millisecondsSinceEpoch : t0, |
184 stop = t1 is DateTime ? t1.millisecondsSinceEpoch : t1; | 186 stop = t1 is DateTime ? t1.millisecondsSinceEpoch : t1; |
185 return new Range((start / step).ceil() * step, stop, step) | 187 return new Range((start / step).ceil() * step, stop, step) |
186 .map((d) => new DateTime.fromMillisecondsSinceEpoch(d)) | 188 .map((d) => new DateTime.fromMillisecondsSinceEpoch(d)) |
187 .toList(); | 189 .toList(); |
188 } | 190 } |
189 } | 191 } |
OLD | NEW |