@orbcharts/core 3.0.0-alpha.56 → 3.0.0-alpha.57

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 +220 -216
  3. package/dist/orbcharts-core.umd.js +2 -2
  4. package/package.json +41 -41
  5. package/src/AbstractChart.ts +48 -48
  6. package/src/GridChart.ts +20 -20
  7. package/src/MultiGridChart.ts +20 -20
  8. package/src/MultiValueChart.ts +20 -20
  9. package/src/RelationshipChart.ts +20 -20
  10. package/src/SeriesChart.ts +20 -20
  11. package/src/TreeChart.ts +20 -20
  12. package/src/base/createBaseChart.ts +369 -369
  13. package/src/base/createBasePlugin.ts +95 -95
  14. package/src/defaults.ts +226 -226
  15. package/src/defineGridPlugin.ts +3 -3
  16. package/src/defineMultiGridPlugin.ts +3 -3
  17. package/src/defineMultiValuePlugin.ts +3 -3
  18. package/src/defineNoneDataPlugin.ts +4 -4
  19. package/src/defineRelationshipPlugin.ts +3 -3
  20. package/src/defineSeriesPlugin.ts +3 -3
  21. package/src/defineTreePlugin.ts +3 -3
  22. package/src/grid/computeGridData.ts +134 -134
  23. package/src/grid/createGridContextObserver.ts +155 -155
  24. package/src/grid/gridObservables.ts +613 -607
  25. package/src/index.ts +21 -21
  26. package/src/multiGrid/computeMultiGridData.ts +130 -130
  27. package/src/multiGrid/createMultiGridContextObserver.ts +41 -41
  28. package/src/multiGrid/multiGridObservables.ts +365 -365
  29. package/src/multiValue/computeMultiValueData.ts +143 -143
  30. package/src/multiValue/createMultiValueContextObserver.ts +12 -12
  31. package/src/relationship/computeRelationshipData.ts +118 -118
  32. package/src/relationship/createRelationshipContextObserver.ts +12 -12
  33. package/src/series/computeSeriesData.ts +90 -90
  34. package/src/series/createSeriesContextObserver.ts +93 -93
  35. package/src/series/seriesObservables.ts +175 -175
  36. package/src/tree/computeTreeData.ts +132 -132
  37. package/src/tree/createTreeContextObserver.ts +61 -61
  38. package/src/tree/treeObservables.ts +94 -94
  39. package/src/types/Chart.ts +50 -50
  40. package/src/types/ChartParams.ts +51 -51
  41. package/src/types/ComputedData.ts +83 -83
  42. package/src/types/ComputedDataGrid.ts +13 -13
  43. package/src/types/ComputedDataMultiGrid.ts +2 -2
  44. package/src/types/ComputedDataMultiValue.ts +9 -9
  45. package/src/types/ComputedDataRelationship.ts +19 -19
  46. package/src/types/ComputedDataSeries.ts +7 -7
  47. package/src/types/ComputedDataTree.ts +19 -19
  48. package/src/types/ContextObserver.ts +38 -38
  49. package/src/types/ContextObserverGrid.ts +42 -42
  50. package/src/types/ContextObserverMultiGrid.ts +16 -16
  51. package/src/types/ContextObserverMultiValue.ts +4 -4
  52. package/src/types/ContextObserverRelationship.ts +4 -4
  53. package/src/types/ContextObserverSeries.ts +29 -29
  54. package/src/types/ContextObserverTree.ts +11 -11
  55. package/src/types/ContextSubject.ts +18 -18
  56. package/src/types/Data.ts +45 -45
  57. package/src/types/DataFormatter.ts +74 -74
  58. package/src/types/DataFormatterGrid.ts +67 -67
  59. package/src/types/DataFormatterMultiGrid.ts +44 -44
  60. package/src/types/DataFormatterMultiValue.ts +23 -23
  61. package/src/types/DataFormatterRelationship.ts +25 -25
  62. package/src/types/DataFormatterSeries.ts +20 -20
  63. package/src/types/DataFormatterTree.ts +12 -12
  64. package/src/types/DataGrid.ts +11 -11
  65. package/src/types/DataMultiGrid.ts +6 -6
  66. package/src/types/DataMultiValue.ts +12 -12
  67. package/src/types/DataRelationship.ts +27 -27
  68. package/src/types/DataSeries.ts +11 -11
  69. package/src/types/DataTree.ts +20 -20
  70. package/src/types/Event.ts +153 -153
  71. package/src/types/Layout.ts +11 -11
  72. package/src/types/Padding.ts +5 -5
  73. package/src/types/Plugin.ts +60 -60
  74. package/src/types/TransformData.ts +7 -7
  75. package/src/types/index.ts +37 -37
  76. package/src/utils/commonUtils.ts +50 -50
  77. package/src/utils/d3Utils.ts +92 -92
  78. package/src/utils/index.ts +4 -4
  79. package/src/utils/observables.ts +201 -201
  80. package/src/utils/orbchartsUtils.ts +349 -349
  81. package/tsconfig.base.json +13 -13
  82. package/tsconfig.json +2 -2
  83. package/vite.config.js +22 -22
