@orbcharts/core 3.0.0-alpha.42 → 3.0.0-alpha.44

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. package/dist/orbcharts-core.es.js +1905 -1896
  2. package/dist/orbcharts-core.umd.js +2 -2
  3. package/dist/src/defaults.d.ts +4 -3
  4. package/dist/src/grid/computeGridData.d.ts +4 -11
  5. package/dist/src/grid/gridObservables.d.ts +15 -18
  6. package/dist/src/multiGrid/multiGridObservables.d.ts +4 -11
  7. package/dist/src/series/seriesObservables.d.ts +26 -1
  8. package/dist/src/types/ComputedData.d.ts +1 -0
  9. package/dist/src/types/ComputedDataGrid.d.ts +0 -3
  10. package/dist/src/types/ComputedDataSeries.d.ts +1 -2
  11. package/dist/src/types/ContextObserverGrid.d.ts +11 -4
  12. package/dist/src/types/ContextObserverMultiGrid.d.ts +8 -3
  13. package/dist/src/types/ContextObserverSeries.d.ts +18 -0
  14. package/dist/src/types/DataFormatter.d.ts +8 -5
  15. package/dist/src/types/DataFormatterGrid.d.ts +13 -16
  16. package/dist/src/types/DataFormatterMultiGrid.d.ts +6 -3
  17. package/dist/src/types/DataFormatterMultiValue.d.ts +3 -0
  18. package/dist/src/types/DataFormatterRelationship.d.ts +3 -0
  19. package/dist/src/types/DataFormatterSeries.d.ts +11 -4
  20. package/dist/src/utils/orbchartsUtils.d.ts +14 -13
  21. package/package.json +1 -1
  22. package/src/base/createBaseChart.ts +10 -10
  23. package/src/defaults.ts +36 -64
  24. package/src/grid/computeGridData.ts +15 -86
  25. package/src/grid/createGridContextObserver.ts +33 -16
  26. package/src/grid/gridObservables.ts +157 -70
  27. package/src/multiGrid/computeMultiGridData.ts +77 -120
  28. package/src/multiGrid/createMultiGridContextObserver.ts +8 -8
  29. package/src/multiGrid/multiGridObservables.ts +236 -171
  30. package/src/multiValue/computeMultiValueData.ts +22 -15
  31. package/src/relationship/computeRelationshipData.ts +16 -4
  32. package/src/series/computeSeriesData.ts +51 -114
  33. package/src/series/createSeriesContextObserver.ts +59 -4
  34. package/src/series/seriesObservables.ts +162 -10
  35. package/src/tree/computeTreeData.ts +6 -3
  36. package/src/types/ComputedData.ts +1 -0
  37. package/src/types/ComputedDataGrid.ts +3 -3
  38. package/src/types/ComputedDataSeries.ts +2 -2
  39. package/src/types/ContextObserverGrid.ts +18 -10
  40. package/src/types/ContextObserverMultiGrid.ts +6 -18
  41. package/src/types/ContextObserverSeries.ts +21 -1
  42. package/src/types/DataFormatter.ts +11 -32
  43. package/src/types/DataFormatterGrid.ts +32 -20
  44. package/src/types/DataFormatterMultiGrid.ts +6 -4
  45. package/src/types/DataFormatterMultiValue.ts +3 -0
  46. package/src/types/DataFormatterRelationship.ts +3 -0
  47. package/src/types/DataFormatterSeries.ts +11 -21
  48. package/src/utils/d3Utils.ts +7 -7
  49. package/src/utils/orbchartsUtils.ts +128 -32
@@ -17,20 +17,93 @@ import type {
17
17
  ComputedDatumTypeMap,
18
18
  ContextObserverFn,
19
19
  DataTypeMap,
20
+ DataGridDatum,
21
+ ComputedDatumGrid,
20
22
  DataFormatterTypeMap,
21
23
  DataFormatterGrid,
22
- DataFormatterGridContainer,
23
24
  DataFormatterValueAxis,
24
25
  DataFormatterGroupAxis,
25
- ContainerPosition,
26
+ ComputedLayoutDatumGrid,
27
+ ComputedLayoutDataGrid,
28
+ GridContainerPosition,
26
29
  HighlightTarget,
27
30
  Layout,
28
31
  TransformData } from '../types'
