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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +1906 -1897
  3. package/dist/orbcharts-core.umd.js +2 -2
  4. package/dist/src/defaults.d.ts +4 -3
  5. package/dist/src/grid/computeGridData.d.ts +4 -11
  6. package/dist/src/grid/gridObservables.d.ts +15 -18
  7. package/dist/src/multiGrid/multiGridObservables.d.ts +4 -11
  8. package/dist/src/series/seriesObservables.d.ts +26 -1
  9. package/dist/src/types/ComputedData.d.ts +1 -0
  10. package/dist/src/types/ComputedDataGrid.d.ts +0 -3
  11. package/dist/src/types/ComputedDataSeries.d.ts +1 -2
  12. package/dist/src/types/ContextObserverGrid.d.ts +11 -4
  13. package/dist/src/types/ContextObserverMultiGrid.d.ts +8 -3
  14. package/dist/src/types/ContextObserverSeries.d.ts +18 -0
  15. package/dist/src/types/DataFormatter.d.ts +8 -5
  16. package/dist/src/types/DataFormatterGrid.d.ts +13 -16
  17. package/dist/src/types/DataFormatterMultiGrid.d.ts +6 -3
  18. package/dist/src/types/DataFormatterMultiValue.d.ts +3 -0
  19. package/dist/src/types/DataFormatterRelationship.d.ts +3 -0
  20. package/dist/src/types/DataFormatterSeries.d.ts +10 -3
  21. package/dist/src/utils/orbchartsUtils.d.ts +14 -13
  22. package/package.json +41 -41
  23. package/src/AbstractChart.ts +48 -48
  24. package/src/GridChart.ts +20 -20
  25. package/src/MultiGridChart.ts +20 -20
  26. package/src/MultiValueChart.ts +20 -20
  27. package/src/RelationshipChart.ts +20 -20
  28. package/src/SeriesChart.ts +20 -20
  29. package/src/TreeChart.ts +20 -20
  30. package/src/base/createBaseChart.ts +367 -367
  31. package/src/base/createBasePlugin.ts +89 -89
  32. package/src/defaults.ts +220 -248
  33. package/src/defineGridPlugin.ts +3 -3
  34. package/src/defineMultiGridPlugin.ts +3 -3
  35. package/src/defineMultiValuePlugin.ts +3 -3
  36. package/src/defineNoneDataPlugin.ts +4 -4
  37. package/src/defineRelationshipPlugin.ts +3 -3
  38. package/src/defineSeriesPlugin.ts +3 -3
  39. package/src/defineTreePlugin.ts +3 -3
  40. package/src/grid/computeGridData.ts +134 -205
  41. package/src/grid/createGridContextObserver.ts +147 -130
  42. package/src/grid/gridObservables.ts +573 -486
  43. package/src/index.ts +21 -21
  44. package/src/multiGrid/computeMultiGridData.ts +130 -173
  45. package/src/multiGrid/createMultiGridContextObserver.ts +40 -40
  46. package/src/multiGrid/multiGridObservables.ts +350 -285
  47. package/src/multiValue/computeMultiValueData.ts +143 -136
  48. package/src/multiValue/createMultiValueContextObserver.ts +12 -12
  49. package/src/relationship/computeRelationshipData.ts +118 -106
  50. package/src/relationship/createRelationshipContextObserver.ts +12 -12
  51. package/src/series/computeSeriesData.ts +90 -153
  52. package/src/series/createSeriesContextObserver.ts +93 -38
  53. package/src/series/seriesObservables.ts +176 -24
  54. package/src/tree/computeTreeData.ts +131 -128
  55. package/src/tree/createTreeContextObserver.ts +61 -61
  56. package/src/tree/treeObservables.ts +94 -94
  57. package/src/types/Chart.ts +48 -48
  58. package/src/types/ChartParams.ts +51 -51
  59. package/src/types/ComputedData.ts +83 -82
  60. package/src/types/ComputedDataGrid.ts +13 -13
  61. package/src/types/ComputedDataMultiGrid.ts +2 -2
  62. package/src/types/ComputedDataMultiValue.ts +9 -9
  63. package/src/types/ComputedDataRelationship.ts +19 -19
  64. package/src/types/ComputedDataSeries.ts +8 -8
  65. package/src/types/ComputedDataTree.ts +19 -19
  66. package/src/types/ContextObserver.ts +38 -38
  67. package/src/types/ContextObserverGrid.ts +41 -33
  68. package/src/types/ContextObserverMultiGrid.ts +16 -28
  69. package/src/types/ContextObserverMultiValue.ts +4 -4
  70. package/src/types/ContextObserverRelationship.ts +4 -4
  71. package/src/types/ContextObserverSeries.ts +29 -9
  72. package/src/types/ContextObserverTree.ts +11 -11
  73. package/src/types/ContextSubject.ts +18 -18
  74. package/src/types/Data.ts +45 -45
  75. package/src/types/DataFormatter.ts +74 -95
  76. package/src/types/DataFormatterGrid.ts +67 -55
  77. package/src/types/DataFormatterMultiGrid.ts +44 -42
  78. package/src/types/DataFormatterMultiValue.ts +23 -20
  79. package/src/types/DataFormatterRelationship.ts +25 -22
  80. package/src/types/DataFormatterSeries.ts +20 -30
  81. package/src/types/DataFormatterTree.ts +12 -12
  82. package/src/types/DataGrid.ts +11 -11
  83. package/src/types/DataMultiGrid.ts +6 -6
  84. package/src/types/DataMultiValue.ts +12 -12
  85. package/src/types/DataRelationship.ts +27 -27
  86. package/src/types/DataSeries.ts +11 -11
  87. package/src/types/DataTree.ts +20 -20
  88. package/src/types/Event.ts +153 -153
  89. package/src/types/Layout.ts +11 -11
  90. package/src/types/Padding.ts +5 -5
  91. package/src/types/Plugin.ts +60 -60
  92. package/src/types/TransformData.ts +7 -7
  93. package/src/types/index.ts +37 -37
  94. package/src/utils/commonUtils.ts +50 -50
  95. package/src/utils/d3Utils.ts +89 -89
  96. package/src/utils/index.ts +4 -4
  97. package/src/utils/observables.ts +201 -201
  98. package/src/utils/orbchartsUtils.ts +349 -253
  99. package/tsconfig.json +13 -13
  100. package/vite.config.js +44 -44