@@ -1,366 +1,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
- 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
- // console.log('gridContainerPositionArr', gridContainerPositionArr)
319
-
320
- // let accGridSlotIndex = 0
321
-
322
- // const gridContainerPositionArr = data.computedData.map((gridData, gridIndex) => {
323
- // const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
324
-
325
- // if (grid.separateSeries) {
326
- // // -- 依seriesSlotIndexes計算 --
327
- // const seriesContainerArr = gridData.map((seriesData, seriesIndex) => {
328
- // const currentSlotIndex = accGridSlotIndex + seriesIndex
329
- // const columnIndex = currentSlotIndex % data.fullDataFormatter.container.columnAmount
330
- // const rowIndex = Math.floor(currentSlotIndex / data.fullDataFormatter.container.columnAmount)
331
- // const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
332
- // return {
333
- // slotIndex: currentSlotIndex,
334
- // rowIndex,
335
- // columnIndex,
336
- // translate,
337
- // scale,
338
- // }
339
- // })
340
- // accGridSlotIndex += seriesContainerArr.length
341
- // return seriesContainerArr
342
- // } else {
343
- // // -- 依grid的slotIndex計算 --
344
- // const columnIndex = accGridSlotIndex % data.fullDataFormatter.container.columnAmount
345
- // const rowIndex = Math.floor(accGridSlotIndex / data.fullDataFormatter.container.columnAmount)
346
- // const seriesContainerArr = gridData.map((seriesData, seriesIndex) => {
347
- // const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
348
- // return {
349
- // slotIndex: accGridSlotIndex,
350
- // rowIndex,
351
- // columnIndex,
352
- // translate,
353
- // scale,
354
- // }
355
- // })
356
- // if (data.fullDataFormatter.separateGrid) {
357
- // accGridSlotIndex += 1
358
- // }
359
- // return seriesContainerArr
360
- // }
361
- // })
362
-
363
- return gridContainerPositionArr
364
- }),
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
+ // console.log('gridContainerPositionArr', gridContainerPositionArr)
319
+
320
+ // let accGridSlotIndex = 0
321
+
322
+ // const gridContainerPositionArr = data.computedData.map((gridData, gridIndex) => {
323
+ // const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
324
+
325
+ // if (grid.separateSeries) {
326
+ // // -- 依seriesSlotIndexes計算 --
327
+ // const seriesContainerArr = gridData.map((seriesData, seriesIndex) => {
328
+ // const currentSlotIndex = accGridSlotIndex + seriesIndex
329
+ // const columnIndex = currentSlotIndex % data.fullDataFormatter.container.columnAmount
330
+ // const rowIndex = Math.floor(currentSlotIndex / data.fullDataFormatter.container.columnAmount)
331
+ // const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
332
+ // return {
333
+ // slotIndex: currentSlotIndex,
334
+ // rowIndex,
335
+ // columnIndex,
336
+ // translate,
337
+ // scale,
338
+ // }
339
+ // })
340
+ // accGridSlotIndex += seriesContainerArr.length
341
+ // return seriesContainerArr
342
+ // } else {
343
+ // // -- 依grid的slotIndex計算 --
344
+ // const columnIndex = accGridSlotIndex % data.fullDataFormatter.container.columnAmount
345
+ // const rowIndex = Math.floor(accGridSlotIndex / data.fullDataFormatter.container.columnAmount)
346
+ // const seriesContainerArr = gridData.map((seriesData, seriesIndex) => {
347
+ // const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
348
+ // return {
349
+ // slotIndex: accGridSlotIndex,
350
+ // rowIndex,
351
+ // columnIndex,
352
+ // translate,
353
+ // scale,
354
+ // }
355
+ // })
356
+ // if (data.fullDataFormatter.separateGrid) {
357
+ // accGridSlotIndex += 1
358
+ // }
359
+ // return seriesContainerArr
360
+ // }
361
+ // })
362
+
363
+ return gridContainerPositionArr
364
+ }),
365
+ )
366
366
  }