Commit 6e8f6fd7014668f8e327f02b976e203aa37c06c5
Committed by
GitHub
Merge pull request #4958 from ChantsovaEkaterina/feature/charts-comparison-custom-interval
[3.3.1] UI: add custom interval option to charts comparison
Showing
7 changed files
with
35 additions
and
5 deletions
... | ... | @@ -243,6 +243,7 @@ export interface WidgetSubscriptionOptions { |
243 | 243 | legendConfig?: LegendConfig; |
244 | 244 | comparisonEnabled?: boolean; |
245 | 245 | timeForComparison?: moment_.unitOfTime.DurationConstructor; |
246 | + comparisonCustomIntervalValue?: number; | |
246 | 247 | decimals?: number; |
247 | 248 | units?: string; |
248 | 249 | callbacks?: WidgetSubscriptionCallbacks; | ... | ... |
... | ... | @@ -110,6 +110,7 @@ export class WidgetSubscription implements IWidgetSubscription { |
110 | 110 | units: string; |
111 | 111 | comparisonEnabled: boolean; |
112 | 112 | timeForComparison: ComparisonDuration; |
113 | + comparisonCustomIntervalValue: number; | |
113 | 114 | comparisonTimeWindow: WidgetTimewindow; |
114 | 115 | timewindowForComparison: SubscriptionTimewindow; |
115 | 116 | |
... | ... | @@ -234,6 +235,7 @@ export class WidgetSubscription implements IWidgetSubscription { |
234 | 235 | this.comparisonEnabled = options.comparisonEnabled && isHistoryTypeTimewindow(this.timeWindowConfig); |
235 | 236 | if (this.comparisonEnabled) { |
236 | 237 | this.timeForComparison = options.timeForComparison; |
238 | + this.comparisonCustomIntervalValue = options.comparisonCustomIntervalValue; | |
237 | 239 | |
238 | 240 | this.comparisonTimeWindow = {}; |
239 | 241 | this.timewindowForComparison = null; |
... | ... | @@ -1183,7 +1185,8 @@ export class WidgetSubscription implements IWidgetSubscription { |
1183 | 1185 | } |
1184 | 1186 | |
1185 | 1187 | private updateSubscriptionForComparison(): SubscriptionTimewindow { |
1186 | - this.timewindowForComparison = createTimewindowForComparison(this.subscriptionTimewindow, this.timeForComparison); | |
1188 | + this.timewindowForComparison = createTimewindowForComparison(this.subscriptionTimewindow, this.timeForComparison, | |
1189 | + this.comparisonCustomIntervalValue); | |
1187 | 1190 | this.updateComparisonTimewindow(); |
1188 | 1191 | return this.timewindowForComparison; |
1189 | 1192 | } | ... | ... |
... | ... | @@ -145,6 +145,7 @@ export interface TbFlotComparisonSettings { |
145 | 145 | comparisonEnabled: boolean; |
146 | 146 | timeForComparison: ComparisonDuration; |
147 | 147 | xaxisSecond: TbFlotSecondXAxisSettings; |
148 | + comparisonCustomIntervalValue?: number; | |
148 | 149 | } |
149 | 150 | |
150 | 151 | export interface TbFlotThresholdsSettings { |
... | ... | @@ -546,6 +547,11 @@ const chartSettingsSchemaForComparison: JsonSettingsSchema = { |
546 | 547 | type: 'string', |
547 | 548 | default: 'previousInterval' |
548 | 549 | }, |
550 | + comparisonCustomIntervalValue: { | |
551 | + title: 'Custom interval value (ms)', | |
552 | + type: 'number', | |
553 | + default: 7200000 | |
554 | + }, | |
549 | 555 | xaxisSecond: { |
550 | 556 | title: 'Second X axis', |
551 | 557 | type: 'object', |
... | ... | @@ -596,10 +602,18 @@ const chartSettingsSchemaForComparison: JsonSettingsSchema = { |
596 | 602 | { |
597 | 603 | value: 'years', |
598 | 604 | label: 'Year ago' |
605 | + }, | |
606 | + { | |
607 | + value: 'customInterval', | |
608 | + label: 'Custom interval' | |
599 | 609 | } |
600 | 610 | ] |
601 | 611 | }, |
602 | 612 | { |
613 | + key: 'comparisonCustomIntervalValue', | |
614 | + condition: 'model.timeForComparison === "customInterval"' | |
615 | + }, | |
616 | + { | |
603 | 617 | key: 'xaxisSecond', |
604 | 618 | items: [ |
605 | 619 | { | ... | ... |
... | ... | @@ -908,7 +908,8 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI |
908 | 908 | warnOnPageDataOverflow: this.typeParameters.warnOnPageDataOverflow, |
909 | 909 | ignoreDataUpdateOnIntervalTick: this.typeParameters.ignoreDataUpdateOnIntervalTick, |
910 | 910 | comparisonEnabled: comparisonSettings.comparisonEnabled, |
911 | - timeForComparison: comparisonSettings.timeForComparison | |
911 | + timeForComparison: comparisonSettings.timeForComparison, | |
912 | + comparisonCustomIntervalValue: comparisonSettings.comparisonCustomIntervalValue | |
912 | 913 | }; |
913 | 914 | if (this.widget.type === widgetType.alarm) { |
914 | 915 | options.alarmSource = deepClone(this.widget.config.alarmSource); | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | /// |
16 | 16 | |
17 | 17 | import { TimeService } from '@core/services/time.service'; |
18 | -import { deepClone, isDefined, isUndefined } from '@app/core/utils'; | |
18 | +import { deepClone, isDefined, isNumeric, isUndefined } from '@app/core/utils'; | |
19 | 19 | import * as moment_ from 'moment'; |
20 | 20 | import * as momentTz from 'moment-timezone'; |
21 | 21 | |
... | ... | @@ -28,7 +28,7 @@ export const DAY = 24 * HOUR; |
28 | 28 | export const WEEK = 7 * DAY; |
29 | 29 | export const YEAR = DAY * 365; |
30 | 30 | |
31 | -export type ComparisonDuration = moment_.unitOfTime.DurationConstructor | 'previousInterval'; | |
31 | +export type ComparisonDuration = moment_.unitOfTime.DurationConstructor | 'previousInterval' | 'customInterval'; | |
32 | 32 | |
33 | 33 | export enum TimewindowType { |
34 | 34 | REALTIME, |
... | ... | @@ -640,7 +640,7 @@ export function calculateIntervalComparisonEndTime(interval: QuickTimeInterval, |
640 | 640 | } |
641 | 641 | |
642 | 642 | export function createTimewindowForComparison(subscriptionTimewindow: SubscriptionTimewindow, |
643 | - timeUnit: ComparisonDuration): SubscriptionTimewindow { | |
643 | + timeUnit: ComparisonDuration, customIntervalValue: number): SubscriptionTimewindow { | |
644 | 644 | const timewindowForComparison: SubscriptionTimewindow = { |
645 | 645 | fixedWindow: null, |
646 | 646 | realtimeWindowMs: null, |
... | ... | @@ -667,6 +667,15 @@ export function createTimewindowForComparison(subscriptionTimewindow: Subscripti |
667 | 667 | endTimeMs = subscriptionTimewindow.fixedWindow.startTimeMs; |
668 | 668 | startTimeMs = endTimeMs - timeInterval; |
669 | 669 | } |
670 | + } else if (timeUnit === 'customInterval') { | |
671 | + if (isNumeric(customIntervalValue) && isFinite(customIntervalValue) && customIntervalValue > 0) { | |
672 | + const timeInterval = subscriptionTimewindow.fixedWindow.endTimeMs - subscriptionTimewindow.fixedWindow.startTimeMs; | |
673 | + endTimeMs = subscriptionTimewindow.fixedWindow.endTimeMs - Math.round(customIntervalValue); | |
674 | + startTimeMs = endTimeMs - timeInterval; | |
675 | + } else { | |
676 | + endTimeMs = subscriptionTimewindow.fixedWindow.endTimeMs; | |
677 | + startTimeMs = subscriptionTimewindow.fixedWindow.startTimeMs; | |
678 | + } | |
670 | 679 | } else { |
671 | 680 | const timeInterval = subscriptionTimewindow.fixedWindow.endTimeMs - subscriptionTimewindow.fixedWindow.startTimeMs; |
672 | 681 | endTimeMs = moment(subscriptionTimewindow.fixedWindow.endTimeMs).subtract(1, timeUnit).valueOf(); | ... | ... |
... | ... | @@ -467,6 +467,7 @@ export interface WidgetActionDescriptor extends CustomActionDescriptor { |
467 | 467 | export interface WidgetComparisonSettings { |
468 | 468 | comparisonEnabled?: boolean; |
469 | 469 | timeForComparison?: moment_.unitOfTime.DurationConstructor; |
470 | + comparisonCustomIntervalValue?: number; | |
470 | 471 | } |
471 | 472 | |
472 | 473 | export interface WidgetConfig { | ... | ... |