@@ -24,13 +24,12 @@ import {
24
24
} from '@angular/core' ;
25
25
import { Store } from '@ngrx/store' ;
26
26
import {
27
+ BehaviorSubject ,
27
28
combineLatest ,
28
29
from ,
29
30
Observable ,
30
31
of ,
31
32
Subject ,
32
- Subscriber ,
33
- zip ,
34
33
} from 'rxjs' ;
35
34
import {
36
35
combineLatestWith ,
@@ -201,9 +200,9 @@ export class ScalarCardContainer implements CardRenderer, OnInit, OnDestroy {
201
200
minMaxSteps$ ?: Observable < MinMaxStep > ;
202
201
columnHeaders$ ?: Observable < ColumnHeaders [ ] > ;
203
202
204
- private lineChartZoomObservers : Subscriber < Extent > [ ] = [ ] ;
205
- lineChartZoom$ : Observable < Extent > = new Observable ( ( observer ) => {
206
- this . lineChartZoomObservers . push ( observer ) ;
203
+ lineChartZoom$ = new BehaviorSubject < MinMaxStep > ( {
204
+ minStep : - Infinity ,
205
+ maxStep : Infinity ,
207
206
} ) ;
208
207
209
208
onVisibilityChange ( { visible} : { visible : boolean } ) {
@@ -353,18 +352,19 @@ export class ScalarCardContainer implements CardRenderer, OnInit, OnDestroy {
353
352
shareReplay ( 1 )
354
353
) ;
355
354
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 ) ) ;
355
+ this . minMaxSteps$ = combineLatest ( [
356
+ partitionedSeries$ ,
357
+ this . lineChartZoom$ ,
358
+ ] ) . pipe (
359
+ map ( ( [ series , viewPort ] ) => {
361
360
const allPoints = series
362
361
. map ( ( { points} ) => points . map ( ( { x} ) => x ) )
363
362
. flat ( ) ;
364
363
const min = Math . min ( ...allPoints ) ;
365
364
const max = Math . max ( ...allPoints ) ;
366
- const minStep = Math . max ( min , minInViewPort ) ;
367
- const maxStep = Math . min ( max , maxInViewPort ) ;
365
+ const minStep = Math . max ( min , viewPort . minStep ) ;
366
+ const maxStep = Math . min ( max , viewPort . maxStep ) ;
367
+
368
368
return { minStep, maxStep} ;
369
369
} )
370
370
) ;
@@ -626,7 +626,12 @@ export class ScalarCardContainer implements CardRenderer, OnInit, OnDestroy {
626
626
this . store . dispatch ( stepSelectorToggled ( { affordance} ) ) ;
627
627
}
628
628
629
- onLineChartZoom ( extent : Extent ) {
630
- this . lineChartZoomObservers . forEach ( ( observer ) => observer . next ( extent ) ) ;
629
+ onLineChartZoom ( lineChartViewBox : Extent ) {
630
+ const minMax = lineChartViewBox . x ;
631
+ const minMaxStepInViewPort : MinMaxStep = {
632
+ minStep : Math . ceil ( Math . min ( ...minMax ) ) ,
633
+ maxStep : Math . floor ( Math . max ( ...minMax ) ) ,
634
+ } ;
635
+ this . lineChartZoom$ . next ( minMaxStepInViewPort ) ;
631
636
}
632
637
}
0 commit comments