From 3c27e8ad7f5c31e6900c6b44d23acff37378384c Mon Sep 17 00:00:00 2001 From: Miki Date: Wed, 27 Nov 2019 20:01:16 -0800 Subject: [PATCH] Allow skipping on certain period-changes --- src/.internal/charts/axes/DateAxis.ts | 52 +++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/src/.internal/charts/axes/DateAxis.ts b/src/.internal/charts/axes/DateAxis.ts index 4967e0f79..85e995198 100644 --- a/src/.internal/charts/axes/DateAxis.ts +++ b/src/.internal/charts/axes/DateAxis.ts @@ -402,6 +402,26 @@ export class DateAxis extends ValueAxis = new Dictionary(); + /** + * When detecting a period change, these units will be skipped in favor of a larger unit. + * + * This allows us to format the next higher unit while zooming, like zooming into: + * + * `22:00 - 23:00 - [b]Jan 1[b] - 01:00 - ...` + * + * Instead of: + * + * `23:00 - 23:30 - [b]00:00[b] - 00:30` + * + * We can have: + * + * `23:00 - 23:30 - [b]Jan 1[b] - 00:30` + * + * This gets overriden by setting `markUnitChange = false`. + */ + + public skipPeriodChanges: List = new List(); + /** * At which intervals grid elements are displayed. */ @@ -1260,6 +1280,16 @@ export class DateAxis extends ValueAxis extends ValueAxis extends ValueAxis 0) { let timeUnit: TimeUnit = axisBreak.gridInterval.timeUnit; let intervalCount: number = axisBreak.gridInterval.count; + let timeUnitAfterSkipping: TimeUnit = timeUnit; + if (this.markUnitChange) { + while (this.skipPeriodChanges.contains(timeUnitAfterSkipping)) { + timeUnitAfterSkipping = $time.getNextUnit(timeUnitAfterSkipping); + } + if (timeUnitAfterSkipping === "year") { + timeUnitAfterSkipping = null; + } + } + let nextGridUnit: TimeUnit = $time.getNextUnit(timeUnitAfterSkipping); // only add grid if gap is bigger then minGridDistance if ($math.getDistance(axisBreak.startPoint, axisBreak.endPoint) > renderer.minGridDistance * 4) { @@ -1326,9 +1366,9 @@ export class DateAxis extends ValueAxis