@@ -23,7 +23,15 @@ import {
23
23
Output ,
24
24
} from '@angular/core' ;
25
25
import { Store } from '@ngrx/store' ;
26
- import { combineLatest , from , Observable , of , Subject } from 'rxjs' ;
26
+ import {
27
+ combineLatest ,
28
+ from ,
29
+ Observable ,
30
+ of ,
31
+ Subject ,
32
+ Subscriber ,
33
+ zip ,
34
+ } from 'rxjs' ;
27
35
import {
28
36
combineLatestWith ,
29
37
debounceTime ,
@@ -57,6 +65,7 @@ import {
57
65
TimeSelectionWithAffordance ,
58
66
} from '../../../widgets/card_fob/card_fob_types' ;
59
67
import { classicSmoothing } from '../../../widgets/line_chart_v2/data_transformer' ;
68
+ import { Extent } from '../../../widgets/line_chart_v2/lib/public_types' ;
60
69
import { ScaleType } from '../../../widgets/line_chart_v2/types' ;
61
70
import {
62
71
linkedTimeToggled ,
@@ -153,6 +162,7 @@ function areSeriesEqual(
153
162
(onTimeSelectionChanged)="onTimeSelectionChanged($event)"
154
163
(onLinkedTimeToggled)="onLinkedTimeToggled($event)"
155
164
(onStepSelectorToggled)="onStepSelectorToggled($event)"
165
+ (onLineChartZoom)="onLineChartZoom($event)"
156
166
></scalar-card-component>
157
167
` ,
158
168
styles : [
@@ -191,6 +201,11 @@ export class ScalarCardContainer implements CardRenderer, OnInit, OnDestroy {
191
201
minMaxSteps$ ?: Observable < MinMaxStep > ;
192
202
columnHeaders$ ?: Observable < ColumnHeaders [ ] > ;
193
203
204
+ private lineChartZoomObservers : Subscriber < Extent > [ ] = [ ] ;
205
+ lineChartZoom$ : Observable < Extent > = new Observable ( ( observer ) => {
206
+ this . lineChartZoomObservers . push ( observer ) ;
207
+ } ) ;
208
+
194
209
onVisibilityChange ( { visible} : { visible : boolean } ) {
195
210
this . isVisible = visible ;
196
211
}
@@ -338,16 +353,18 @@ export class ScalarCardContainer implements CardRenderer, OnInit, OnDestroy {
338
353
shareReplay ( 1 )
339
354
) ;
340
355
341
- this . minMaxSteps$ = partitionedSeries$ . pipe (
342
- map ( ( series ) => {
343
- let minStep = Infinity ;
344
- let maxStep = - Infinity ;
345
- for ( const { points} of series ) {
346
- for ( const point of points ) {
347
- minStep = minStep > point . x ? point . x : minStep ;
348
- maxStep = maxStep < point . x ? point . x : maxStep ;
349
- }
350
- }
356
+ this . minMaxSteps$ = zip ( partitionedSeries$ , this . lineChartZoom$ ) . pipe (
357
+ map ( ( [ series , lineChartViewBox ] ) => {
358
+ const minMax = lineChartViewBox . x ;
359
+ const minInViewPort = Math . ceil ( Math . min ( ...minMax ) ) ;
360
+ const maxInViewPort = Math . floor ( Math . max ( ...minMax ) ) ;
361
+ const allPoints = series
362
+ . map ( ( { points} ) => points . map ( ( { x} ) => x ) )
363
+ . flat ( ) ;
364
+ const min = Math . min ( ...allPoints ) ;
365
+ const max = Math . max ( ...allPoints ) ;
366
+ const minStep = Math . max ( min , minInViewPort ) ;
367
+ const maxStep = Math . min ( max , maxInViewPort ) ;
351
368
return { minStep, maxStep} ;
352
369
} )
353
370
) ;
@@ -608,4 +625,8 @@ export class ScalarCardContainer implements CardRenderer, OnInit, OnDestroy {
608
625
onStepSelectorToggled ( affordance : TimeSelectionToggleAffordance ) {
609
626
this . store . dispatch ( stepSelectorToggled ( { affordance} ) ) ;
610
627
}
628
+
629
+ onLineChartZoom ( extent : Extent ) {
630
+ this . lineChartZoomObservers . forEach ( ( observer ) => observer . next ( extent ) ) ;
631
+ }
611
632
}
0 commit comments