@orbcharts/core 3.0.0-beta.3 → 3.0.0-beta.4

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