@orbcharts/core 3.0.0-beta.8 → 3.0.0

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 (76) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +2734 -2353
  3. package/dist/orbcharts-core.umd.js +4 -4
  4. package/dist/src/defaults.d.ts +2 -1
  5. package/dist/src/utils/gridObservables.d.ts +8 -4
  6. package/dist/src/utils/index.d.ts +0 -3
  7. package/dist/src/utils/multiGridObservables.d.ts +3 -2
  8. package/dist/src/utils/multiValueObservables.d.ts +76 -29
  9. package/dist/src/utils/observables.d.ts +8 -1
  10. package/dist/src/utils/orbchartsUtils.d.ts +9 -9
  11. package/dist/src/utils/seriesObservables.d.ts +1 -1
  12. package/lib/core-types.ts +7 -7
  13. package/package.json +42 -42
  14. package/src/AbstractChart.ts +57 -57
  15. package/src/GridChart.ts +24 -24
  16. package/src/MultiGridChart.ts +24 -24
  17. package/src/MultiValueChart.ts +24 -24
  18. package/src/RelationshipChart.ts +24 -24
  19. package/src/SeriesChart.ts +24 -24
  20. package/src/TreeChart.ts +24 -24
  21. package/src/base/createBaseChart.ts +506 -505
  22. package/src/base/createBasePlugin.ts +154 -153
  23. package/src/base/validators/chartOptionsValidator.ts +23 -23
  24. package/src/base/validators/chartParamsValidator.ts +133 -133
  25. package/src/base/validators/elementValidator.ts +13 -13
  26. package/src/base/validators/pluginsValidator.ts +14 -14
  27. package/src/defaults.ts +282 -238
  28. package/src/defineGridPlugin.ts +3 -3
  29. package/src/defineMultiGridPlugin.ts +3 -3
  30. package/src/defineMultiValuePlugin.ts +3 -3
  31. package/src/defineNoneDataPlugin.ts +4 -4
  32. package/src/defineRelationshipPlugin.ts +3 -3
  33. package/src/defineSeriesPlugin.ts +3 -3
  34. package/src/defineTreePlugin.ts +3 -3
  35. package/src/grid/computedDataFn.ts +129 -129
  36. package/src/grid/contextObserverCallback.ts +198 -176
  37. package/src/grid/dataFormatterValidator.ts +120 -101
  38. package/src/grid/dataValidator.ts +12 -12
  39. package/src/index.ts +20 -20
  40. package/src/multiGrid/computedDataFn.ts +123 -123
  41. package/src/multiGrid/contextObserverCallback.ts +72 -41
  42. package/src/multiGrid/dataFormatterValidator.ts +115 -115
  43. package/src/multiGrid/dataValidator.ts +12 -12
  44. package/src/multiValue/computedDataFn.ts +113 -110
  45. package/src/multiValue/contextObserverCallback.ts +276 -160
  46. package/src/multiValue/dataFormatterValidator.ts +89 -9
  47. package/src/multiValue/dataValidator.ts +12 -9
  48. package/src/relationship/computedDataFn.ts +159 -144
  49. package/src/relationship/contextObserverCallback.ts +80 -80
  50. package/src/relationship/dataFormatterValidator.ts +13 -9
  51. package/src/relationship/dataValidator.ts +13 -9
  52. package/src/series/computedDataFn.ts +88 -88
  53. package/src/series/contextObserverCallback.ts +107 -100
  54. package/src/series/dataFormatterValidator.ts +41 -41
  55. package/src/series/dataValidator.ts +12 -12
  56. package/src/tree/computedDataFn.ts +129 -129
  57. package/src/tree/contextObserverCallback.ts +58 -58
  58. package/src/tree/dataFormatterValidator.ts +13 -13
  59. package/src/tree/dataValidator.ts +13 -13
  60. package/src/utils/commonUtils.ts +55 -55
  61. package/src/utils/d3Scale.ts +198 -198
  62. package/src/utils/errorMessage.ts +42 -42
  63. package/src/utils/gridObservables.ts +705 -683
  64. package/src/utils/index.ts +10 -10
  65. package/src/utils/multiGridObservables.ts +401 -392
  66. package/src/utils/multiValueObservables.ts +1044 -662
  67. package/src/utils/observables.ts +281 -219
  68. package/src/utils/orbchartsUtils.ts +377 -377
  69. package/src/utils/relationshipObservables.ts +84 -84
  70. package/src/utils/seriesObservables.ts +175 -175
  71. package/src/utils/treeObservables.ts +105 -105
  72. package/src/utils/validator.ts +126 -126
  73. package/tsconfig.base.json +13 -13
  74. package/tsconfig.json +2 -2
  75. package/vite-env.d.ts +6 -6
  76. package/vite.config.js +22 -22
