@orbcharts/core 3.0.0-alpha.48 → 3.0.0-alpha.50

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