@orbcharts/core 3.0.6 → 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.
Files changed (68) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +779 -779
  3. package/dist/orbcharts-core.umd.js +1 -1
  4. package/lib/core-types.ts +7 -7
  5. package/package.json +46 -46
  6. package/src/AbstractChart.ts +57 -57
  7. package/src/GridChart.ts +24 -24
  8. package/src/MultiGridChart.ts +24 -24
  9. package/src/MultiValueChart.ts +24 -24
  10. package/src/RelationshipChart.ts +24 -24
  11. package/src/SeriesChart.ts +24 -24
  12. package/src/TreeChart.ts +24 -24
  13. package/src/base/createBaseChart.ts +524 -524
  14. package/src/base/createBasePlugin.ts +154 -154
  15. package/src/base/validators/chartOptionsValidator.ts +23 -23
  16. package/src/base/validators/chartParamsValidator.ts +133 -133
  17. package/src/base/validators/elementValidator.ts +13 -13
  18. package/src/base/validators/pluginsValidator.ts +14 -14
  19. package/src/defaults.ts +284 -284
  20. package/src/defineGridPlugin.ts +3 -3
  21. package/src/defineMultiGridPlugin.ts +3 -3
  22. package/src/defineMultiValuePlugin.ts +3 -3
  23. package/src/defineNoneDataPlugin.ts +4 -4
  24. package/src/defineRelationshipPlugin.ts +3 -3
  25. package/src/defineSeriesPlugin.ts +3 -3
  26. package/src/defineTreePlugin.ts +3 -3
  27. package/src/grid/computedDataFn.ts +129 -129
  28. package/src/grid/contextObserverCallback.ts +209 -209
  29. package/src/grid/dataFormatterValidator.ts +125 -125
  30. package/src/grid/dataValidator.ts +12 -12
  31. package/src/grid/gridObservables.ts +698 -698
  32. package/src/index.ts +20 -20
  33. package/src/multiGrid/computedDataFn.ts +123 -123
  34. package/src/multiGrid/contextObserverCallback.ts +109 -109
  35. package/src/multiGrid/dataFormatterValidator.ts +120 -120
  36. package/src/multiGrid/dataValidator.ts +12 -12
  37. package/src/multiGrid/multiGridObservables.ts +366 -366
  38. package/src/multiValue/computedDataFn.ts +113 -113
  39. package/src/multiValue/contextObserverCallback.ts +328 -328
  40. package/src/multiValue/dataFormatterValidator.ts +94 -94
  41. package/src/multiValue/dataValidator.ts +12 -12
  42. package/src/multiValue/multiValueObservables.ts +865 -865
  43. package/src/relationship/computedDataFn.ts +159 -159
  44. package/src/relationship/contextObserverCallback.ts +80 -80
  45. package/src/relationship/dataFormatterValidator.ts +13 -13
  46. package/src/relationship/dataValidator.ts +13 -13
  47. package/src/relationship/relationshipObservables.ts +84 -84
  48. package/src/series/computedDataFn.ts +88 -88
  49. package/src/series/contextObserverCallback.ts +132 -132
  50. package/src/series/dataFormatterValidator.ts +46 -46
  51. package/src/series/dataValidator.ts +12 -12
  52. package/src/series/seriesObservables.ts +209 -209
  53. package/src/tree/computedDataFn.ts +129 -129
  54. package/src/tree/contextObserverCallback.ts +58 -58
  55. package/src/tree/dataFormatterValidator.ts +13 -13
  56. package/src/tree/dataValidator.ts +13 -13
  57. package/src/tree/treeObservables.ts +105 -105
  58. package/src/utils/commonUtils.ts +55 -55
  59. package/src/utils/d3Scale.ts +198 -198
  60. package/src/utils/errorMessage.ts +40 -40
  61. package/src/utils/index.ts +3 -3
  62. package/src/utils/observables.ts +307 -308
  63. package/src/utils/orbchartsUtils.ts +396 -396
  64. package/src/utils/validator.ts +126 -126
  65. package/tsconfig.base.json +13 -13
  66. package/tsconfig.json +2 -2
  67. package/vite-env.d.ts +6 -6
  68. package/vite.config.js +22 -22
