From f0be7b8b979316a3a573b527dfb9adbce0271fe8 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Thu, 21 May 2020 16:46:25 +0300 Subject: [PATCH 1/2] Fix calculate tooltip --- .../widget/trip-animation/trip-animation.component.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/trip-animation/trip-animation.component.ts b/ui-ngx/src/app/modules/home/components/widget/trip-animation/trip-animation.component.ts index 24f2541caf..cabbf47def 100644 --- a/ui-ngx/src/app/modules/home/components/widget/trip-animation/trip-animation.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/trip-animation/trip-animation.component.ts @@ -63,9 +63,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { activeTrip: FormattedData; label; minTime: number; - minTimeFormat: string; maxTime: number; - maxTimeFormat: string; anchors: number[] = []; useAnchors: boolean; currentTime: number; @@ -97,14 +95,14 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { this.settings = { ...settings, ...this.ctx.settings }; this.useAnchors = this.settings.showPoints && this.settings.usePointAsAnchor; this.settings.pointAsAnchorFunction = parseFunction(this.settings.pointAsAnchorFunction, ['data', 'dsData', 'dsIndex']); + this.settings.tooltipFunction = parseFunction(this.settings.tooltipFunction, ['data', 'dsData', 'dsIndex']); + this.settings.labelFunction = parseFunction(this.settings.labelFunction, ['data', 'dsData', 'dsIndex']); this.settings.fitMapBounds = true; this.normalizationStep = this.settings.normalizationStep; const subscription = this.ctx.subscriptions[Object.keys(this.ctx.subscriptions)[0]]; if (subscription) subscription.callbacks.onDataUpdated = () => { this.historicalData = parseArray(this.ctx.data).filter(arr => arr.length); if (this.historicalData.length) { - if (!this.activeTrip) - this.activeTrip = this.historicalData[0][0]; this.calculateIntervals(); this.timeUpdated(this.currentTime ? this.currentTime : this.minTime); } @@ -167,6 +165,9 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { const maxTimeFormat = this.maxTime !== -Infinity ? moment(this.maxTime).format('YYYY-MM-DD HH:mm:ss') : ''; this.interpolatedTimeData[index] = this.interpolateArray(dataSource, minTimeFormat, maxTimeFormat); }); + if(!this.activeTrip){ + this.activeTrip = this.interpolatedTimeData.map(dataSource => dataSource[this.minTime]).filter(ds => ds)[0]; + } if (this.useAnchors) { const anchorDate = Object.entries(_.union(this.interpolatedTimeData)[0]); this.anchors = anchorDate @@ -181,7 +182,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { } const data = this.activeTrip; const tooltipPattern: string = this.settings.useTooltipFunction ? - safeExecute(this.settings.tooolTipFunction, [data, this.historicalData, point.dsIndex]) : this.settings.tooltipPattern; + safeExecute(this.settings.tooltipFunction, [point, this.historicalData, point.dsIndex]) : this.settings.tooltipPattern; const tooltipText = parseWithTranslation.parseTemplate(tooltipPattern, data, true); if (setTooltip) { this.mainTooltip = this.sanitizer.sanitize( From 0408dd16d3d8d624366d03794b895e442f028eab Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Thu, 21 May 2020 17:28:57 +0300 Subject: [PATCH 2/2] Clear code --- .../widget/trip-animation/trip-animation.component.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/trip-animation/trip-animation.component.ts b/ui-ngx/src/app/modules/home/components/widget/trip-animation/trip-animation.component.ts index cabbf47def..e2678a5147 100644 --- a/ui-ngx/src/app/modules/home/components/widget/trip-animation/trip-animation.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/trip-animation/trip-animation.component.ts @@ -97,7 +97,6 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { this.settings.pointAsAnchorFunction = parseFunction(this.settings.pointAsAnchorFunction, ['data', 'dsData', 'dsIndex']); this.settings.tooltipFunction = parseFunction(this.settings.tooltipFunction, ['data', 'dsData', 'dsIndex']); this.settings.labelFunction = parseFunction(this.settings.labelFunction, ['data', 'dsData', 'dsIndex']); - this.settings.fitMapBounds = true; this.normalizationStep = this.settings.normalizationStep; const subscription = this.ctx.subscriptions[Object.keys(this.ctx.subscriptions)[0]]; if (subscription) subscription.callbacks.onDataUpdated = () => { @@ -180,16 +179,14 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { if (!point) { point = this.activeTrip; } - const data = this.activeTrip; const tooltipPattern: string = this.settings.useTooltipFunction ? safeExecute(this.settings.tooltipFunction, [point, this.historicalData, point.dsIndex]) : this.settings.tooltipPattern; - const tooltipText = parseWithTranslation.parseTemplate(tooltipPattern, data, true); + const tooltipText = parseWithTranslation.parseTemplate(tooltipPattern, point, true); if (setTooltip) { this.mainTooltip = this.sanitizer.sanitize( SecurityContext.HTML, tooltipText); this.cd.detectChanges(); } - this.activeTrip = point; return tooltipText; }