29
32
  import { getMinAndMaxGrid } from '../utils/orbchartsUtils'
30
33
  import { createAxisLinearScale, createAxisPointScale, createAxisQuantizeScale } from '../utils/d3Utils'
31
34
  import { highlightObservable } from '../utils/observables'
32
- import { calcGridContainerPosition } from '../utils/orbchartsUtils'
35
+ import { calcGridContainerLayout } from '../utils/orbchartsUtils'
33
36
  import { DATA_FORMATTER_GRID_GRID_DEFAULT } from '../defaults'
37
+ import { getMinAndMaxValue, transposeData, createGridSeriesLabels, createGridGroupLabels, seriesColorPredicate } from '../utils/orbchartsUtils'
38
+
39
+ export const gridComputedLayoutDataObservable = ({ computedData$, fullDataFormatter$, layout$ }: {
40
+ computedData$: Observable<ComputedDataTypeMap<'grid'>>
41
+ fullDataFormatter$: Observable<DataFormatterTypeMap<'grid'>>
42
+ layout$: Observable<Layout>
43
+ }): Observable<ComputedLayoutDatumGrid[][]> => {
44
+
45
+ // 未篩選group範圍前的group scale
46
+ function createOriginGroupScale (computedData: ComputedDatumGrid[][], dataFormatter: DataFormatterGrid, layout: Layout) {
47
+ const groupAxisWidth = (dataFormatter.grid.groupAxis.position === 'top' || dataFormatter.grid.groupAxis.position === 'bottom')
48
+ ? layout.width
49
+ : layout.height
50
+ const groupEndIndex = computedData[0] ? computedData[0].length - 1 : 0
51
+ const groupScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
52
+ maxValue: groupEndIndex,
53
+ minValue: 0,
54
+ axisWidth: groupAxisWidth,
55
+ scaleDomain: [0, groupEndIndex], // 不使用dataFormatter設定
56
+ scaleRange: [0, 1] // 不使用dataFormatter設定
57
+ })
58
+ return groupScale
59
+ }
60
+
61
+ // 未篩選group範圍及visible前的value scale
62
+ function createOriginValueScale (computedData: ComputedDatumGrid[][], dataFormatter: DataFormatterGrid, layout: Layout) {
63
+ const valueAxisWidth = (dataFormatter.grid.valueAxis.position === 'left' || dataFormatter.grid.valueAxis.position === 'right')
64
+ ? layout.height
65
+ : layout.width
66
+
67
+ const listData = computedData.flat()
68
+ const [minValue, maxValue] = getMinAndMaxValue(listData)
69
+
70
+ const valueScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
71
+ maxValue,
72
+ minValue,
73
+ axisWidth: valueAxisWidth,
74
+ scaleDomain: [minValue, maxValue], // 不使用dataFormatter設定
75
+ scaleRange: [0, 1] // 不使用dataFormatter設定
76
+ })
77
+
78
+ return valueScale
79
+ }
80
+
81
+ return combineLatest({
82
+ computedData: computedData$,
83
+ fullDataFormatter: fullDataFormatter$,
84
+ layout: layout$
85
+ }).pipe(
86
+ switchMap(async d => d),
87
+ map(data => {
88
+ const groupScale = createOriginGroupScale(data.computedData, data.fullDataFormatter, data.layout)
89
+ const valueScale = createOriginValueScale(data.computedData, data.fullDataFormatter, data.layout)
90
+ const zeroY = valueScale(0)
91
+
92
+ return data.computedData.map((seriesData, seriesIndex) => {
93
+ return seriesData.map((groupDatum, groupIndex) => {
94
+ const axisX = groupScale(groupIndex)
95
+ const axisY = valueScale(groupDatum.value ?? 0)
96
+ return {
97
+ ...groupDatum,
98
+ axisX,
99
+ axisY,
100
+ axisYFromZero: axisY - zeroY
101
+ }
102
+ })
103
+ })
104
+ })
105
+ )
106
+ }
34
107
 
