@orbcharts/core 3.0.4 → 3.0.5

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.
Files changed (69) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +1685 -1636
  3. package/dist/orbcharts-core.umd.js +4 -4
  4. package/dist/src/series/seriesObservables.d.ts +18 -7
  5. package/lib/core-types.ts +7 -7
  6. package/package.json +46 -46
  7. package/src/AbstractChart.ts +57 -57
  8. package/src/GridChart.ts +24 -24
  9. package/src/MultiGridChart.ts +24 -24
  10. package/src/MultiValueChart.ts +24 -24
  11. package/src/RelationshipChart.ts +24 -24
  12. package/src/SeriesChart.ts +24 -24
  13. package/src/TreeChart.ts +24 -24
  14. package/src/base/createBaseChart.ts +524 -524
  15. package/src/base/createBasePlugin.ts +154 -154
  16. package/src/base/validators/chartOptionsValidator.ts +23 -23
  17. package/src/base/validators/chartParamsValidator.ts +133 -133
  18. package/src/base/validators/elementValidator.ts +13 -13
  19. package/src/base/validators/pluginsValidator.ts +14 -14
  20. package/src/defaults.ts +284 -283
  21. package/src/defineGridPlugin.ts +3 -3
  22. package/src/defineMultiGridPlugin.ts +3 -3
  23. package/src/defineMultiValuePlugin.ts +3 -3
  24. package/src/defineNoneDataPlugin.ts +4 -4
  25. package/src/defineRelationshipPlugin.ts +3 -3
  26. package/src/defineSeriesPlugin.ts +3 -3
  27. package/src/defineTreePlugin.ts +3 -3
  28. package/src/grid/computedDataFn.ts +129 -129
  29. package/src/grid/contextObserverCallback.ts +201 -201
  30. package/src/grid/dataFormatterValidator.ts +125 -125
  31. package/src/grid/dataValidator.ts +12 -12
  32. package/src/grid/gridObservables.ts +694 -718
  33. package/src/index.ts +20 -20
  34. package/src/multiGrid/computedDataFn.ts +123 -123
  35. package/src/multiGrid/contextObserverCallback.ts +75 -75
  36. package/src/multiGrid/dataFormatterValidator.ts +120 -120
  37. package/src/multiGrid/dataValidator.ts +12 -12
  38. package/src/multiGrid/multiGridObservables.ts +357 -401
  39. package/src/multiValue/computedDataFn.ts +113 -113
  40. package/src/multiValue/contextObserverCallback.ts +328 -328
  41. package/src/multiValue/dataFormatterValidator.ts +94 -94
  42. package/src/multiValue/dataValidator.ts +12 -12
  43. package/src/multiValue/multiValueObservables.ts +865 -1219
  44. package/src/relationship/computedDataFn.ts +159 -159
  45. package/src/relationship/contextObserverCallback.ts +80 -80
  46. package/src/relationship/dataFormatterValidator.ts +13 -13
  47. package/src/relationship/dataValidator.ts +13 -13
  48. package/src/relationship/relationshipObservables.ts +84 -84
  49. package/src/series/computedDataFn.ts +88 -88
  50. package/src/series/contextObserverCallback.ts +132 -107
  51. package/src/series/dataFormatterValidator.ts +46 -46
  52. package/src/series/dataValidator.ts +12 -12
  53. package/src/series/seriesObservables.ts +209 -175
  54. package/src/tree/computedDataFn.ts +129 -129
  55. package/src/tree/contextObserverCallback.ts +58 -58
  56. package/src/tree/dataFormatterValidator.ts +13 -13
  57. package/src/tree/dataValidator.ts +13 -13
  58. package/src/tree/treeObservables.ts +105 -105
  59. package/src/utils/commonUtils.ts +55 -55
  60. package/src/utils/d3Scale.ts +198 -198
  61. package/src/utils/errorMessage.ts +40 -40
  62. package/src/utils/index.ts +3 -3
  63. package/src/utils/observables.ts +308 -293
  64. package/src/utils/orbchartsUtils.ts +396 -396
  65. package/src/utils/validator.ts +126 -126
  66. package/tsconfig.base.json +13 -13
  67. package/tsconfig.json +2 -2
  68. package/vite-env.d.ts +6 -6
  69. package/vite.config.js +22 -22