@@ -1,286 +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 } 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
- existSeriesLabelsObservable,
40
- gridVisibleComputedDataObservable,
41
- isSeriesPositionSeprateObservable,
42
- gridContainerObservable } from '../grid/gridObservables'
43
- import { DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT } from '../defaults'
44
- import { calcGridContainerPosition } from '../utils/orbchartsUtils'
45
-
46
- // 每一個grid計算出來的所有Observable
47
- export const multiGridEachDetailObservable = ({ fullDataFormatter$, computedData$, layout$, fullChartParams$, event$ }: {
48
- fullDataFormatter$: Observable<DataFormatterTypeMap<'multiGrid'>>
49
- computedData$: Observable<ComputedDataTypeMap<'multiGrid'>>
50
- layout$: Observable<Layout>
51
- fullChartParams$: Observable<ChartParams>
52
- event$: Subject<EventMultiGrid>
53
- }) => {
54
-
55
- // 建立Observables
56
- function detailObservables ({ gridDataFormatter$, gridComputedData$, layout$, fullChartParams$, event$ }: {
57
- // fullDataFormatter$: Observable<DataFormatterTypeMap<'multiGrid'>>
58
- // computedData$: Observable<ComputedDataTypeMap<'multiGrid'>>
59
- gridDataFormatter$: Observable<DataFormatterGrid>
60
- gridComputedData$: Observable<ComputedDataGrid>
61
- layout$: Observable<Layout>
62
- fullChartParams$: Observable<ChartParams>
63
- event$: Subject<EventMultiGrid>
64
- }): ContextObserverGridDetail {
65
-
66
- const isSeriesPositionSeprate$ = isSeriesPositionSeprateObservable({
67
- computedData$: gridComputedData$,
68
- fullDataFormatter$: gridDataFormatter$,
69
- }).pipe(
70
- shareReplay(1)
71
- )
72
-
73
- const gridContainer$ = gridContainerObservable({
74
- computedData$: gridComputedData$,
75
- fullDataFormatter$: gridDataFormatter$,
76
- fullChartParams$,
77
- layout$
78
- }).pipe(
79
- shareReplay(1)
80
- )
81
-
82
- const gridAxesTransform$ = gridAxesTransformObservable({
83
- fullDataFormatter$: gridDataFormatter$,
84
- layout$: layout$
85
- }).pipe(
86
- shareReplay(1)
87
- )
88
-
89
-
90
- const gridAxesReverseTransform$ = gridAxesReverseTransformObservable({
91
- gridAxesTransform$
92
- }).pipe(
93
- shareReplay(1)
94
- )
95
-
96
- const gridGraphicTransform$ = gridGraphicTransformObservable({
97
- computedData$: gridComputedData$,
98
- fullDataFormatter$: gridDataFormatter$,
99
- layout$: layout$
100
- }).pipe(
101
- shareReplay(1)
102
- )
103
-
104
- const gridGraphicReverseScale$ = gridGraphicReverseScaleObservable({
105
- gridContainer$: gridContainer$,
106
- gridAxesTransform$: gridAxesTransform$,
107
- gridGraphicTransform$: gridGraphicTransform$,
108
- })
109
-
110
- const gridAxesSize$ = gridAxesSizeObservable({
111
- fullDataFormatter$: gridDataFormatter$,
112
- layout$: layout$
113
- }).pipe(
114
- shareReplay(1)
115
- )
116
-
117
- const datumList$ = gridComputedData$.pipe(
118
- map(d => d.flat())
119
- ).pipe(
120
- shareReplay(1)
121
- )
122
-
123
- const gridHighlight$ = highlightObservable({
124
- datumList$,
125
- fullChartParams$: fullChartParams$,
126
- event$: event$
127
- }).pipe(
128
- shareReplay(1)
129
- )
130
-
131
- const existSeriesLabels$ = existSeriesLabelsObservable({
132
- computedData$: gridComputedData$,
133
- })
134
-
135
- const SeriesDataMap$ = seriesDataMapObservable({
136
- datumList$: datumList$
137
- }).pipe(
138
- shareReplay(1)
139
- )
140
-
141
- const GroupDataMap$ = groupDataMapObservable({
142
- datumList$: datumList$
143
- }).pipe(
144
- shareReplay(1)
145
- )
146
-
147
- const visibleComputedData$ = gridVisibleComputedDataObservable({
148
- computedData$: gridComputedData$,
149
- }).pipe(
150
- shareReplay(1)
151
- )
152
-
153
-
154
- return {
155
- isSeriesPositionSeprate$,
156
- gridContainer$,
157
- gridAxesTransform$,
158
- gridAxesReverseTransform$,
159
- gridGraphicTransform$,
160
- gridGraphicReverseScale$,
161
- gridAxesSize$,
162
- gridHighlight$,
163
- existSeriesLabels$,
164
- SeriesDataMap$,
165
- GroupDataMap$,
166
- visibleComputedData$,
167
- }
168
- }
169
-
170
- const destroy$ = new Subject()
171
-
172
- return combineLatest({
173
- fullDataFormatter: fullDataFormatter$,
174
- computedData: computedData$,
175
- }).pipe(
176
- switchMap(async (d) => d),
177
- // distinctUntilChanged((a, b) => {
178
- // // 只有當computedData的長度改變時,才重新計算
179
- // return a.computedData.length === b.computedData.length
180
- // }),
181
- map(data => {
182
- // 每次重新計算時,清除之前的訂閱
183
- destroy$.next(undefined)
184
-
185
- const defaultGrid = data.fullDataFormatter.gridList[0] ?? DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT
186
-
187
- return data.computedData.map((gridComputedData, gridIndex) => {
188
-
189
- // -- 取得該grid的data和dataFormatter
190
- const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
191
- const gridDataFormatter: DataFormatterGrid = {
192
- type: 'grid',
193
- grid: {
194
- ...grid
195
- },
196
- container: {
197
- ...data.fullDataFormatter.container
198
- }
199
- }
200
- const gridDataFormatter$ = of(gridDataFormatter).pipe(
201
- takeUntil(destroy$),
202
- shareReplay(1)
203
- )
204
- const gridComputedData$ = of(gridComputedData).pipe(
205
- takeUntil(destroy$),
206
- shareReplay(1)
207
- )
208
-
209
- // -- 建立Observables --
210
- return detailObservables ({
211
- gridDataFormatter$,
212
- gridComputedData$,
213
- layout$,
214
- fullChartParams$,
215
- event$
216
- })
217
- })
218
- })
219
- )
220
- }
221
-
222
-
223
- // 所有container位置(對應series)
224
- export const multiGridContainerObservable = ({ computedData$, fullDataFormatter$, fullChartParams$, layout$ }: {
225
- computedData$: Observable<ComputedDataTypeMap<'multiGrid'>>
226
- fullDataFormatter$: Observable<DataFormatterTypeMap<'multiGrid'>>
227
- fullChartParams$: Observable<ChartParams>
228
- layout$: Observable<Layout>
229
- }) => {
230
-
231
- const multiGridContainer$ = combineLatest({
232
- computedData: computedData$,
233
- fullDataFormatter: fullDataFormatter$,
234
- fullChartParams: fullChartParams$,
235
- layout: layout$,
236
- }).pipe(
237
- switchMap(async (d) => d),
238
- map(data => {
239
-
240
- const defaultGrid = data.fullDataFormatter.gridList[0] ?? DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT
241
-
242
- const boxArr = data.computedData.map((gridData, gridIndex) => {
243
- const grid = data.fullDataFormatter.gridList[gridIndex] ?? defaultGrid
244
-
245
- // 有設定series定位
246
- const hasSeriesPosition = grid.seriesSlotIndexes && grid.seriesSlotIndexes.length === gridData.length
247
- ? true
248
- : false
249
-
250
- if (hasSeriesPosition) {
251
- // -- 依seriesSlotIndexes計算 --
252
- return gridData.map((seriesData, seriesIndex) => {
253
- const columnIndex = grid.seriesSlotIndexes[seriesIndex] % data.fullDataFormatter.container.columnAmount
254
- const rowIndex = Math.floor(grid.seriesSlotIndexes[seriesIndex] / data.fullDataFormatter.container.columnAmount)
255
- const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
256
- return {
257
- slotIndex: grid.seriesSlotIndexes[seriesIndex],
258
- rowIndex,
259
- columnIndex,
260
- translate,
261
- scale,
262
- }
263
- })
264
- } else {
265
- // -- 依grid的slotIndex計算 --
266
- const columnIndex = grid.slotIndex % data.fullDataFormatter.container.columnAmount
267
- const rowIndex = Math.floor(grid.slotIndex / data.fullDataFormatter.container.columnAmount)
268
- return gridData.map((seriesData, seriesIndex) => {
269
- const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
270
- return {
271
- slotIndex: grid.slotIndex,
272
- rowIndex,
273
- columnIndex,
274
- translate,
275
- scale,
276
- }
277
- })
278
- }
279
-
280
- })
281
- return boxArr
282
- }),
283
- )
284
-
285
- return multiGridContainer$
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
+ )
286
351
  }