@orbcharts/core 3.0.5 → 3.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbcharts/core",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "description": "Core codes for OrbCharts",
5
5
  "author": "Blue Planet Inc.",
6
6
  "license": "Apache-2.0",
@@ -39,7 +39,7 @@
39
39
  "vite-plugin-dts": "^3.7.3"
40
40
  },
41
41
  "dependencies": {
42
- "@orbcharts/core-types": "^3.0.3",
42
+ "@orbcharts/core-types": "^3.0.5",
43
43
  "d3": "^7.8.5",
44
44
  "rxjs": "^7.8.1"
45
45
  }
@@ -139,6 +139,13 @@ export const contextObserverCallback: ContextObserverCallback<'grid'> = ({ subje
139
139
  shareReplay(1)
140
140
  )
141
141
 
142
+ const filteredStackedMinMaxValue$ = filteredMinMaxValueObservable({
143
+ computedData$: computedStackedData$,
144
+ groupScaleDomainValue$: groupScaleDomainValue$,
145
+ }).pipe(
146
+ shareReplay(1)
147
+ )
148
+
142
149
  const gridAxesTransform$ = gridAxesTransformObservable({
143
150
  fullDataFormatter$: observer.fullDataFormatter$,
144
151
  layout$: observer.layout$
@@ -193,6 +200,7 @@ export const contextObserverCallback: ContextObserverCallback<'grid'> = ({ subje
193
200
  computedStackedData$,
194
201
  groupScaleDomainValue$,
195
202
  filteredMinMaxValue$,
203
+ filteredStackedMinMaxValue$,
196
204
  gridAxesTransform$,
197
205
  gridAxesReverseTransform$,
198
206
  gridGraphicTransform$,
@@ -586,9 +586,11 @@ export const gridGraphicTransformObservable = ({ computedData$, groupScaleDomain
586
586
  // })
587
587
 
588
588
  // const filteredMinMax = getMinMaxGrid(filteredData)
589
- if (filteredMinMaxValue[0] === filteredMinMaxValue[1] && filteredMinMaxValue[1] === 0) {
589
+ const filteredMin = filteredMinMaxValue[0]
590
+ let filteredMax = filteredMinMaxValue[1]
591
+ if (filteredMin === filteredMax && filteredMax === 0) {
590
592
  // filteredMinMaxValue[0] = filteredMinMaxValue[1] - 1 // 避免最大及最小值相同造成無法計算scale
591
- filteredMinMaxValue[1] = 1 // 避免最大及最小值同等於 0 造成無法計算scale
593
+ filteredMax = 1 // 避免最大及最小值同等於 0 造成無法計算scale
592
594
  }
593
595
 
594
596
  const valueAxisWidth = (valueAxis.position === 'left' || valueAxis.position === 'right')
@@ -596,8 +598,8 @@ export const gridGraphicTransformObservable = ({ computedData$, groupScaleDomain
596
598
  : width
597
599
 
598
600
  const valueScale: d3.ScaleLinear<number, number> = createValueToAxisScale({
599
- maxValue: filteredMinMaxValue[1],
600
- minValue: filteredMinMaxValue[0],
601
+ maxValue: filteredMax,
602
+ minValue: filteredMin,
601
603
  axisWidth: valueAxisWidth,
602
604
  scaleDomain: valueAxis.scaleDomain,
603
605
  scaleRange: valueAxis.scaleRange
@@ -611,9 +613,11 @@ export const gridGraphicTransformObservable = ({ computedData$, groupScaleDomain
611
613
  // })
612
614
  // -- translateY, scaleY --
613
615
  const minMax = getMinMaxGrid(data)
614
- if (minMax[0] === minMax[1] && minMax[1] === 0) {
616
+ const min = minMax[0]
617
+ let max = minMax[1]
618
+ if (min === max && max === 0) {
615
619
  // minMax[0] = minMax[1] - 1 // 避免最大及最小值相同造成無法計算scale
616
- minMax[1] = 1 // 避免最大及最小值同等於 0 造成無法計算scale
620
+ max = 1 // 避免最大及最小值同等於 0 造成無法計算scale
617
621
  }
618
622
  // const rangeMinY = valueScale(minMax[0])
619
623
  const rangeMinY = valueScale(minMax[0] > 0 ? 0 : minMax[0]) // * 因為原本的座標就是以 0 到最大值或最小值範範圍計算的,所以這邊也是用同樣的方式計算
@@ -1,11 +1,15 @@
1
1
  import {
2
2
  map,
3
- shareReplay } from 'rxjs'
3
+ switchMap,
4
+ merge,
5
+ forkJoin,
6
+ shareReplay,
7
+ Observable } from 'rxjs'
4
8
  import type { ContextObserverCallback, DataGridDatum } from '../../lib/core-types'
5
9
  import { multiGridEachDetailObservable, multiGridContainerObservable } from './multiGridObservables'
6
10
  import { textSizePxObservable, containerSizeObservable, highlightObservable } from '../utils/observables'
7
11
  // import { createMultiGridSeriesLabels } from '../utils/orbchartsUtils'
8
- import { combineLatest } from 'rxjs/internal/observable/combineLatest'
12
+ import { filteredMinMaxValueObservable } from '../grid/gridObservables'
9
13
 
10
14
  export const contextObserverCallback: ContextObserverCallback<'multiGrid'> = ({ subject, observer }) => {
11
15
 
@@ -59,6 +63,34 @@ export const contextObserverCallback: ContextObserverCallback<'multiGrid'> = ({
59
63
  // console.log('multiGridContainerPosition$', d)
60
64
  // })
61
65
 
66
+ const filteredMinMaxValue$: Observable<[number, number]> = multiGridEachDetail$.pipe(
67
+ switchMap(details => {
68
+ return forkJoin(details.map((detail, index) => {
69
+ return detail.filteredMinMaxValue$
70
+ }))
71
+ }),
72
+ map(filteredMinMaxValue => {
73
+ return [
74
+ Math.min(...filteredMinMaxValue.map(d => d[0])),
75
+ Math.max(...filteredMinMaxValue.map(d => d[1]))
76
+ ]
77
+ })
78
+ )
79
+
80
+ const filteredStackedMinMaxValue$: Observable<[number, number]> = multiGridEachDetail$.pipe(
81
+ switchMap(details => {
82
+ return forkJoin(details.map((detail, index) => {
83
+ return detail.filteredStackedMinMaxValue$
84
+ }))
85
+ }),
86
+ map(filteredMinMaxValue => {
87
+ return [
88
+ Math.min(...filteredMinMaxValue.map(d => d[0])),
89
+ Math.max(...filteredMinMaxValue.map(d => d[1]))
90
+ ]
91
+ })
92
+ )
93
+
62
94
  return {
63
95
  fullParams$: observer.fullParams$,
64
96
  fullChartParams$: observer.fullChartParams$,
@@ -69,6 +101,8 @@ export const contextObserverCallback: ContextObserverCallback<'multiGrid'> = ({
69
101
  containerSize$,
70
102
  multiGridHighlight$,
71
103
  multiGridContainerPosition$,
104
+ filteredMinMaxValue$,
105
+ filteredStackedMinMaxValue$,
72
106
  multiGridEachDetail$,
73
107
  // multiGridContainer$
74
108
  }
@@ -247,6 +247,14 @@ export const multiGridEachDetailObservable = ({ fullDataFormatter$, computedData
247
247
  shareReplay(1)
248
248
  )
249
249
 
250
+ const filteredStackedMinMaxValue$ = filteredMinMaxValueObservable({
251
+ computedData$: computedStackedData$,
252
+ groupScaleDomainValue$: groupScaleDomainValue$,
253
+ }).pipe(
254
+ takeUntil(destroy$),
255
+ shareReplay(1)
256
+ )
257
+
250
258
  const gridAxesTransform$ = gridAxesTransformObservable({
251
259
  fullDataFormatter$: gridDataFormatter$,
252
260
  layout$: layout$
@@ -297,6 +305,7 @@ export const multiGridEachDetailObservable = ({ fullDataFormatter$, computedData
297
305
  computedStackedData$,
298
306
  groupScaleDomainValue$,
299
307
  filteredMinMaxValue$,
308
+ filteredStackedMinMaxValue$,
300
309
  gridAxesTransform$,
301
310
  gridAxesReverseTransform$,
302
311
  gridGraphicTransform$,
@@ -53,7 +53,7 @@ interface HighlightTargetValue {
53
53
  seriesLabel: string | null
54
54
  groupLabel: string | null
55
55
  categoryLabel: string | null
56
- highlightDefault: string | null
56
+ // highlightDefault: string | null
57
57
  }
58
58
 
59
59
  // 通用 highlight Observable
@@ -67,16 +67,16 @@ export const highlightObservable = <T extends ChartType, D>({ datumList$, fullCh
67
67
  // 預設的highlight
68
68
  const highlightDefault$: Observable<HighlightTargetValue> = fullChartParams$.pipe(
69
69
  takeUntil(destroy$),
70
- map(d => d.highlightDefault),
70
+ map(d => d.highlightDefault || null),
71
71
  distinctUntilChanged(),
72
72
  map(highlightDefault => {
73
73
  return {
74
- id: null,
75
- label: null,
76
- seriesLabel: null,
77
- groupLabel: null,
78
- categoryLabel: null,
79
- highlightDefault
74
+ id: highlightDefault,
75
+ label: highlightDefault,
76
+ seriesLabel: highlightDefault,
77
+ groupLabel: highlightDefault,
78
+ categoryLabel: highlightDefault,
79
+ // highlightDefault
80
80
  } as HighlightTargetValue
81
81
  }),
82
82
  shareReplay(1)
@@ -106,7 +106,7 @@ export const highlightObservable = <T extends ChartType, D>({ datumList$, fullCh
106
106
  seriesLabel: highlightTarget === 'series' ? d.datum.seriesLabel : null,
107
107
  groupLabel: highlightTarget === 'group' ? d.datum.groupLabel : null,
108
108
  categoryLabel: highlightTarget === 'category' ? d.datum.categoryLabel : null,
109
- highlightDefault: null
109
+ // highlightDefault: null
110
110
  } as HighlightTargetValue
111
111
  : {
112
112
  id: null,
@@ -114,7 +114,7 @@ export const highlightObservable = <T extends ChartType, D>({ datumList$, fullCh
114
114
  seriesLabel: null,
115
115
  groupLabel: null,
116
116
  categoryLabel: null,
117
- highlightDefault: null
117
+ // highlightDefault: null
118
118
  } as HighlightTargetValue
119
119
  })
120
120
  )
@@ -178,7 +178,6 @@ export const highlightObservable = <T extends ChartType, D>({ datumList$, fullCh
178
178
  } else if (data.fullChartParams.highlightTarget === 'category') {
179
179
  datumList = getCategoryIds(data.datumList as ComputedDatumTypeMap<T>[], data.target.categoryLabel)
180
180
  }
181
-
182
181
  subscriber.next(datumList as D[])
183
182
  })
184
183