35
108
  export const gridAxesTransformObservable = ({ fullDataFormatter$, layout$ }: {
36
109
  fullDataFormatter$: Observable<DataFormatterTypeMap<'grid'>>
@@ -218,10 +291,16 @@ export const gridGraphicTransformObservable = ({ computedData$, fullDataFormatte
218
291
  // -- translateX, scaleX --
219
292
  const rangeMinX = groupScale(groupMin)
220
293
  const rangeMaxX = groupScale(groupMax)
221
- translateX = rangeMinX
222
- const gWidth = rangeMaxX - rangeMinX
223
- scaleX = gWidth / groupAxisWidth
224
-
294
+ if (groupMin == groupMax) {
295
+ // 當group只有一個
296
+ translateX = 0
297
+ scaleX = 1
298
+ } else {
299
+ translateX = rangeMinX
300
+ const gWidth = rangeMaxX - rangeMinX
301
+ scaleX = gWidth / groupAxisWidth
302
+ }
303
+
225
304
  // -- valueScale --
226
305
  const filteredData = data.map((d, i) => {
227
306
  return d.filter((_d, _i) => {
@@ -287,31 +366,31 @@ export const gridGraphicTransformObservable = ({ computedData$, fullDataFormatte
287
366
  })
288
367
  }
289
368
 
290
- export const gridGraphicReverseScaleObservable = ({ gridContainer$, gridAxesTransform$, gridGraphicTransform$ }: {
291
- gridContainer$: Observable<ContainerPosition[]>
369
+ export const gridGraphicReverseScaleObservable = ({ gridContainerPosition$, gridAxesTransform$, gridGraphicTransform$ }: {
370
+ gridContainerPosition$: Observable<GridContainerPosition[]>
292
371
  gridAxesTransform$: Observable<TransformData>
293
372
  gridGraphicTransform$: Observable<TransformData>
294
373
  }): Observable<[number, number][]> => {
295
374
  return combineLatest({
296
- gridContainer: gridContainer$,
375
+ gridContainerPosition: gridContainerPosition$,
297
376
  gridAxesTransform: gridAxesTransform$,
298
377
  gridGraphicTransform: gridGraphicTransform$,
299
378
  }).pipe(
300
379
  switchMap(async (d) => d),
301
380
  map(data => {
302
381
  if (data.gridAxesTransform.rotate == 0 || data.gridAxesTransform.rotate == 180) {
303
- return data.gridContainer.map((series, seriesIndex) => {
382
+ return data.gridContainerPosition.map((series, seriesIndex) => {
304
383
  return [
305
- 1 / data.gridGraphicTransform.scale[0] / data.gridContainer[seriesIndex].scale[0],
306
- 1 / data.gridGraphicTransform.scale[1] / data.gridContainer[seriesIndex].scale[1],
384
+ 1 / data.gridGraphicTransform.scale[0] / data.gridContainerPosition[seriesIndex].scale[0],
385
+ 1 / data.gridGraphicTransform.scale[1] / data.gridContainerPosition[seriesIndex].scale[1],
307
386
  ]
308
387
  })
309
388
  } else {
310
- return data.gridContainer.map((series, seriesIndex) => {
389
+ return data.gridContainerPosition.map((series, seriesIndex) => {
311
390
  // 由於有垂直的旋轉,所以外層 (container) x和y的scale要互換
312
391
  return [
313
- 1 / data.gridGraphicTransform.scale[0] / data.gridContainer[seriesIndex].scale[1],
314
- 1 / data.gridGraphicTransform.scale[1] / data.gridContainer[seriesIndex].scale[0],
392
+ 1 / data.gridGraphicTransform.scale[0] / data.gridContainerPosition[seriesIndex].scale[1],
393
+ 1 / data.gridGraphicTransform.scale[1] / data.gridContainerPosition[seriesIndex].scale[0],
315
394
  ]
316
395
  })
317
396
  }
@@ -380,7 +459,7 @@ export const gridAxesSizeObservable = ({ fullDataFormatter$, layout$ }: {
380
459
  // return highlightObservable ({ datumList$, fullChartParams$, event$ })
381
460
  // }
382
461
 
383
- export const existSeriesLabelsObservable = ({ computedData$ }: { computedData$: Observable<ComputedDataTypeMap<'grid'>> }) => {
462
+ export const seriesLabelsObservable = ({ computedData$ }: { computedData$: Observable<ComputedDataTypeMap<'grid'>> }) => {
384
463
  return computedData$.pipe(
385
464
  map(data => {
386
465
  return data
@@ -410,78 +489,86 @@ export const gridVisibleComputedDataObservable = ({ computedData$ }: { computedD
410
489
  )
411
490
  }
412
491
 
413
- export const isSeriesPositionSeprateObservable = ({ computedData$, fullDataFormatter$ }: {
414
- computedData$: Observable<ComputedDataTypeMap<'grid'>>
415
- fullDataFormatter$: Observable<DataFormatterTypeMap<'grid'>>
416
- }) => {
417
- return combineLatest({
418
- computedData: computedData$,
419
- fullDataFormatter: fullDataFormatter$
420
- }).pipe(
492
+ export const gridVisibleComputedLayoutDataObservable = ({ computedLayoutData$ }: { computedLayoutData$: Observable<ComputedLayoutDataGrid> }) => {
493
+ return computedLayoutData$.pipe(
421
494
  map(data => {
422
- return data.fullDataFormatter.grid.seriesSlotIndexes && data.fullDataFormatter.grid.seriesSlotIndexes.length === data.computedData.length
423
- ? true
424
- : false
425
- }),
426
- distinctUntilChanged()
495
+ const visibleComputedData = data
496
+ .map(d => {
497
+ return d.filter(_d => {
498
+ return _d.visible == true
499
+ })
500
+ })
501
+ .filter(d => d.length)
502
+ return visibleComputedData
503
+ })
427
504
  )
428
505
  }
429
506
 
507
+ // export const isSeriesSeprateObservable = ({ computedData$, fullDataFormatter$ }: {
508
+ // computedData$: Observable<ComputedDataTypeMap<'grid'>>
509
+ // fullDataFormatter$: Observable<DataFormatterTypeMap<'grid'>>
510
+ // }) => {
511
+ // return combineLatest({
512
+ // computedData: computedData$,
513
+ // fullDataFormatter: fullDataFormatter$
514
+ // }).pipe(
515
+ // map(data => {
516
+ // return data.fullDataFormatter.grid.seriesSlotIndexes && data.fullDataFormatter.grid.seriesSlotIndexes.length === data.computedData.length
517
+ // ? true
518
+ // : false
519
+ // }),
520
+ // distinctUntilChanged()
521
+ // )
522
+ // }
523
+
430
524
  // 所有container位置(對應series)
431
- export const gridContainerObservable = ({ computedData$, fullDataFormatter$, fullChartParams$, layout$ }: {
525
+ export const gridContainerPositionObservable = ({ computedData$, fullDataFormatter$, layout$ }: {
432
526
  computedData$: Observable<ComputedDataTypeMap<'grid'>>
433
527
  fullDataFormatter$: Observable<DataFormatterTypeMap<'grid'>>
434
- fullChartParams$: Observable<ChartParams>
435
528
  layout$: Observable<Layout>
436
- }) => {
529
+ }): Observable<GridContainerPosition[]> => {
437
530
 
438
- const gridContainer$ = combineLatest({
531
+ const gridContainerPosition$ = combineLatest({
439
532
  computedData: computedData$,
440
533
  fullDataFormatter: fullDataFormatter$,
441
- fullChartParams: fullChartParams$,
442
534
  layout: layout$,
443
535
  }).pipe(
444
536
  switchMap(async (d) => d),
445
537
  map(data => {
446
-
447
- const grid = data.fullDataFormatter.grid
448
538
 
449
- // 有設定series定位
450
- const hasSeriesPosition = grid.seriesSlotIndexes && grid.seriesSlotIndexes.length === data.computedData.length
451
- ? true
452
- : false
453
-
454
- if (hasSeriesPosition) {
455
- // -- 依seriesSlotIndexes計算 --
456
- return data.computedData.map((seriesData, seriesIndex) => {
457
- const columnIndex = grid.seriesSlotIndexes[seriesIndex] % data.fullDataFormatter.container.columnAmount
458
- const rowIndex = Math.floor(grid.seriesSlotIndexes[seriesIndex] / data.fullDataFormatter.container.columnAmount)
459
- const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
460
- return {
461
- slotIndex: grid.seriesSlotIndexes[seriesIndex],
462
- rowIndex,
463
- columnIndex,
464
- translate,
465
- scale,
466
- }
467
- })
539
+ if (data.fullDataFormatter.grid.separateSeries) {
540
+ // -- 依slotIndexes計算 --
541
+ return calcGridContainerLayout(data.layout, data.fullDataFormatter.container, data.computedData.length)
542
+ // return data.computedData.map((seriesData, seriesIndex) => {
543
+ // const columnIndex = seriesIndex % data.fullDataFormatter.container.columnAmount
544
+ // const rowIndex = Math.floor(seriesIndex / data.fullDataFormatter.container.columnAmount)
545
+ // const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
546
+ // return {
547
+ // slotIndex: seriesIndex,
548
+ // rowIndex,
549
+ // columnIndex,
550
+ // translate,
551
+ // scale,
552
+ // }
553
+ // })
468
554
  } else {
469
- // -- 依grid的slotIndex計算 --
470
- const columnIndex = grid.slotIndex % data.fullDataFormatter.container.columnAmount
471
- const rowIndex = Math.floor(grid.slotIndex / data.fullDataFormatter.container.columnAmount)
472
- return data.computedData.map((seriesData, seriesIndex) => {
473
- const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
474
- return {
475
- slotIndex: grid.slotIndex,
476
- rowIndex,
477
- columnIndex,
478
- translate,
479
- scale,
480
- }
481
- })
555
+ // -- 無拆分 --
556
+ return calcGridContainerLayout(data.layout, data.fullDataFormatter.container, 1)
557
+ // const columnIndex = 0
558
+ // const rowIndex = 0
559
+ // return data.computedData.map((seriesData, seriesIndex) => {
560
+ // const { translate, scale } = calcGridContainerPosition(data.layout, data.fullDataFormatter.container, rowIndex, columnIndex)
561
+ // return {
562
+ // slotIndex: 0,
563
+ // rowIndex,
564
+ // columnIndex,
565
+ // translate,
566
+ // scale,
567
+ // }
568
+ // })
482
569
  }
483
570
  })
484
571
  )
485
572
 
486
- return gridContainer$
573
+ return gridContainerPosition$
487
574
  }
@@ -1,8 +1,8 @@
1
- import type { DataGrid } from '../types/DataGrid'
1
+ import type { DataGrid, DataGridDatum } from '../types/DataGrid'
2
2
  import type { ComputedDataFn } from '../types/ComputedData'
3
3
  import type { ComputedDatumGrid } from '../types/ComputedDataGrid'
4
4
  import type { DataFormatterContext } from '../types/DataFormatter'
5
- import type { DataFormatterGrid } from '../types/DataFormatterGrid'
5
+ import type { DataFormatterGridGrid } from '../types/DataFormatterGrid'
6
6
  import type { ComputedDataMultiGrid } from '../types/ComputedDataMultiGrid'
7
7
  // import { computeBaseGridData } from '../grid/computeGridData'
8
8
  import { DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT } from '../defaults'
@@ -13,76 +13,11 @@ import {
13
13
  createMultiGridSeriesLabels,
14
14
  createMultiGridGroupLabels
15
15
  } from '../utils/orbchartsUtils'
16
- import type { DataGridDatumTemp } from '../grid/computeGridData'
17
- import { createTransposedDataGrid, createGroupScale, createSeriesValueScaleArr } from '../grid/computeGridData'
16
+ // import type { DataGridDatumTemp } from '../grid/computeGridData'
17
+ import { createTransposedDataGrid } from '../grid/computeGridData'
18
18
 
19
- function createGridData ({ context, gridIndex, transposedDataGrid, gridSeriesLabels, SeriesLabelColorMap }: {
20
- context: DataFormatterContext<'grid'>
21
- gridIndex: number
22
- transposedDataGrid: DataGridDatumTemp[][]
23
- gridSeriesLabels: string[]
24
- SeriesLabelColorMap: Map<string, string>
25
- }) {
26
- const { data = [], dataFormatter, chartParams, layout } = context
27
- if (!data.length) {
28
- return []
29
- }
30
-
31
- const groupScale = createGroupScale(transposedDataGrid, dataFormatter, layout)
32
-
33
- // const seriesLabels = createGridSeriesLabels({ transposedDataGrid, dataFormatter, chartType: 'multiGrid', gridIndex })
34
-
35
- const groupLabels = createMultiGridGroupLabels({ transposedDataGrid, dataFormatter, chartType: 'multiGrid', gridIndex })
36
-
37
- // 每一個series的valueScale
38
- const seriesValueScaleArr = createSeriesValueScaleArr(transposedDataGrid, dataFormatter, layout)
39
-
40
- const zeroYArr = transposedDataGrid.map((series, seriesIndex) => {
41
- return seriesValueScaleArr[seriesIndex]!(0)
42
- })
43
-
44
- let _index = 0
45
- let computedDataGrid: ComputedDatumGrid[][] = transposedDataGrid.map((seriesData, seriesIndex) => {
46
- return seriesData.map((groupDatum, groupIndex) => {
47
-
48
- const defaultId = createDefaultDatumId('multiGrid', gridIndex, seriesIndex, groupIndex)
49
- const groupLabel = groupLabels[groupIndex]
50
- const seriesLabel = gridSeriesLabels[seriesIndex]
51
- const valueScale = seriesValueScaleArr[seriesIndex]
52
- const axisY = valueScale(groupDatum.value ?? 0)
53
- const zeroY = zeroYArr[seriesIndex]
54
-
55
- const computedDatum: ComputedDatumGrid = {
56
- id: groupDatum.id ? groupDatum.id : defaultId,
57
- index: _index,
58
- label: groupDatum.label ? groupDatum.label : defaultId,
59
- description: groupDatum.description ?? '',
60
- data: groupDatum.data,
61
- value: groupDatum.value,
62
- gridIndex,
63
- // accSeriesIndex: seriesIndex, // 預設為seriesIndex
64
- seriesIndex,
65
- seriesLabel,
66
- groupIndex,
67
- groupLabel,
68
- // color: seriesColorPredicate(seriesIndex, chartParams),
69
- color: SeriesLabelColorMap.get(seriesLabel),
70
- axisX: groupScale(groupIndex),
71
- axisY,
72
- axisYFromZero: axisY - zeroY,
73
- visible: groupDatum._visible
74
- }
75
-
76
- _index ++
77
-
78
- return computedDatum
79
- })
80
- })
81
-
82
- return computedDataGrid
83
- }
84
-
85
- export const computeMultiGridData: ComputedDataFn<'multiGrid'> = ({ data = [], dataFormatter, chartParams, layout }) => {
19
+ export const computeMultiGridData: ComputedDataFn<'multiGrid'> = (context) => {
20
+ const { data = [], dataFormatter, chartParams } = context
86
21
  if (!data.length) {
87
22
  return []
88
23
  }
@@ -93,54 +28,41 @@ export const computeMultiGridData: ComputedDataFn<'multiGrid'> = ({ data = [], d
93
28
  const defaultGrid = dataFormatter.gridList[0] || DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT
94
29
 
95
30
  // 計算每個grid的dataFormatter
96
- const gridDataFormatterList: DataFormatterGrid[] = data.map((gridData, gridIndex) => {
97
- const currentDataFormatterGrid = dataFormatter.gridList[gridIndex] || defaultGrid
98
-
99
- return {
100
- type: 'grid',
101
- grid: {
102
- ...currentDataFormatterGrid
103
- },
104
- container: {
105
- ...dataFormatter.container
106
- }
107
- }
108
- })
109
-
110
- const gridContextList = data.map((gridData, gridIndex) => {
111
- // grid context
112
- return {
113
- data: gridData,
114
- dataFormatter: gridDataFormatterList[gridIndex],
115
- chartParams,
116
- layout
117
- }
31
+ const gridDataFormatterList: DataFormatterGridGrid[] = data.map((gridData, gridIndex) => {
32
+ return dataFormatter.gridList[gridIndex] || defaultGrid
118
33
  })
119
34
 
120
35
  const transposedDataGridList = data.map((gridData, gridIndex) => {
121
36
  // 依seriesDirection轉置資料矩陣
122
- return createTransposedDataGrid(gridContextList[gridIndex])
37
+ return createTransposedDataGrid(gridData, gridDataFormatterList[gridIndex])
123
38
  })
124
39
 
125
- const createSeriesLabelsFn = (() => {
126
- const SlotIndexSet = new Set(gridDataFormatterList.map(d => d.grid.slotIndex))
127
- // 判斷是否有重疊的grid
128
- const isOverlappingMultiGrid = SlotIndexSet.size !== gridDataFormatterList.length
129
- return isOverlappingMultiGrid
130
- ? createMultiGridSeriesLabels // 有重疊的grid則使用「不同」的seriesLabels
131
- : createGridSeriesLabels // 沒有重疊的grid則使用「相同」的seriesLabels
132
- })()
133
-
134
-
135
- const multiGridSeriesLabels = transposedDataGridList
136
- .map((gridData, gridIndex) => {
137
- return createSeriesLabelsFn({
138
- transposedDataGrid: gridData,
139
- dataFormatter: gridDataFormatterList[gridIndex],
140
- chartType: 'multiGrid',
141
- gridIndex
142
- } as any)
143
- })
40
+ // const isOverlappingMultiGrid = (() => {
41
+ // const SlotIndexSet = new Set(gridDataFormatterList.map(d => d.slotIndex))
42
+ // // 判斷是否有重疊的grid
43
+ // return SlotIndexSet.size !== gridDataFormatterList.length
44
+ // })()
45
+
46
+ const multiGridSeriesLabels = dataFormatter.separateGrid
47
+ // grid分開的時候,預設每組的seriesLabels相同
48
+ ? transposedDataGridList
49
+ .map((gridData, gridIndex) => {
50
+ return createGridSeriesLabels({
51
+ transposedDataGrid: gridData,
52
+ dataFormatterGrid: gridDataFormatterList[gridIndex],
53
+ chartType: 'multiGrid',
54
+ })
55
+ })
56
+ // grid不分開的時候,預設每個grid相同seriesIndex的seriesLabel相同
57
+ : transposedDataGridList
58
+ .map((gridData, gridIndex) => {
59
+ return createMultiGridSeriesLabels({
60
+ transposedDataGrid: gridData,
61
+ dataFormatterGrid: gridDataFormatterList[gridIndex],
62
+ chartType: 'multiGrid',
63
+ gridIndex
64
+ })
65
+ })
144
66
 
145
67
  const SeriesLabelColorMap: Map<string, string> = new Map()
146
68
  let accIndex = 0
@@ -153,14 +75,49 @@ export const computeMultiGridData: ComputedDataFn<'multiGrid'> = ({ data = [], d
153
75
  })
154
76
 
155
77
  // 計算每個grid的資料
156
- multiGridData = data.map((gridData, gridIndex) => {
157
- return createGridData({
158
- context: gridContextList[gridIndex],
159
- gridIndex,
160
- transposedDataGrid: transposedDataGridList[gridIndex],
161
- gridSeriesLabels: multiGridSeriesLabels[gridIndex],
162
- SeriesLabelColorMap
78
+ multiGridData = transposedDataGridList.map((gridData, gridIndex) => {
79
+ const gridSeriesLabels = multiGridSeriesLabels[gridIndex]
80
+ const groupLabels = createMultiGridGroupLabels({
81
+ transposedDataGrid: gridData,
82
+ dataFormatterGrid: gridDataFormatterList[gridIndex],
83
+ chartType: 'multiGrid',
84
+ gridIndex
163
85
  })
86
+
87
+ let _index = 0
88
+ let computedDataGrid: ComputedDatumGrid[][] = gridData.map((seriesData, seriesIndex) => {
89
+ return seriesData.map((groupDatum, groupIndex) => {
90
+
91
+ const defaultId = createDefaultDatumId('multiGrid', gridIndex, seriesIndex, groupIndex)
92
+ const groupLabel = groupLabels[groupIndex]
93
+ const seriesLabel = gridSeriesLabels[seriesIndex]
94
+
95
+ const computedDatum: ComputedDatumGrid = {
96
+ id: groupDatum.id ? groupDatum.id : defaultId,
97
+ index: _index,
98
+ label: groupDatum.label ? groupDatum.label : defaultId,
99
+ description: groupDatum.description ?? '',
100
+ data: groupDatum.data,
101
+ value: groupDatum.value,
102
+ gridIndex,
103
+ // accSeriesIndex: seriesIndex, // 預設為seriesIndex
104
+ seriesIndex,
105
+ seriesLabel,
106
+ groupIndex,
107
+ groupLabel,
108
+ color: SeriesLabelColorMap.get(seriesLabel),
109
+ visible: true // 先給一個預設值
110
+ }
111
+
112
+ computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
113
+
114
+ _index ++
115
+
116
+ return computedDatum
117
+ })
118
+ })
119
+
120
+ return computedDataGrid
164
121
  })
165
122
 
166
123
 
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  shareReplay } from 'rxjs'
3
3
  import type { ContextObserverFn } from '../types'
4
- import { multiGridEachDetailObservable, multiGridContainerObservable } from './multiGridObservables'
4
+ import { multiGridEachDetailObservable } from './multiGridObservables'
5
5
  import { textSizePxObservable } from '../utils/observables'
6
6
 
7
7
  export const createMultiGridContextObserver: ContextObserverFn<'multiGrid'> = ({ subject, observer }) => {
@@ -20,12 +20,12 @@ export const createMultiGridContextObserver: ContextObserverFn<'multiGrid'> = ({
20
20
  shareReplay(1)
21
21
  )
22
22
 
23
- const multiGridContainer$ = multiGridContainerObservable({
24
- computedData$: observer.computedData$,
25
- fullDataFormatter$: observer.fullDataFormatter$,
26
- fullChartParams$: observer.fullChartParams$,
27
- layout$: observer.layout$,
28
- })
23
+ // const multiGridContainer$ = multiGridContainerObservable({
24
+ // computedData$: observer.computedData$,
25
+ // fullDataFormatter$: observer.fullDataFormatter$,
26
+ // fullChartParams$: observer.fullChartParams$,
27
+ // layout$: observer.layout$,
28
+ // })
29
29
 
30
30
  return {
31
31
  fullParams$: observer.fullParams$,
@@ -35,6 +35,6 @@ export const createMultiGridContextObserver: ContextObserverFn<'multiGrid'> = ({
35
35
  layout$: observer.layout$,
36
36
  textSizePx$,
37
37
  multiGridEachDetail$,
38
- multiGridContainer$
38
+ // multiGridContainer$
39
39
  }
40
40
  }