@@ -1,402 +1,358 @@
1
- import {
2
- combineLatest,
3
- distinctUntilChanged,
4
- filter,
5
- of,
6
- map,
7
- merge,
8
- takeUntil,
9
- shareReplay,
10
- switchMap,
11
- Subject,
12
- Observable,
13
- combineLatestAll} from 'rxjs'
14
- import type {
15
- AxisPosition,
16
- ChartType,
17
- ChartParams,
18
- ComputedDataTypeMap,
19
- ComputedDataGrid,
20
- ContextObserverMultiGridDetail,
21
- ContainerSize,
22
- DataTypeMap,
23
- DataFormatterTypeMap,
24
- DataFormatterGrid,
25
- DataFormatterMultiGridContainer,
26
- EventMultiGrid,
27
- ContainerPositionScaled,
28
- HighlightTarget,
29
- Layout,
30
- TransformData } from '../../lib/core-types'
31
- import {
32
- highlightObservable,
33
- seriesDataMapObservable,
34
- groupDataMapObservable } from '../utils/observables'
35
- import {
36
- gridComputedAxesDataObservable,
37
- gridAxesSizeObservable,
38
- gridAxesContainerSizeObservable,
39
- gridSeriesLabelsObservable,
40
- gridVisibleComputedDataObservable,
41
- gridVisibleComputedAxesDataObservable,
42
- // isSeriesSeprateObservable,
43
- gridContainerPositionObservable,
44
- computedStackedDataObservables,
45
- groupScaleDomainValueObservable,
46
- filteredMinMaxValueObservable,
47
- gridAxesTransformObservable,
48
- gridAxesReverseTransformObservable,
49
- gridGraphicTransformObservable,
50
- gridGraphicReverseScaleObservable,
51
- } from '../grid/gridObservables'
52
- import { DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID } from '../defaults'
53
- import { calcContainerPositionScaled } from '../utils/orbchartsUtils'
54
-
55
- // 每一個grid計算出來的所有Observable
56
- export const multiGridEachDetailObservable = ({ fullDataFormatter$, computedData$, layout$, fullChartParams$, event$, containerSize$ }: {
57
- fullDataFormatter$: Observable<DataFormatterTypeMap<'multiGrid'>>
58
- computedData$: Observable<ComputedDataTypeMap<'multiGrid'>>
59
- layout$: Observable<Layout>
60
- fullChartParams$: Observable<ChartParams>
61
- event$: Subject<EventMultiGrid>
62
- containerSize$: Observable<ContainerSize>
63
- }): Observable<ContextObserverMultiGridDetail[]> => {
64
-
65
- const destroy$ = new Subject()
66
-
67
- // // highlight全部grid
68
- // const allGridHighlight$ = highlightObservable({
69
- // datumList$: computedData$.pipe(
70
- // map(d => d.flat().flat()),
71
- // shareReplay(1)
72
- // ),
73
- // fullChartParams$: fullChartParams$,
74
- // event$: event$
75
- // }).pipe(
76
- // shareReplay(1)
77
- // )
78
-
79
- const multiGridContainer$ = multiGridContainerObservable({
80
- computedData$: computedData$,
81
- fullDataFormatter$: fullDataFormatter$,
82
- layout$: layout$,
83
- }).pipe(
84
- shareReplay(1)
85
- )
86
-
87
- return combineLatest({
88
- fullDataFormatter: fullDataFormatter$,
89
- computedData: computedData$,
90
- multiGridContainer: multiGridContainer$
91
- }).pipe(
92
- switchMap(async (d) => d),
93
- // distinctUntilChanged((a, b) => {
94
- // // 只有當computedData的長度改變時,才重新計算
95
- // return a.computedData.length === b.computedData.length
96
- // }),
97
- map(data => {
98
- // 每次重新計算時,清除之前的訂閱
99
- destroy$.next(undefined)
100
-
101
- const defaultGrid = data.fullDataFormatter.gridList[0] ?? DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID
102
-
103
- return data.computedData.map((gridComputedData, gridIndex) => {
104
-
105
- // -- 取得該grid的data和dataFormatter
106
- const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
107
- const gridDataFormatter: DataFormatterGrid = {
108
- type: 'grid',
109
- visibleFilter: data.fullDataFormatter.visibleFilter as any,
110
- // grid: {
111
- ...grid,
112
- // },
113
- container: {
114
- ...data.fullDataFormatter.container
115
- }
116
- }
117
- const gridDataFormatter$ = of(gridDataFormatter).pipe(
118
- takeUntil(destroy$),
119
- shareReplay(1)
120
- )
121
- const gridComputedData$ = of(gridComputedData).pipe(
122
- takeUntil(destroy$),
123
- shareReplay(1)
124
- )
125
-
126
- // const isSeriesSeprate$ = isSeriesSeprateObservable({
127
- // computedData$: gridComputedData$,
128
- // fullDataFormatter$: gridDataFormatter$,
129
- // }).pipe(
130
- // takeUntil(destroy$),
131
- // shareReplay(1)
132
- // )
133
-
134
- // const gridContainerPosition$ = gridContainerPositionObservable({
135
- // computedData$: gridComputedData$,
136
- // fullDataFormatter$: gridDataFormatter$,
137
- // layout$
138
- // }).pipe(
139
- // shareReplay(1)
140
- // )
141
-
142
- const isSeriesSeprate$ = gridDataFormatter$.pipe(
143
- map(d => d.separateSeries),
144
- distinctUntilChanged(),
145
- shareReplay(1)
146
- )
147
-
148
- const gridContainerPosition$ = of(data.multiGridContainer[gridIndex]).pipe(
149
- takeUntil(destroy$),
150
- shareReplay(1)
151
- )
152
-
153
- const gridAxesSize$ = gridAxesSizeObservable({
154
- fullDataFormatter$: gridDataFormatter$,
155
- layout$: layout$
156
- }).pipe(
157
- takeUntil(destroy$),
158
- shareReplay(1)
159
- )
160
-
161
- const gridAxesContainerSize$ = gridAxesContainerSizeObservable({
162
- fullDataFormatter$: gridDataFormatter$,
163
- containerSize$: containerSize$
164
- }).pipe(
165
- shareReplay(1)
166
- )
167
-
168
- const datumList$ = gridComputedData$.pipe(
169
- map(d => d.flat())
170
- ).pipe(
171
- takeUntil(destroy$),
172
- shareReplay(1)
173
- )
174
-
175
- // const gridHighlight$ = highlightObservable({
176
- // datumList$,
177
- // fullChartParams$: fullChartParams$,
178
- // event$: event$
179
- // }).pipe(
180
- // shareReplay(1)
181
- // )
182
-
183
- const seriesLabels$ = gridSeriesLabelsObservable({
184
- computedData$: gridComputedData$,
185
- }).pipe(
186
- takeUntil(destroy$),
187
- shareReplay(1)
188
- )
189
-
190
- const SeriesDataMap$ = seriesDataMapObservable({
191
- datumList$: datumList$
192
- }).pipe(
193
- takeUntil(destroy$),
194
- shareReplay(1)
195
- )
196
-
197
- const GroupDataMap$ = groupDataMapObservable({
198
- datumList$: datumList$
199
- }).pipe(
200
- takeUntil(destroy$),
201
- shareReplay(1)
202
- )
203
-
204
- const visibleComputedData$ = gridVisibleComputedDataObservable({
205
- computedData$: gridComputedData$,
206
- }).pipe(
207
- takeUntil(destroy$),
208
- shareReplay(1)
209
- )
210
-
211
- const computedAxesData$ = gridComputedAxesDataObservable({
212
- computedData$: gridComputedData$,
213
- fullDataFormatter$: gridDataFormatter$,
214
- layout$: layout$,
215
- }).pipe(
216
- takeUntil(destroy$),
217
- shareReplay(1)
218
- )
219
-
220
- const visibleComputedAxesData$ = gridVisibleComputedAxesDataObservable({
221
- computedAxesData$: computedAxesData$,
222
- }).pipe(
223
- takeUntil(destroy$),
224
- shareReplay(1)
225
- )
226
-
227
- const computedStackedData$ = computedStackedDataObservables({
228
- computedData$: gridComputedData$,
229
- isSeriesSeprate$: isSeriesSeprate$
230
- }).pipe(
231
- shareReplay(1)
232
- )
233
-
234
- const groupScaleDomainValue$ = groupScaleDomainValueObservable({
235
- computedData$: gridComputedData$,
236
- fullDataFormatter$: gridDataFormatter$,
237
- }).pipe(
238
- takeUntil(destroy$),
239
- shareReplay(1)
240
- )
241
-
242
- const filteredMinMaxValue$ = filteredMinMaxValueObservable({
243
- computedData$: gridComputedData$,
244
- groupScaleDomainValue$: groupScaleDomainValue$,
245
- }).pipe(
246
- takeUntil(destroy$),
247
- shareReplay(1)
248
- )
249
-
250
- const gridAxesTransform$ = gridAxesTransformObservable({
251
- fullDataFormatter$: gridDataFormatter$,
252
- layout$: layout$
253
- }).pipe(
254
- takeUntil(destroy$),
255
- shareReplay(1)
256
- )
257
-
258
-
259
- const gridAxesReverseTransform$ = gridAxesReverseTransformObservable({
260
- gridAxesTransform$
261
- }).pipe(
262
- takeUntil(destroy$),
263
- shareReplay(1)
264
- )
265
-
266
- const gridGraphicTransform$ = gridGraphicTransformObservable({
267
- computedData$: gridComputedData$,
268
- groupScaleDomainValue$: groupScaleDomainValue$,
269
- filteredMinMaxValue$: filteredMinMaxValue$,
270
- fullDataFormatter$: gridDataFormatter$,
271
- layout$: layout$
272
- }).pipe(
273
- takeUntil(destroy$),
274
- shareReplay(1)
275
- )
276
-
277
- const gridGraphicReverseScale$ = gridGraphicReverseScaleObservable({
278
- gridContainerPosition$: gridContainerPosition$,
279
- gridAxesTransform$: gridAxesTransform$,
280
- gridGraphicTransform$: gridGraphicTransform$,
281
- })
282
-
283
- return {
284
- isSeriesSeprate$,
285
- gridContainerPosition$,
286
- gridAxesSize$,
287
- gridAxesContainerSize$,
288
- // gridHighlight$: allGridHighlight$,
289
- seriesLabels$,
290
- SeriesDataMap$,
291
- GroupDataMap$,
292
- dataFormatter$: gridDataFormatter$,
293
- computedData$: gridComputedData$,
294
- computedAxesData$,
295
- visibleComputedData$,
296
- visibleComputedAxesData$,
297
- computedStackedData$,
298
- groupScaleDomainValue$,
299
- filteredMinMaxValue$,
300
- gridAxesTransform$,
301
- gridAxesReverseTransform$,
302
- gridGraphicTransform$,
303
- gridGraphicReverseScale$,
304
- }
305
- })
306
- })
307
- )
308
- }
309
-
310
-
311
- // 所有container位置(對應series)
312
- export const multiGridContainerObservable = ({ computedData$, fullDataFormatter$, layout$ }: {
313
- computedData$: Observable<ComputedDataTypeMap<'multiGrid'>>
314
- fullDataFormatter$: Observable<DataFormatterTypeMap<'multiGrid'>>
315
- layout$: Observable<Layout>
316
- }): Observable<ContainerPositionScaled[][]> => {
317
-
318
- return combineLatest({
319
- computedData: computedData$,
320
- fullDataFormatter: fullDataFormatter$,
321
- layout: layout$,
322
- }).pipe(
323
- switchMap(async (d) => d),
324
- map(data => {
325
-
326
- const defaultGrid = data.fullDataFormatter.gridList[0] ?? DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID
327
- const slotAmount = data.computedData.reduce((acc, gridData, gridIndex) => {
328
- const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
329
- const gridSlotAmount = grid.separateSeries
330
- ? gridData.length
331
- : data.fullDataFormatter.separateGrid
332
- ? 1
333
- : 0 // 如果grid和series都不分開,則slotAmount不增加(在相同的slot)
334
- return acc + gridSlotAmount
335
- }, 0) || 1
336
-
337
- const gridContainerLayout = calcContainerPositionScaled(data.layout, data.fullDataFormatter.container, slotAmount)
338
-
339
- let accGridSlotIndex = 0
340
- const gridContainerPositionArr = data.computedData.map((gridData, gridIndex) => {
341
- const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
342
- const seriesContainerArr = gridData.map((seriesData, seriesIndex) => {
343
- const container = gridContainerLayout[accGridSlotIndex]
344
- if (grid.separateSeries) {
345
- accGridSlotIndex += 1
346
- }
347
- return container
348
- })
349
- if (!grid.separateSeries && data.fullDataFormatter.separateGrid) {
350
- accGridSlotIndex += 1
351
- }
352
- return seriesContainerArr
353
- })
354
- // console.log('gridContainerPositionArr', gridContainerPositionArr)
355
-
356
- // let accGridSlotIndex = 0
357
-
358
- // const gridContainerPositionArr = data.computedData.map((gridData, gridIndex) => {
359
- // const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
360
-
361
- // if (grid.separateSeries) {
362
- // // -- 依seriesSlotIndexes計算 --
363
- // const seriesContainerArr = gridData.map((seriesData, seriesIndex) => {
364
- // const currentSlotIndex = accGridSlotIndex + seriesIndex
365
- // const columnIndex = currentSlotIndex % data.fullDataFormatter.container.columnAmount
366
- // const rowIndex = Math.floor(currentSlotIndex / data.fullDataFormatter.container.columnAmount)
367
- // const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
368
- // return {
369
- // slotIndex: currentSlotIndex,
370
- // rowIndex,
371
- // columnIndex,
372
- // translate,
373
- // scale,
374
- // }
375
- // })
376
- // accGridSlotIndex += seriesContainerArr.length
377
- // return seriesContainerArr
378
- // } else {
379
- // // -- 依grid的slotIndex計算 --
380
- // const columnIndex = accGridSlotIndex % data.fullDataFormatter.container.columnAmount
381
- // const rowIndex = Math.floor(accGridSlotIndex / data.fullDataFormatter.container.columnAmount)
382
- // const seriesContainerArr = gridData.map((seriesData, seriesIndex) => {
383
- // const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
384
- // return {
385
- // slotIndex: accGridSlotIndex,
386
- // rowIndex,
387
- // columnIndex,
388
- // translate,
389
- // scale,
390
- // }
391
- // })
392
- // if (data.fullDataFormatter.separateGrid) {
393
- // accGridSlotIndex += 1
394
- // }
395
- // return seriesContainerArr
396
- // }
397
- // })
398
-
399
- return gridContainerPositionArr
400
- }),
401
- )
1
+ import {
2
+ combineLatest,
3
+ distinctUntilChanged,
4
+ filter,
5
+ of,
6
+ map,
7
+ merge,
8
+ takeUntil,
9
+ shareReplay,
10
+ switchMap,
11
+ Subject,
12
+ Observable,
13
+ combineLatestAll} from 'rxjs'
14
+ import type {
15
+ AxisPosition,
16
+ ChartType,
17
+ ChartParams,
18
+ ComputedDataTypeMap,
19
+ ComputedDataGrid,
20
+ ContextObserverMultiGridDetail,
21
+ ContainerSize,
22
+ DataTypeMap,
23
+ DataFormatterTypeMap,
24
+ DataFormatterGrid,
25
+ DataFormatterMultiGridContainer,
26
+ EventMultiGrid,
27
+ ContainerPositionScaled,
28
+ HighlightTarget,
29
+ Layout,
30
+ TransformData } from '../../lib/core-types'
31
+ import {
32
+ highlightObservable,
33
+ seriesDataMapObservable,
34
+ groupDataMapObservable } from '../utils/observables'
35
+ import {
36
+ gridComputedAxesDataObservable,
37
+ gridAxesSizeObservable,
38
+ gridAxesContainerSizeObservable,
39
+ gridSeriesLabelsObservable,
40
+ gridVisibleComputedDataObservable,
41
+ gridVisibleComputedAxesDataObservable,
42
+ // isSeriesSeprateObservable,
43
+ gridContainerPositionObservable,
44
+ computedStackedDataObservables,
45
+ groupScaleDomainValueObservable,
46
+ filteredMinMaxValueObservable,
47
+ gridAxesTransformObservable,
48
+ gridAxesReverseTransformObservable,
49
+ gridGraphicTransformObservable,
50
+ gridGraphicReverseScaleObservable,
51
+ } from '../grid/gridObservables'
52
+ import { DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID } from '../defaults'
53
+ import { calcContainerPositionScaled } from '../utils/orbchartsUtils'
54
+
55
+ // 每一個grid計算出來的所有Observable
56
+ export const multiGridEachDetailObservable = ({ fullDataFormatter$, computedData$, layout$, fullChartParams$, event$, containerSize$ }: {
57
+ fullDataFormatter$: Observable<DataFormatterTypeMap<'multiGrid'>>
58
+ computedData$: Observable<ComputedDataTypeMap<'multiGrid'>>
59
+ layout$: Observable<Layout>
60
+ fullChartParams$: Observable<ChartParams>
61
+ event$: Subject<EventMultiGrid>
62
+ containerSize$: Observable<ContainerSize>
63
+ }): Observable<ContextObserverMultiGridDetail[]> => {
64
+
65
+ const destroy$ = new Subject()
66
+
67
+ // // highlight全部grid
68
+ // const allGridHighlight$ = highlightObservable({
69
+ // datumList$: computedData$.pipe(
70
+ // map(d => d.flat().flat()),
71
+ // shareReplay(1)
72
+ // ),
73
+ // fullChartParams$: fullChartParams$,
74
+ // event$: event$
75
+ // }).pipe(
76
+ // shareReplay(1)
77
+ // )
78
+
79
+ const multiGridContainer$ = multiGridContainerObservable({
80
+ computedData$: computedData$,
81
+ fullDataFormatter$: fullDataFormatter$,
82
+ layout$: layout$,
83
+ }).pipe(
84
+ shareReplay(1)
85
+ )
86
+
87
+ return combineLatest({
88
+ fullDataFormatter: fullDataFormatter$,
89
+ computedData: computedData$,
90
+ multiGridContainer: multiGridContainer$
91
+ }).pipe(
92
+ switchMap(async (d) => d),
93
+ // distinctUntilChanged((a, b) => {
94
+ // // 只有當computedData的長度改變時,才重新計算
95
+ // return a.computedData.length === b.computedData.length
96
+ // }),
97
+ map(data => {
98
+ // 每次重新計算時,清除之前的訂閱
99
+ destroy$.next(undefined)
100
+
101
+ const defaultGrid = data.fullDataFormatter.gridList[0] ?? DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID
102
+
103
+ return data.computedData.map((gridComputedData, gridIndex) => {
104
+
105
+ // -- 取得該grid的data和dataFormatter
106
+ const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
107
+ const gridDataFormatter: DataFormatterGrid = {
108
+ type: 'grid',
109
+ visibleFilter: data.fullDataFormatter.visibleFilter as any,
110
+ // grid: {
111
+ ...grid,
112
+ // },
113
+ container: {
114
+ ...data.fullDataFormatter.container
115
+ }
116
+ }
117
+ const gridDataFormatter$ = of(gridDataFormatter).pipe(
118
+ takeUntil(destroy$),
119
+ shareReplay(1)
120
+ )
121
+ const gridComputedData$ = of(gridComputedData).pipe(
122
+ takeUntil(destroy$),
123
+ shareReplay(1)
124
+ )
125
+
126
+ // const isSeriesSeprate$ = isSeriesSeprateObservable({
127
+ // computedData$: gridComputedData$,
128
+ // fullDataFormatter$: gridDataFormatter$,
129
+ // }).pipe(
130
+ // takeUntil(destroy$),
131
+ // shareReplay(1)
132
+ // )
133
+
134
+ // const gridContainerPosition$ = gridContainerPositionObservable({
135
+ // computedData$: gridComputedData$,
136
+ // fullDataFormatter$: gridDataFormatter$,
137
+ // layout$
138
+ // }).pipe(
139
+ // shareReplay(1)
140
+ // )
141
+
142
+ const isSeriesSeprate$ = gridDataFormatter$.pipe(
143
+ map(d => d.separateSeries),
144
+ distinctUntilChanged(),
145
+ shareReplay(1)
146
+ )
147
+
148
+ const gridContainerPosition$ = of(data.multiGridContainer[gridIndex]).pipe(
149
+ takeUntil(destroy$),
150
+ shareReplay(1)
151
+ )
152
+
153
+ const gridAxesSize$ = gridAxesSizeObservable({
154
+ fullDataFormatter$: gridDataFormatter$,
155
+ layout$: layout$
156
+ }).pipe(
157
+ takeUntil(destroy$),
158
+ shareReplay(1)
159
+ )
160
+
161
+ const gridAxesContainerSize$ = gridAxesContainerSizeObservable({
162
+ fullDataFormatter$: gridDataFormatter$,
163
+ containerSize$: containerSize$
164
+ }).pipe(
165
+ shareReplay(1)
166
+ )
167
+
168
+ const datumList$ = gridComputedData$.pipe(
169
+ map(d => d.flat())
170
+ ).pipe(
171
+ takeUntil(destroy$),
172
+ shareReplay(1)
173
+ )
174
+
175
+ // const gridHighlight$ = highlightObservable({
176
+ // datumList$,
177
+ // fullChartParams$: fullChartParams$,
178
+ // event$: event$
179
+ // }).pipe(
180
+ // shareReplay(1)
181
+ // )
182
+
183
+ const seriesLabels$ = gridSeriesLabelsObservable({
184
+ computedData$: gridComputedData$,
185
+ }).pipe(
186
+ takeUntil(destroy$),
187
+ shareReplay(1)
188
+ )
189
+
190
+ const SeriesDataMap$ = seriesDataMapObservable({
191
+ datumList$: datumList$
192
+ }).pipe(
193
+ takeUntil(destroy$),
194
+ shareReplay(1)
195
+ )
196
+
197
+ const GroupDataMap$ = groupDataMapObservable({
198
+ datumList$: datumList$
199
+ }).pipe(
200
+ takeUntil(destroy$),
201
+ shareReplay(1)
202
+ )
203
+
204
+ const visibleComputedData$ = gridVisibleComputedDataObservable({
205
+ computedData$: gridComputedData$,
206
+ }).pipe(
207
+ takeUntil(destroy$),
208
+ shareReplay(1)
209
+ )
210
+
211
+ const computedAxesData$ = gridComputedAxesDataObservable({
212
+ computedData$: gridComputedData$,
213
+ fullDataFormatter$: gridDataFormatter$,
214
+ layout$: layout$,
215
+ }).pipe(
216
+ takeUntil(destroy$),
217
+ shareReplay(1)
218
+ )
219
+
220
+ const visibleComputedAxesData$ = gridVisibleComputedAxesDataObservable({
221
+ computedAxesData$: computedAxesData$,
222
+ }).pipe(
223
+ takeUntil(destroy$),
224
+ shareReplay(1)
225
+ )
226
+
227
+ const computedStackedData$ = computedStackedDataObservables({
228
+ computedData$: gridComputedData$,
229
+ isSeriesSeprate$: isSeriesSeprate$
230
+ }).pipe(
231
+ shareReplay(1)
232
+ )
233
+
234
+ const groupScaleDomainValue$ = groupScaleDomainValueObservable({
235
+ computedData$: gridComputedData$,
236
+ fullDataFormatter$: gridDataFormatter$,
237
+ }).pipe(
238
+ takeUntil(destroy$),
239
+ shareReplay(1)
240
+ )
241
+
242
+ const filteredMinMaxValue$ = filteredMinMaxValueObservable({
243
+ computedData$: gridComputedData$,
244
+ groupScaleDomainValue$: groupScaleDomainValue$,
245
+ }).pipe(
246
+ takeUntil(destroy$),
247
+ shareReplay(1)
248
+ )
249
+
250
+ const gridAxesTransform$ = gridAxesTransformObservable({
251
+ fullDataFormatter$: gridDataFormatter$,
252
+ layout$: layout$
253
+ }).pipe(
254
+ takeUntil(destroy$),
255
+ shareReplay(1)
256
+ )
257
+
258
+
259
+ const gridAxesReverseTransform$ = gridAxesReverseTransformObservable({
260
+ gridAxesTransform$
261
+ }).pipe(
262
+ takeUntil(destroy$),
263
+ shareReplay(1)
264
+ )
265
+
266
+ const gridGraphicTransform$ = gridGraphicTransformObservable({
267
+ computedData$: gridComputedData$,
268
+ groupScaleDomainValue$: groupScaleDomainValue$,
269
+ filteredMinMaxValue$: filteredMinMaxValue$,
270
+ fullDataFormatter$: gridDataFormatter$,
271
+ layout$: layout$
272
+ }).pipe(
273
+ takeUntil(destroy$),
274
+ shareReplay(1)
275
+ )
276
+
277
+ const gridGraphicReverseScale$ = gridGraphicReverseScaleObservable({
278
+ gridContainerPosition$: gridContainerPosition$,
279
+ gridAxesTransform$: gridAxesTransform$,
280
+ gridGraphicTransform$: gridGraphicTransform$,
281
+ })
282
+
283
+ return {
284
+ isSeriesSeprate$,
285
+ gridContainerPosition$,
286
+ gridAxesSize$,
287
+ gridAxesContainerSize$,
288
+ // gridHighlight$: allGridHighlight$,
289
+ seriesLabels$,
290
+ SeriesDataMap$,
291
+ GroupDataMap$,
292
+ dataFormatter$: gridDataFormatter$,
293
+ computedData$: gridComputedData$,
294
+ computedAxesData$,
295
+ visibleComputedData$,
296
+ visibleComputedAxesData$,
297
+ computedStackedData$,
298
+ groupScaleDomainValue$,
299
+ filteredMinMaxValue$,
300
+ gridAxesTransform$,
301
+ gridAxesReverseTransform$,
302
+ gridGraphicTransform$,
303
+ gridGraphicReverseScale$,
304
+ }
305
+ })
306
+ })
307
+ )
308
+ }
309
+
310
+
311
+ // 所有container位置(對應series)
312
+ export const multiGridContainerObservable = ({ computedData$, fullDataFormatter$, layout$ }: {
313
+ computedData$: Observable<ComputedDataTypeMap<'multiGrid'>>
314
+ fullDataFormatter$: Observable<DataFormatterTypeMap<'multiGrid'>>
315
+ layout$: Observable<Layout>
316
+ }): Observable<ContainerPositionScaled[][]> => {
317
+
318
+ return combineLatest({
319
+ computedData: computedData$,
320
+ fullDataFormatter: fullDataFormatter$,
321
+ layout: layout$,
322
+ }).pipe(
323
+ switchMap(async (d) => d),
324
+ map(data => {
325
+
326
+ const defaultGrid = data.fullDataFormatter.gridList[0] ?? DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID
327
+ const slotAmount = data.computedData.reduce((acc, gridData, gridIndex) => {
328
+ const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
329
+ const gridSlotAmount = grid.separateSeries
330
+ ? gridData.length
331
+ : data.fullDataFormatter.separateGrid
332
+ ? 1
333
+ : 0 // 如果grid和series都不分開,則slotAmount不增加(在相同的slot)
334
+ return acc + gridSlotAmount
335
+ }, 0) || 1
336
+
337
+ const gridContainerLayout = calcContainerPositionScaled(data.layout, data.fullDataFormatter.container, slotAmount)
338
+
339
+ let accGridSlotIndex = 0
340
+ const gridContainerPositionArr = data.computedData.map((gridData, gridIndex) => {
341
+ const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
342
+ const seriesContainerArr = gridData.map((seriesData, seriesIndex) => {
343
+ const container = gridContainerLayout[accGridSlotIndex]
344
+ if (grid.separateSeries) {
345
+ accGridSlotIndex += 1
346
+ }
347
+ return container
348
+ })
349
+ if (!grid.separateSeries && data.fullDataFormatter.separateGrid) {
350
+ accGridSlotIndex += 1
351
+ }
352
+ return seriesContainerArr
353
+ })
354
+
355
+ return gridContainerPositionArr
356
+ }),
357
+ )
402
358
  }