@orbcharts/core 3.0.0-alpha.43 → 3.0.0-alpha.45

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