@@ -1,102 +1,121 @@
1
- import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
2
- import { validateColumns } from '../utils/validator'
3
-
4
- export const dataFormatterValidator: DataFormatterValidator<'grid'> = (dataFormatter: DataFormatterTypeMap<'grid'>) => {
5
- const result = validateColumns(dataFormatter, {
6
- visibleFilter: {
7
- toBeTypes: ['Function']
8
- },
9
- // grid: {
10
- // toBeTypes: ['object']
11
- // },
12
- container: {
13
- toBeTypes: ['object']
14
- }
15
- })
16
- // if (dataFormatter.grid) {
17
- const visibleFilterResult = validateColumns(dataFormatter, {
18
- seriesDirection: {
19
- toBe: '"row" | "column"',
20
- test: (value) => value === 'row' || value === 'column'
21
- },
22
- rowLabels: {
23
- toBeTypes: ['string[]']
24
- },
25
- columnLabels: {
26
- toBeTypes: ['string[]']
27
- },
28
- valueAxis: {
29
- toBeTypes: ['object']
30
- },
31
- groupAxis: {
32
- toBeTypes: ['object']
33
- },
34
- separateSeries: {
35
- toBeTypes: ['boolean']
36
- }
37
- })
38
- if (visibleFilterResult.status === 'error') {
39
- return visibleFilterResult
40
- }
41
- if (dataFormatter.valueAxis) {
42
- const valueAxisResult = validateColumns(dataFormatter.valueAxis, {
43
- position: {
44
- toBe: '"bottom" | "left" | "top" | "right"',
45
- test: (value) => value === 'bottom' || value === 'left' || value === 'top' || value === 'right'
46
- },
47
- scaleDomain: {
48
- toBe: '[number | "min" | "auto", number | "max" | "auto"]',
49
- test: (value) => Array.isArray(value) && value.length === 2 && (typeof value[0] === 'number' || value[0] === 'min' || value[0] === 'auto') && (typeof value[1] === 'number' || value[1] === 'max' || value[1] === 'auto')
50
- },
51
- scaleRange: {
52
- toBe: '[number, number]',
53
- test: (value) => Array.isArray(value) && value.length === 2 && typeof value[0] === 'number' && typeof value[1] === 'number'
54
- },
55
- label: {
56
- toBeTypes: ['string']
57
- }
58
- })
59
- if (valueAxisResult.status === 'error') {
60
- return valueAxisResult
61
- }
62
- }
63
- if (dataFormatter.groupAxis) {
64
- const groupAxisResult = validateColumns(dataFormatter.groupAxis, {
65
- position: {
66
- toBe: '"bottom" | "left" | "top" | "right"',
67
- test: (value) => value === 'bottom' || value === 'left' || value === 'top' || value === 'right'
68
- },
69
- scaleDomain: {
70
- toBe: '[number, number | "max"]',
71
- test: (value) => Array.isArray(value) && value.length === 2 && typeof value[0] === 'number' && (typeof value[1] === 'number' || value[1] === 'max')
72
- },
73
- scalePadding: {
74
- toBeTypes: ['number']
75
- },
76
- label: {
77
- toBeTypes: ['string']
78
- }
79
- })
80
- if (groupAxisResult.status === 'error') {
81
- return groupAxisResult
82
- }
83
- }
84
- // }
85
- if (dataFormatter.container) {
86
- const containerResult = validateColumns(dataFormatter.container, {
87
- gap: {
88
- toBeTypes: ['number']
89
- },
90
- rowAmount: {
91
- toBeTypes: ['number']
92
- },
93
- columnAmount: {
94
- toBeTypes: ['number']
95
- }
96
- })
97
- if (containerResult.status === 'error') {
98
- return containerResult
99
- }
100
- }
101
- return result
1
+ import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
2
+ import { validateColumns } from '../utils/validator'
3
+
4
+ export const dataFormatterValidator: DataFormatterValidator<'grid'> = (dataFormatter: DataFormatterTypeMap<'grid'>) => {
5
+ const result = validateColumns(dataFormatter, {
6
+ visibleFilter: {
7
+ toBeTypes: ['Function']
8
+ },
9
+ // grid: {
10
+ // toBeTypes: ['object']
11
+ // },
12
+ container: {
13
+ toBeTypes: ['object']
14
+ },
15
+ seriesDirection: {
16
+ toBe: '"row" | "column"',
17
+ test: (value) => value === 'row' || value === 'column'
18
+ },
19
+ rowLabels: {
20
+ toBeTypes: ['string[]']
21
+ },
22
+ columnLabels: {
23
+ toBeTypes: ['string[]']
24
+ },
25
+ valueAxis: {
26
+ toBeTypes: ['object']
27
+ },
28
+ groupAxis: {
29
+ toBeTypes: ['object']
30
+ },
31
+ separateSeries: {
32
+ toBeTypes: ['boolean']
33
+ }
34
+ })
35
+ // if (dataFormatter.grid) {
36
+ // const visibleFilterResult = validateColumns(dataFormatter, {
37
+ // seriesDirection: {
38
+ // toBe: '"row" | "column"',
39
+ // test: (value) => value === 'row' || value === 'column'
40
+ // },
41
+ // rowLabels: {
42
+ // toBeTypes: ['string[]']
43
+ // },
44
+ // columnLabels: {
45
+ // toBeTypes: ['string[]']
46
+ // },
47
+ // valueAxis: {
48
+ // toBeTypes: ['object']
49
+ // },
50
+ // groupAxis: {
51
+ // toBeTypes: ['object']
52
+ // },
53
+ // separateSeries: {
54
+ // toBeTypes: ['boolean']
55
+ // }
56
+ // })
57
+ if (result.status === 'error') {
58
+ return result
59
+ }
60
+ if (dataFormatter.valueAxis) {
61
+ const valueAxisResult = validateColumns(dataFormatter.valueAxis, {
62
+ position: {
63
+ toBe: '"bottom" | "left" | "top" | "right"',
64
+ test: (value) => value === 'bottom' || value === 'left' || value === 'top' || value === 'right'
65
+ },
66
+ scaleDomain: {
67
+ toBe: '[number | "min" | "auto", number | "max" | "auto"]',
68
+ test: (value) => Array.isArray(value) && value.length === 2 && (typeof value[0] === 'number' || value[0] === 'min' || value[0] === 'auto') && (typeof value[1] === 'number' || value[1] === 'max' || value[1] === 'auto')
69
+ },
70
+ scaleRange: {
71
+ toBe: '[number, number]',
72
+ test: (value) => Array.isArray(value) && value.length === 2 && typeof value[0] === 'number' && typeof value[1] === 'number'
73
+ },
74
+ label: {
75
+ toBeTypes: ['string']
76
+ }
77
+ })
78
+ if (valueAxisResult.status === 'error') {
79
+ return valueAxisResult
80
+ }
81
+ }
82
+ if (dataFormatter.groupAxis) {
83
+ const groupAxisResult = validateColumns(dataFormatter.groupAxis, {
84
+ position: {
85
+ toBe: '"bottom" | "left" | "top" | "right"',
86
+ test: (value) => value === 'bottom' || value === 'left' || value === 'top' || value === 'right'
87
+ },
88
+ scaleDomain: {
89
+ toBe: '[number, number | "max"]',
90
+ test: (value) => Array.isArray(value) && value.length === 2 && typeof value[0] === 'number' && (typeof value[1] === 'number' || value[1] === 'max')
91
+ },
92
+ scalePadding: {
93
+ toBeTypes: ['number']
94
+ },
95
+ label: {
96
+ toBeTypes: ['string']
97
+ }
98
+ })
99
+ if (groupAxisResult.status === 'error') {
100
+ return groupAxisResult
101
+ }
102
+ }
103
+ // }
104
+ if (dataFormatter.container) {
105
+ const containerResult = validateColumns(dataFormatter.container, {
106
+ gap: {
107
+ toBeTypes: ['number']
108
+ },
109
+ rowAmount: {
110
+ toBeTypes: ['number']
111
+ },
112
+ columnAmount: {
113
+ toBeTypes: ['number']
114
+ }
115
+ })
116
+ if (containerResult.status === 'error') {
117
+ return containerResult
118
+ }
119
+ }
120
+ return result
102
121
  }
@@ -1,13 +1,13 @@
1
- import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
- import { validateColumns } from '../utils/validator'
3
-
4
- export const dataValidator: DataValidator<'grid'> = (data: DataTypeMap<'grid'>) => {
5
- const result = validateColumns({ data }, {
6
- data: {
7
- toBe: '(DataGridDatum | DataGridValue)[][]',
8
- // 畢免資料量過大檢查不完,不深度檢查
9
- test: (value) => Array.isArray(value)
10
- }
11
- })
12
- return result
1
+ import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
+ import { validateColumns } from '../utils/validator'
3
+
4
+ export const dataValidator: DataValidator<'grid'> = (data: DataTypeMap<'grid'>) => {
5
+ const result = validateColumns({ data }, {
6
+ data: {
7
+ toBe: '(DataGridDatum | DataGridValue)[][]',
8
+ // 畢免資料量過大檢查不完,不深度檢查
9
+ test: (value) => Array.isArray(value)
10
+ }
11
+ })
12
+ return result
13
13
  }
package/src/index.ts CHANGED
@@ -1,20 +1,20 @@
1
-
2
- export { SeriesChart } from './SeriesChart'
3
- export { GridChart } from './GridChart'
4
- export { MultiGridChart } from './MultiGridChart'
5
- export { MultiValueChart } from './MultiValueChart'
6
- export { RelationshipChart } from './RelationshipChart'
7
- export { TreeChart } from './TreeChart'
8
-
9
- export { defineSeriesPlugin } from './defineSeriesPlugin'
10
- export { defineGridPlugin } from './defineGridPlugin'
11
- export { defineMultiGridPlugin } from './defineMultiGridPlugin'
12
- export { defineMultiValuePlugin } from './defineMultiValuePlugin'
13
- export { defineNoneDataPlugin } from './defineNoneDataPlugin'
14
- export { defineRelationshipPlugin } from './defineRelationshipPlugin'
15
- export { defineTreePlugin } from './defineTreePlugin'
16
-
17
- export * from './utils'
18
- export * from './defaults'
19
-
20
-
1
+
2
+ export { SeriesChart } from './SeriesChart'
3
+ export { GridChart } from './GridChart'
4
+ export { MultiGridChart } from './MultiGridChart'
5
+ export { MultiValueChart } from './MultiValueChart'
6
+ export { RelationshipChart } from './RelationshipChart'
7
+ export { TreeChart } from './TreeChart'
8
+
9
+ export { defineSeriesPlugin } from './defineSeriesPlugin'
10
+ export { defineGridPlugin } from './defineGridPlugin'
11
+ export { defineMultiGridPlugin } from './defineMultiGridPlugin'
12
+ export { defineMultiValuePlugin } from './defineMultiValuePlugin'
13
+ export { defineNoneDataPlugin } from './defineNoneDataPlugin'
14
+ export { defineRelationshipPlugin } from './defineRelationshipPlugin'
15
+ export { defineTreePlugin } from './defineTreePlugin'
16
+
17
+ export * from './utils'
18
+ export * from './defaults'
19
+
20
+
@@ -1,123 +1,123 @@
1
- import type { ComputedDataFn, ComputedDatumGrid, DataFormatterGridGrid, ComputedDataMultiGrid } from '../../lib/core-types'
2
- import { DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID } from '../defaults'
3
- import {
4
- createDefaultDatumId,
5
- seriesColorPredicate,
6
- createGridSeriesLabels,
7
- createMultiGridSeriesLabels,
8
- createMultiGridGroupLabels
9
- } from '../utils/orbchartsUtils'
10
- import { createTransposedDataGrid } from '../grid/computedDataFn'
11
-
12
- export const computedDataFn: ComputedDataFn<'multiGrid'> = (context) => {
13
- const { data = [], dataFormatter, chartParams } = context
14
- if (!data.length) {
15
- return []
16
- }
17
-
18
- let multiGridData: ComputedDataMultiGrid = []
19
-
20
- try {
21
- const defaultGrid = dataFormatter.gridList[0] || DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID
22
-
23
- // 計算每個grid的dataFormatter
24
- const gridDataFormatterList: DataFormatterGridGrid[] = data.map((gridData, gridIndex) => {
25
- return dataFormatter.gridList[gridIndex] || defaultGrid
26
- })
27
-
28
- const transposedDataGridList = data.map((gridData, gridIndex) => {
29
- // 依seriesDirection轉置資料矩陣
30
- return createTransposedDataGrid(gridData, gridDataFormatterList[gridIndex])
31
- })
32
-
33
- // const isOverlappingMultiGrid = (() => {
34
- // const SlotIndexSet = new Set(gridDataFormatterList.map(d => d.slotIndex))
35
- // // 判斷是否有重疊的grid
36
- // return SlotIndexSet.size !== gridDataFormatterList.length
37
- // })()
38
-
39
- const multiGridSeriesLabels = dataFormatter.separateGrid
40
- // grid分開的時候,預設每組的seriesLabels相同
41
- ? transposedDataGridList
42
- .map((gridData, gridIndex) => {
43
- return createGridSeriesLabels({
44
- transposedDataGrid: gridData,
45
- dataFormatterGrid: gridDataFormatterList[gridIndex],
46
- chartType: 'multiGrid',
47
- })
48
- })
49
- // grid不分開的時候,預設每個grid相同seriesIndex的seriesLabel相同
50
- : transposedDataGridList
51
- .map((gridData, gridIndex) => {
52
- return createMultiGridSeriesLabels({
53
- transposedDataGrid: gridData,
54
- dataFormatterGrid: gridDataFormatterList[gridIndex],
55
- chartType: 'multiGrid',
56
- gridIndex
57
- })
58
- })
59
-
60
- const SeriesLabelColorMap: Map<string, string> = new Map()
61
- let accIndex = 0
62
- multiGridSeriesLabels.flat().forEach((label, i) => {
63
- if (!SeriesLabelColorMap.has(label)) {
64
- const color = seriesColorPredicate(accIndex, chartParams)
65
- SeriesLabelColorMap.set(label, color)
66
- accIndex ++
67
- }
68
- })
69
-
70
- // 計算每個grid的資料
71
- multiGridData = transposedDataGridList.map((gridData, gridIndex) => {
72
- const gridSeriesLabels = multiGridSeriesLabels[gridIndex]
73
- const groupLabels = createMultiGridGroupLabels({
74
- transposedDataGrid: gridData,
75
- dataFormatterGrid: gridDataFormatterList[gridIndex],
76
- chartType: 'multiGrid',
77
- gridIndex
78
- })
79
-
80
- let _index = 0
81
- let computedDataGrid: ComputedDatumGrid[][] = gridData.map((seriesData, seriesIndex) => {
82
- return seriesData.map((groupDatum, groupIndex) => {
83
-
84
- const defaultId = createDefaultDatumId('multiGrid', gridIndex, seriesIndex, groupIndex)
85
- const groupLabel = groupLabels[groupIndex]
86
- const seriesLabel = gridSeriesLabels[seriesIndex]
87
-
88
- const computedDatum: ComputedDatumGrid = {
89
- id: groupDatum.id ? groupDatum.id : defaultId,
90
- index: _index,
91
- label: groupDatum.label ? groupDatum.label : defaultId,
92
- description: groupDatum.description ?? '',
93
- data: groupDatum.data,
94
- value: groupDatum.value,
95
- gridIndex,
96
- // accSeriesIndex: seriesIndex, // 預設為seriesIndex
97
- seriesIndex,
98
- seriesLabel,
99
- groupIndex,
100
- groupLabel,
101
- color: SeriesLabelColorMap.get(seriesLabel),
102
- visible: true // 先給一個預設值
103
- }
104
-
105
- computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
106
-
107
- _index ++
108
-
109
- return computedDatum
110
- })
111
- })
112
-
113
- return computedDataGrid
114
- })
115
-
116
-
117
- } catch (e) {
118
- // console.error(e)
119
- throw Error(e)
120
- }
121
-
122
- return multiGridData
123
- }
1
+ import type { ComputedDataFn, ComputedDatumGrid, DataFormatterGridGrid, ComputedDataMultiGrid } from '../../lib/core-types'
2
+ import { DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID } from '../defaults'
3
+ import {
4
+ createDefaultDatumId,
5
+ seriesColorPredicate,
6
+ createGridSeriesLabels,
7
+ createMultiGridSeriesLabels,
8
+ createMultiGridGroupLabels
9
+ } from '../utils/orbchartsUtils'
10
+ import { createTransposedDataGrid } from '../grid/computedDataFn'
11
+
12
+ export const computedDataFn: ComputedDataFn<'multiGrid'> = (context) => {
13
+ const { data = [], dataFormatter, chartParams } = context
14
+ if (!data.length) {
15
+ return []
16
+ }
17
+
18
+ let multiGridData: ComputedDataMultiGrid = []
19
+
20
+ try {
21
+ const defaultGrid = dataFormatter.gridList[0] || DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID
22
+
23
+ // 計算每個grid的dataFormatter
24
+ const gridDataFormatterList: DataFormatterGridGrid[] = data.map((gridData, gridIndex) => {
25
+ return dataFormatter.gridList[gridIndex] || defaultGrid
26
+ })
27
+
28
+ const transposedDataGridList = data.map((gridData, gridIndex) => {
29
+ // 依seriesDirection轉置資料矩陣
30
+ return createTransposedDataGrid(gridData, gridDataFormatterList[gridIndex])
31
+ })
32
+
33
+ // const isOverlappingMultiGrid = (() => {
34
+ // const SlotIndexSet = new Set(gridDataFormatterList.map(d => d.slotIndex))
35
+ // // 判斷是否有重疊的grid
36
+ // return SlotIndexSet.size !== gridDataFormatterList.length
37
+ // })()
38
+
39
+ const multiGridSeriesLabels = dataFormatter.separateGrid
40
+ // grid分開的時候,預設每組的seriesLabels相同
41
+ ? transposedDataGridList
42
+ .map((gridData, gridIndex) => {
43
+ return createGridSeriesLabels({
44
+ transposedDataGrid: gridData,
45
+ dataFormatterGrid: gridDataFormatterList[gridIndex],
46
+ chartType: 'multiGrid',
47
+ })
48
+ })
49
+ // grid不分開的時候,預設每個grid相同seriesIndex的seriesLabel相同
50
+ : transposedDataGridList
51
+ .map((gridData, gridIndex) => {
52
+ return createMultiGridSeriesLabels({
53
+ transposedDataGrid: gridData,
54
+ dataFormatterGrid: gridDataFormatterList[gridIndex],
55
+ chartType: 'multiGrid',
56
+ gridIndex
57
+ })
58
+ })
59
+
60
+ const SeriesLabelColorMap: Map<string, string> = new Map()
61
+ let accIndex = 0
62
+ multiGridSeriesLabels.flat().forEach((label, i) => {
63
+ if (!SeriesLabelColorMap.has(label)) {
64
+ const color = seriesColorPredicate(accIndex, chartParams)
65
+ SeriesLabelColorMap.set(label, color)
66
+ accIndex ++
67
+ }
68
+ })
69
+
70
+ // 計算每個grid的資料
71
+ multiGridData = transposedDataGridList.map((gridData, gridIndex) => {
72
+ const gridSeriesLabels = multiGridSeriesLabels[gridIndex]
73
+ const groupLabels = createMultiGridGroupLabels({
74
+ transposedDataGrid: gridData,
75
+ dataFormatterGrid: gridDataFormatterList[gridIndex],
76
+ chartType: 'multiGrid',
77
+ gridIndex
78
+ })
79
+
80
+ let _index = 0
81
+ let computedDataGrid: ComputedDatumGrid[][] = gridData.map((seriesData, seriesIndex) => {
82
+ return seriesData.map((groupDatum, groupIndex) => {
83
+
84
+ const defaultId = createDefaultDatumId('multiGrid', gridIndex, seriesIndex, groupIndex)
85
+ const groupLabel = groupLabels[groupIndex]
86
+ const seriesLabel = gridSeriesLabels[seriesIndex]
87
+
88
+ const computedDatum: ComputedDatumGrid = {
89
+ id: groupDatum.id ? groupDatum.id : defaultId,
90
+ index: _index,
91
+ label: groupDatum.label ? groupDatum.label : defaultId,
92
+ description: groupDatum.description ?? '',
93
+ data: groupDatum.data,
94
+ value: groupDatum.value,
95
+ gridIndex,
96
+ // accSeriesIndex: seriesIndex, // 預設為seriesIndex
97
+ seriesIndex,
98
+ seriesLabel,
99
+ groupIndex,
100
+ groupLabel,
101
+ color: SeriesLabelColorMap.get(seriesLabel),
102
+ visible: true // 先給一個預設值
103
+ }
104
+
105
+ computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
106
+
107
+ _index ++
108
+
109
+ return computedDatum
110
+ })
111
+ })
112
+
113
+ return computedDataGrid
114
+ })
115
+
116
+
117
+ } catch (e) {
118
+ // console.error(e)
119
+ throw Error(e)
120
+ }
121
+
122
+ return multiGridData
123
+ }
@@ -1,41 +1,72 @@
1
- import {
2
- map,
3
- shareReplay } from 'rxjs'
4
- import type { ContextObserverCallback } from '../../lib/core-types'
5
- import { multiGridEachDetailObservable, multiGridContainerObservable } from '../utils/multiGridObservables'
6
- import { textSizePxObservable } from '../utils/observables'
7
-
8
- export const contextObserverCallback: ContextObserverCallback<'multiGrid'> = ({ subject, observer }) => {
9
-
10
- const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
11
- shareReplay(1)
12
- )
13
-
14
- const multiGridEachDetail$ = multiGridEachDetailObservable({
15
- fullDataFormatter$: observer.fullDataFormatter$,
16
- computedData$: observer.computedData$,
17
- layout$: observer.layout$,
18
- fullChartParams$: observer.fullChartParams$,
19
- event$: subject.event$
20
- }).pipe(
21
- shareReplay(1)
22
- )
23
-
24
- const multiGridContainerPosition$ = multiGridContainerObservable({
25
- computedData$: observer.computedData$,
26
- fullDataFormatter$: observer.fullDataFormatter$,
27
- layout$: observer.layout$,
28
- })
29
-
30
- return {
31
- fullParams$: observer.fullParams$,
32
- fullChartParams$: observer.fullChartParams$,
33
- fullDataFormatter$: observer.fullDataFormatter$,
34
- computedData$: observer.computedData$,
35
- layout$: observer.layout$,
36
- textSizePx$,
37
- multiGridContainerPosition$,
38
- multiGridEachDetail$,
39
- // multiGridContainer$
40
- }
41
- }
1
+ import {
2
+ map,
3
+ shareReplay } from 'rxjs'
4
+ import type { ContextObserverCallback, DataGridDatum } from '../../lib/core-types'
5
+ import { multiGridEachDetailObservable, multiGridContainerObservable } from '../utils/multiGridObservables'
6
+ import { textSizePxObservable, containerSizeObservable, highlightObservable } from '../utils/observables'
7
+ // import { createMultiGridSeriesLabels } from '../utils/orbchartsUtils'
8
+ import { combineLatest } from 'rxjs/internal/observable/combineLatest'
9
+
10
+ export const contextObserverCallback: ContextObserverCallback<'multiGrid'> = ({ subject, observer }) => {
11
+
12
+ const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
13
+ shareReplay(1)
14
+ )
15
+
16
+ const multiGridContainerPosition$ = multiGridContainerObservable({
17
+ computedData$: observer.computedData$,
18
+ fullDataFormatter$: observer.fullDataFormatter$,
19
+ layout$: observer.layout$,
20
+ }).pipe(
21
+ shareReplay(1)
22
+ )
23
+
24
+ const containerSize$ = containerSizeObservable({
25
+ layout$: observer.layout$,
26
+ containerPosition$: multiGridContainerPosition$.pipe(
27
+ map(d => d.flat())
28
+ )
29
+ }).pipe(
30
+ shareReplay(1)
31
+ )
32
+
33
+ // highlight全部grid
34
+ const multiGridHighlight$ = highlightObservable({
35
+ datumList$: observer.computedData$.pipe(
36
+ map(d => d.flat().flat()),
37
+ shareReplay(1)
38
+ ),
39
+ fullChartParams$: observer.fullChartParams$,
40
+ event$: subject.event$
41
+ }).pipe(
42
+ shareReplay(1)
43
+ )
44
+
45
+ const multiGridEachDetail$ = multiGridEachDetailObservable({
46
+ fullDataFormatter$: observer.fullDataFormatter$,
47
+ computedData$: observer.computedData$,
48
+ layout$: observer.layout$,
49
+ fullChartParams$: observer.fullChartParams$,
50
+ event$: subject.event$,
51
+ containerSize$
52
+ }).pipe(
53
+ shareReplay(1)
54
+ )
55
+ // multiGridContainerPosition$.subscribe(d => {
56
+ // console.log('multiGridContainerPosition$', d)
57
+ // })
58
+
59
+ return {
60
+ fullParams$: observer.fullParams$,
61
+ fullChartParams$: observer.fullChartParams$,
62
+ fullDataFormatter$: observer.fullDataFormatter$,
63
+ computedData$: observer.computedData$,
64
+ layout$: observer.layout$,
65
+ textSizePx$,
66
+ containerSize$,
67
+ multiGridHighlight$,
68
+ multiGridContainerPosition$,
69
+ multiGridEachDetail$,
70
+ // multiGridContainer$
71
+ }
72
+ }