@orbcharts/core 3.0.0-beta.8 → 3.0.0

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 (76) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +2734 -2353
  3. package/dist/orbcharts-core.umd.js +4 -4
  4. package/dist/src/defaults.d.ts +2 -1
  5. package/dist/src/utils/gridObservables.d.ts +8 -4
  6. package/dist/src/utils/index.d.ts +0 -3
  7. package/dist/src/utils/multiGridObservables.d.ts +3 -2
  8. package/dist/src/utils/multiValueObservables.d.ts +76 -29
  9. package/dist/src/utils/observables.d.ts +8 -1
  10. package/dist/src/utils/orbchartsUtils.d.ts +9 -9
  11. package/dist/src/utils/seriesObservables.d.ts +1 -1
  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 +506 -505
  22. package/src/base/createBasePlugin.ts +154 -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 +282 -238
  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 +198 -176
  37. package/src/grid/dataFormatterValidator.ts +120 -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 +72 -41
  42. package/src/multiGrid/dataFormatterValidator.ts +115 -115
  43. package/src/multiGrid/dataValidator.ts +12 -12
  44. package/src/multiValue/computedDataFn.ts +113 -110
  45. package/src/multiValue/contextObserverCallback.ts +276 -160
  46. package/src/multiValue/dataFormatterValidator.ts +89 -9
  47. package/src/multiValue/dataValidator.ts +12 -9
  48. package/src/relationship/computedDataFn.ts +159 -144
  49. package/src/relationship/contextObserverCallback.ts +80 -80
  50. package/src/relationship/dataFormatterValidator.ts +13 -9
  51. package/src/relationship/dataValidator.ts +13 -9
  52. package/src/series/computedDataFn.ts +88 -88
  53. package/src/series/contextObserverCallback.ts +107 -100
  54. package/src/series/dataFormatterValidator.ts +41 -41
  55. package/src/series/dataValidator.ts +12 -12
  56. package/src/tree/computedDataFn.ts +129 -129
  57. package/src/tree/contextObserverCallback.ts +58 -58
  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 -198
  62. package/src/utils/errorMessage.ts +42 -42
  63. package/src/utils/gridObservables.ts +705 -683
  64. package/src/utils/index.ts +10 -10
  65. package/src/utils/multiGridObservables.ts +401 -392
  66. package/src/utils/multiValueObservables.ts +1044 -662
  67. package/src/utils/observables.ts +281 -219
  68. package/src/utils/orbchartsUtils.ts +377 -377
  69. package/src/utils/relationshipObservables.ts +84 -84
  70. package/src/utils/seriesObservables.ts +175 -175
  71. package/src/utils/treeObservables.ts +105 -105
  72. package/src/utils/validator.ts +126 -126
  73. package/tsconfig.base.json +13 -13
  74. package/tsconfig.json +2 -2
  75. package/vite-env.d.ts +6 -6
  76. package/vite.config.js +22 -22
@@ -1,393 +1,402 @@
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
+ 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 './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 './gridObservables'
52
+ import { DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID } from '../defaults'
53
+ import { calcContainerPositionScaled } from './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
+ )
393
402
  }