|
2 | 2 | use chrono::{Date, DateTime, Datelike, Duration, NaiveDate, NaiveDateTime, TimeZone, Timelike}; |
3 | 3 | use std::ops::{Add, Range, Sub}; |
4 | 4 |
|
5 | | -use super::{AsRangedCoord, DiscreteRanged, Ranged, ValueFormatter}; |
| 5 | +use super::{AsRangedCoord, DiscreteRanged, KeyPointHint, Ranged, ValueFormatter}; |
6 | 6 |
|
7 | 7 | /// The trait that describe some time value. This is the uniformed abstraction that works |
8 | 8 | /// for both Date, DateTime and Duration, etc. |
@@ -176,7 +176,8 @@ where |
176 | 176 | TimeValue::map_coord(value, &self.0, &self.1, limit) |
177 | 177 | } |
178 | 178 |
|
179 | | - fn key_points(&self, max_points: usize) -> Vec<Self::ValueType> { |
| 179 | + fn key_points<HintType: KeyPointHint>(&self, hint: HintType) -> Vec<Self::ValueType> { |
| 180 | + let max_points = hint.max_num_points(); |
180 | 181 | let mut ret = vec![]; |
181 | 182 |
|
182 | 183 | let total_days = (self.1.clone() - self.0.clone()).num_days(); |
@@ -263,7 +264,8 @@ impl<T: TimeValue + Clone> Ranged for Monthly<T> { |
263 | 264 | T::map_coord(value, &self.0.start, &self.0.end, limit) |
264 | 265 | } |
265 | 266 |
|
266 | | - fn key_points(&self, max_points: usize) -> Vec<Self::ValueType> { |
| 267 | + fn key_points<HintType: KeyPointHint>(&self, hint: HintType) -> Vec<Self::ValueType> { |
| 268 | + let max_points = hint.max_num_points(); |
267 | 269 | let start_date = self.0.start.date_ceil(); |
268 | 270 | let end_date = self.0.end.date_floor(); |
269 | 271 |
|
@@ -465,7 +467,8 @@ impl<T: TimeValue + Clone> Ranged for Yearly<T> { |
465 | 467 | T::map_coord(value, &self.0.start, &self.0.end, limit) |
466 | 468 | } |
467 | 469 |
|
468 | | - fn key_points(&self, max_points: usize) -> Vec<Self::ValueType> { |
| 470 | + fn key_points<HintType: KeyPointHint>(&self, hint: HintType) -> Vec<Self::ValueType> { |
| 471 | + let max_points = hint.max_num_points(); |
469 | 472 | let start_date = self.0.start.date_ceil(); |
470 | 473 | let end_date = self.0.end.date_floor(); |
471 | 474 |
|
@@ -583,7 +586,8 @@ where |
583 | 586 | TimeValue::map_coord(value, &self.0, &self.1, limit) |
584 | 587 | } |
585 | 588 |
|
586 | | - fn key_points(&self, max_points: usize) -> Vec<Self::ValueType> { |
| 589 | + fn key_points<HintType: KeyPointHint>(&self, hint: HintType) -> Vec<Self::ValueType> { |
| 590 | + let max_points = hint.max_num_points(); |
587 | 591 | let total_span = self.1.clone() - self.0.clone(); |
588 | 592 |
|
589 | 593 | if let Some(total_ns) = total_span.num_nanoseconds() { |
@@ -665,7 +669,8 @@ impl Ranged for RangedDuration { |
665 | 669 | + (f64::from(limit.1 - limit.0) * value_days as f64 / total_days as f64 + 1e-10) as i32 |
666 | 670 | } |
667 | 671 |
|
668 | | - fn key_points(&self, max_points: usize) -> Vec<Self::ValueType> { |
| 672 | + fn key_points<HintType: KeyPointHint>(&self, hint: HintType) -> Vec<Self::ValueType> { |
| 673 | + let max_points = hint.max_num_points(); |
669 | 674 | let total_span = self.1 - self.0; |
670 | 675 |
|
671 | 676 | if let Some(total_ns) = total_span.num_nanoseconds() { |
|
0 commit comments