@@ -1,367 +1,367 @@
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 filteredStackedMinMaxValue$ = filteredMinMaxValueObservable({
251
- computedData$: computedStackedData$,
252
- groupScaleDomainValue$: groupScaleDomainValue$,
253
- }).pipe(
254
- takeUntil(destroy$),
255
- shareReplay(1)
256
- )
257
-
258
- const gridAxesTransform$ = gridAxesTransformObservable({
259
- fullDataFormatter$: gridDataFormatter$,
260
- layout$: layout$
261
- }).pipe(
262
- takeUntil(destroy$),
263
- shareReplay(1)
264
- )
265
-
266
-
267
- const gridAxesReverseTransform$ = gridAxesReverseTransformObservable({
268
- gridAxesTransform$
269
- }).pipe(
270
- takeUntil(destroy$),
271
- shareReplay(1)
272
- )
273
-
274
- const gridGraphicTransform$ = gridGraphicTransformObservable({
275
- computedData$: gridComputedData$,
276
- groupScaleDomainValue$: groupScaleDomainValue$,
277
- filteredMinMaxValue$: filteredMinMaxValue$,
278
- fullDataFormatter$: gridDataFormatter$,
279
- layout$: layout$
280
- }).pipe(
281
- takeUntil(destroy$),
282
- shareReplay(1)
283
- )
284
-
285
- const gridGraphicReverseScale$ = gridGraphicReverseScaleObservable({
286
- gridContainerPosition$: gridContainerPosition$,
287
- gridAxesTransform$: gridAxesTransform$,
288
- gridGraphicTransform$: gridGraphicTransform$,
289
- })
290
-
291
- return {
292
- isSeriesSeprate$,
293
- gridContainerPosition$,
294
- gridAxesSize$,
295
- gridAxesContainerSize$,
296
- // gridHighlight$: allGridHighlight$,
297
- seriesLabels$,
298
- SeriesDataMap$,
299
- GroupDataMap$,
300
- dataFormatter$: gridDataFormatter$,
301
- computedData$: gridComputedData$,
302
- computedAxesData$,
303
- visibleComputedData$,
304
- visibleComputedAxesData$,
305
- computedStackedData$,
306
- groupScaleDomainValue$,
307
- filteredMinMaxValue$,
308
- filteredStackedMinMaxValue$,
309
- gridAxesTransform$,
310
- gridAxesReverseTransform$,
311
- gridGraphicTransform$,
312
- gridGraphicReverseScale$,
313
- }
314
- })
315
- })
316
- )
317
- }
318
-
319
-
320
- // 所有container位置(對應series)
321
- export const multiGridContainerObservable = ({ computedData$, fullDataFormatter$, layout$ }: {
322
- computedData$: Observable<ComputedDataTypeMap<'multiGrid'>>
323
- fullDataFormatter$: Observable<DataFormatterTypeMap<'multiGrid'>>
324
- layout$: Observable<Layout>
325
- }): Observable<ContainerPositionScaled[][]> => {
326
-
327
- return combineLatest({
328
- computedData: computedData$,
329
- fullDataFormatter: fullDataFormatter$,
330
- layout: layout$,
331
- }).pipe(
332
- switchMap(async (d) => d),
333
- map(data => {
334
-
335
- const defaultGrid = data.fullDataFormatter.gridList[0] ?? DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID
336
- const slotAmount = data.computedData.reduce((acc, gridData, gridIndex) => {
337
- const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
338
- const gridSlotAmount = grid.separateSeries
339
- ? gridData.length
340
- : data.fullDataFormatter.separateGrid
341
- ? 1
342
- : 0 // 如果grid和series都不分開,則slotAmount不增加(在相同的slot)
343
- return acc + gridSlotAmount
344
- }, 0) || 1
345
-
346
- const gridContainerLayout = calcContainerPositionScaled(data.layout, data.fullDataFormatter.container, slotAmount)
347
-
348
- let accGridSlotIndex = 0
349
- const gridContainerPositionArr = data.computedData.map((gridData, gridIndex) => {
350
- const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
351
- const seriesContainerArr = gridData.map((seriesData, seriesIndex) => {
352
- const container = gridContainerLayout[accGridSlotIndex]
353
- if (grid.separateSeries) {
354
- accGridSlotIndex += 1
355
- }
356
- return container
357
- })
358
- if (!grid.separateSeries && data.fullDataFormatter.separateGrid) {
359
- accGridSlotIndex += 1
360
- }
361
- return seriesContainerArr
362
- })
363
-
364
- return gridContainerPositionArr
365
- }),
366
- )
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 filteredStackedMinMaxValue$ = filteredMinMaxValueObservable({
251
+ computedData$: computedStackedData$,
252
+ groupScaleDomainValue$: groupScaleDomainValue$,
253
+ }).pipe(
254
+ takeUntil(destroy$),
255
+ shareReplay(1)
256
+ )
257
+
258
+ const gridAxesTransform$ = gridAxesTransformObservable({
259
+ fullDataFormatter$: gridDataFormatter$,
260
+ layout$: layout$
261
+ }).pipe(
262
+ takeUntil(destroy$),
263
+ shareReplay(1)
264
+ )
265
+
266
+
267
+ const gridAxesReverseTransform$ = gridAxesReverseTransformObservable({
268
+ gridAxesTransform$
269
+ }).pipe(
270
+ takeUntil(destroy$),
271
+ shareReplay(1)
272
+ )
273
+
274
+ const gridGraphicTransform$ = gridGraphicTransformObservable({
275
+ computedData$: gridComputedData$,
276
+ groupScaleDomainValue$: groupScaleDomainValue$,
277
+ filteredMinMaxValue$: filteredMinMaxValue$,
278
+ fullDataFormatter$: gridDataFormatter$,
279
+ layout$: layout$
280
+ }).pipe(
281
+ takeUntil(destroy$),
282
+ shareReplay(1)
283
+ )
284
+
285
+ const gridGraphicReverseScale$ = gridGraphicReverseScaleObservable({
286
+ gridContainerPosition$: gridContainerPosition$,
287
+ gridAxesTransform$: gridAxesTransform$,
288
+ gridGraphicTransform$: gridGraphicTransform$,
289
+ })
290
+
291
+ return {
292
+ isSeriesSeprate$,
293
+ gridContainerPosition$,
294
+ gridAxesSize$,
295
+ gridAxesContainerSize$,
296
+ // gridHighlight$: allGridHighlight$,
297
+ seriesLabels$,
298
+ SeriesDataMap$,
299
+ GroupDataMap$,
300
+ dataFormatter$: gridDataFormatter$,
301
+ computedData$: gridComputedData$,
302
+ computedAxesData$,
303
+ visibleComputedData$,
304
+ visibleComputedAxesData$,
305
+ computedStackedData$,
306
+ groupScaleDomainValue$,
307
+ filteredMinMaxValue$,
308
+ filteredStackedMinMaxValue$,
309
+ gridAxesTransform$,
310
+ gridAxesReverseTransform$,
311
+ gridGraphicTransform$,
312
+ gridGraphicReverseScale$,
313
+ }
314
+ })
315
+ })
316
+ )
317
+ }
318
+
319
+
320
+ // 所有container位置(對應series)
321
+ export const multiGridContainerObservable = ({ computedData$, fullDataFormatter$, layout$ }: {
322
+ computedData$: Observable<ComputedDataTypeMap<'multiGrid'>>
323
+ fullDataFormatter$: Observable<DataFormatterTypeMap<'multiGrid'>>
324
+ layout$: Observable<Layout>
325
+ }): Observable<ContainerPositionScaled[][]> => {
326
+
327
+ return combineLatest({
328
+ computedData: computedData$,
329
+ fullDataFormatter: fullDataFormatter$,
330
+ layout: layout$,
331
+ }).pipe(
332
+ switchMap(async (d) => d),
333
+ map(data => {
334
+
335
+ const defaultGrid = data.fullDataFormatter.gridList[0] ?? DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID
336
+ const slotAmount = data.computedData.reduce((acc, gridData, gridIndex) => {
337
+ const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
338
+ const gridSlotAmount = grid.separateSeries
339
+ ? gridData.length
340
+ : data.fullDataFormatter.separateGrid
341
+ ? 1
342
+ : 0 // 如果grid和series都不分開,則slotAmount不增加(在相同的slot)
343
+ return acc + gridSlotAmount
344
+ }, 0) || 1
345
+
346
+ const gridContainerLayout = calcContainerPositionScaled(data.layout, data.fullDataFormatter.container, slotAmount)
347
+
348
+ let accGridSlotIndex = 0
349
+ const gridContainerPositionArr = data.computedData.map((gridData, gridIndex) => {
350
+ const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
351
+ const seriesContainerArr = gridData.map((seriesData, seriesIndex) => {
352
+ const container = gridContainerLayout[accGridSlotIndex]
353
+ if (grid.separateSeries) {
354
+ accGridSlotIndex += 1
355
+ }
356
+ return container
357
+ })
358
+ if (!grid.separateSeries && data.fullDataFormatter.separateGrid) {
359
+ accGridSlotIndex += 1
360
+ }
361
+ return seriesContainerArr
362
+ })
363
+
364
+ return gridContainerPositionArr
365
+ }),
366
+ )
367
367
  }