@orbcharts/core 3.0.0-beta.7 → 3.0.0-beta.8

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