@orbcharts/core 3.0.0-alpha.61 → 3.0.0-alpha.63

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. package/LICENSE +200 -200
  2. package/dist/lib/core-types.d.ts +1 -0
  3. package/dist/orbcharts-core.es.js +3418 -2726
  4. package/dist/orbcharts-core.umd.js +6 -2
  5. package/dist/src/AbstractChart.d.ts +5 -3
  6. package/dist/src/GridChart.d.ts +1 -1
  7. package/dist/src/MultiGridChart.d.ts +1 -1
  8. package/dist/src/MultiValueChart.d.ts +1 -1
  9. package/dist/src/RelationshipChart.d.ts +1 -1
  10. package/dist/src/SeriesChart.d.ts +1 -1
  11. package/dist/src/TreeChart.d.ts +1 -1
  12. package/dist/src/base/createBaseChart.d.ts +1 -1
  13. package/dist/src/base/createBasePlugin.d.ts +1 -1
  14. package/dist/src/base/validators/chartOptionsValidator.d.ts +3 -0
  15. package/dist/src/base/validators/chartParamsValidator.d.ts +3 -0
  16. package/dist/src/base/validators/elementValidator.d.ts +3 -0
  17. package/dist/src/base/validators/pluginsValidator.d.ts +3 -0
  18. package/dist/src/defaults.d.ts +1 -16
  19. package/dist/src/defineGridPlugin.d.ts +1 -1
  20. package/dist/src/defineMultiGridPlugin.d.ts +1 -1
  21. package/dist/src/defineMultiValuePlugin.d.ts +1 -1
  22. package/dist/src/defineNoneDataPlugin.d.ts +1 -1
  23. package/dist/src/defineRelationshipPlugin.d.ts +1 -1
  24. package/dist/src/defineSeriesPlugin.d.ts +1 -1
  25. package/dist/src/defineTreePlugin.d.ts +1 -1
  26. package/dist/src/grid/computedDataFn.d.ts +4 -0
  27. package/dist/src/grid/contextObserverCallback.d.ts +3 -0
  28. package/dist/src/grid/dataFormatterValidator.d.ts +3 -0
  29. package/dist/src/grid/dataValidator.d.ts +3 -0
  30. package/dist/src/index.d.ts +1 -1
  31. package/dist/src/multiGrid/computedDataFn.d.ts +3 -0
  32. package/dist/src/multiGrid/contextObserverCallback.d.ts +3 -0
  33. package/dist/src/multiGrid/dataFormatterValidator.d.ts +3 -0
  34. package/dist/src/multiGrid/dataValidator.d.ts +3 -0
  35. package/dist/src/multiValue/computedDataFn.d.ts +3 -0
  36. package/dist/src/multiValue/contextObserverCallback.d.ts +3 -0
  37. package/dist/src/multiValue/dataFormatterValidator.d.ts +3 -0
  38. package/dist/src/multiValue/dataValidator.d.ts +3 -0
  39. package/dist/src/relationship/computedDataFn.d.ts +3 -0
  40. package/dist/src/relationship/contextObserverCallback.d.ts +3 -0
  41. package/dist/src/relationship/dataFormatterValidator.d.ts +3 -0
  42. package/dist/src/relationship/dataValidator.d.ts +3 -0
  43. package/dist/src/series/computedDataFn.d.ts +3 -0
  44. package/dist/src/series/contextObserverCallback.d.ts +3 -0
  45. package/dist/src/series/dataFormatterValidator.d.ts +3 -0
  46. package/dist/src/series/dataValidator.d.ts +3 -0
  47. package/dist/src/tree/computedDataFn.d.ts +3 -0
  48. package/dist/src/tree/contextObserverCallback.d.ts +3 -0
  49. package/dist/src/tree/dataFormatterValidator.d.ts +3 -0
  50. package/dist/src/tree/dataValidator.d.ts +3 -0
  51. package/dist/src/utils/commonUtils.d.ts +1 -0
  52. package/dist/src/utils/errorMessage.d.ts +14 -0
  53. package/dist/src/{grid → utils}/gridObservables.d.ts +2 -2
  54. package/dist/src/utils/index.d.ts +7 -3
  55. package/dist/src/{multiGrid → utils}/multiGridObservables.d.ts +1 -1
  56. package/dist/src/utils/observables.d.ts +2 -1
  57. package/dist/src/utils/orbchartsUtils.d.ts +1 -12
  58. package/dist/src/{series → utils}/seriesObservables.d.ts +3 -3
  59. package/dist/src/{tree → utils}/treeObservables.d.ts +1 -1
  60. package/dist/src/utils/validator.d.ts +3 -0
  61. package/lib/core-types.ts +7 -0
  62. package/package.json +42 -41
  63. package/src/AbstractChart.ts +57 -48
  64. package/src/GridChart.ts +24 -20
  65. package/src/MultiGridChart.ts +24 -20
  66. package/src/MultiValueChart.ts +24 -20
  67. package/src/RelationshipChart.ts +24 -20
  68. package/src/SeriesChart.ts +24 -20
  69. package/src/TreeChart.ts +24 -20
  70. package/src/base/createBaseChart.ts +500 -388
  71. package/src/base/createBasePlugin.ts +152 -95
  72. package/src/base/validators/chartOptionsValidator.ts +24 -0
  73. package/src/base/validators/chartParamsValidator.ts +134 -0
  74. package/src/base/validators/elementValidator.ts +14 -0
  75. package/src/base/validators/pluginsValidator.ts +15 -0
  76. package/src/defaults.ts +232 -228
  77. package/src/defineGridPlugin.ts +3 -3
  78. package/src/defineMultiGridPlugin.ts +3 -3
  79. package/src/defineMultiValuePlugin.ts +3 -3
  80. package/src/defineNoneDataPlugin.ts +4 -4
  81. package/src/defineRelationshipPlugin.ts +3 -3
  82. package/src/defineSeriesPlugin.ts +3 -3
  83. package/src/defineTreePlugin.ts +3 -3
  84. package/src/grid/{computeGridData.ts → computedDataFn.ts} +129 -134
  85. package/src/grid/{createGridContextObserver.ts → contextObserverCallback.ts} +155 -155
  86. package/src/grid/dataFormatterValidator.ts +102 -0
  87. package/src/grid/dataValidator.ts +13 -0
  88. package/src/index.ts +20 -21
  89. package/src/multiGrid/{computeMultiGridData.ts → computedDataFn.ts} +123 -130
  90. package/src/multiGrid/{createMultiGridContextObserver.ts → contextObserverCallback.ts} +41 -41
  91. package/src/multiGrid/dataFormatterValidator.ts +116 -0
  92. package/src/multiGrid/dataValidator.ts +13 -0
  93. package/src/multiValue/{computeMultiValueData.ts → computedDataFn.ts} +176 -179
  94. package/src/multiValue/{createMultiValueContextObserver.ts → contextObserverCallback.ts} +12 -12
  95. package/src/multiValue/dataFormatterValidator.ts +10 -0
  96. package/src/multiValue/dataValidator.ts +10 -0
  97. package/src/relationship/{computeRelationshipData.ts → computedDataFn.ts} +125 -118
  98. package/src/relationship/{createRelationshipContextObserver.ts → contextObserverCallback.ts} +12 -12
  99. package/src/relationship/dataFormatterValidator.ts +10 -0
  100. package/src/relationship/dataValidator.ts +10 -0
  101. package/src/series/{computeSeriesData.ts → computedDataFn.ts} +88 -90
  102. package/src/series/{createSeriesContextObserver.ts → contextObserverCallback.ts} +100 -93
  103. package/src/series/dataFormatterValidator.ts +42 -0
  104. package/src/series/dataValidator.ts +13 -0
  105. package/src/tree/{computeTreeData.ts → computedDataFn.ts} +130 -132
  106. package/src/tree/{createTreeContextObserver.ts → contextObserverCallback.ts} +61 -61
  107. package/src/tree/dataFormatterValidator.ts +14 -0
  108. package/src/tree/dataValidator.ts +14 -0
  109. package/src/utils/commonUtils.ts +54 -50
  110. package/src/utils/d3Utils.ts +108 -108
  111. package/src/utils/errorMessage.ts +43 -0
  112. package/src/{grid → utils}/gridObservables.ts +611 -614
  113. package/src/utils/index.ts +10 -4
  114. package/src/{multiGrid → utils}/multiGridObservables.ts +366 -365
  115. package/src/utils/observables.ts +219 -202
  116. package/src/utils/orbchartsUtils.ts +352 -349
  117. package/src/{series → utils}/seriesObservables.ts +175 -175
  118. package/src/{tree → utils}/treeObservables.ts +94 -94
  119. package/src/utils/validator.ts +126 -0
  120. package/tsconfig.base.json +13 -13
  121. package/tsconfig.json +2 -2
  122. package/vite-env.d.ts +7 -0
  123. package/vite.config.js +22 -22
  124. package/dist/src/grid/computeGridData.d.ts +0 -6
  125. package/dist/src/grid/createGridContextObserver.d.ts +0 -3
  126. package/dist/src/multiGrid/computeMultiGridData.d.ts +0 -3
  127. package/dist/src/multiGrid/createMultiGridContextObserver.d.ts +0 -3
  128. package/dist/src/multiValue/computeMultiValueData.d.ts +0 -3
  129. package/dist/src/multiValue/createMultiValueContextObserver.d.ts +0 -3
  130. package/dist/src/relationship/computeRelationshipData.d.ts +0 -3
  131. package/dist/src/relationship/createRelationshipContextObserver.d.ts +0 -3
  132. package/dist/src/series/computeSeriesData.d.ts +0 -3
  133. package/dist/src/series/createSeriesContextObserver.d.ts +0 -3
  134. package/dist/src/tree/computeTreeData.d.ts +0 -3
  135. package/dist/src/tree/createTreeContextObserver.d.ts +0 -3
  136. package/dist/src/types/Axis.d.ts +0 -1
  137. package/dist/src/types/Chart.d.ts +0 -45
  138. package/dist/src/types/ChartParams.d.ts +0 -36
  139. package/dist/src/types/ComputedData.d.ts +0 -42
  140. package/dist/src/types/ComputedDataGrid.d.ts +0 -5
  141. package/dist/src/types/ComputedDataMultiGrid.d.ts +0 -3
  142. package/dist/src/types/ComputedDataMultiValue.d.ts +0 -6
  143. package/dist/src/types/ComputedDataRelationship.d.ts +0 -18
  144. package/dist/src/types/ComputedDataSeries.d.ts +0 -5
  145. package/dist/src/types/ComputedDataTree.d.ts +0 -7
  146. package/dist/src/types/ContextObserver.d.ts +0 -28
  147. package/dist/src/types/ContextObserverGrid.d.ts +0 -41
  148. package/dist/src/types/ContextObserverMultiGrid.d.ts +0 -15
  149. package/dist/src/types/ContextObserverMultiValue.d.ts +0 -4
  150. package/dist/src/types/ContextObserverRelationship.d.ts +0 -4
  151. package/dist/src/types/ContextObserverSeries.d.ts +0 -27
  152. package/dist/src/types/ContextObserverTree.d.ts +0 -11
  153. package/dist/src/types/ContextSubject.d.ts +0 -15
  154. package/dist/src/types/Data.d.ts +0 -19
  155. package/dist/src/types/DataFormatter.d.ts +0 -41
  156. package/dist/src/types/DataFormatterGrid.d.ts +0 -34
  157. package/dist/src/types/DataFormatterMultiGrid.d.ts +0 -20
  158. package/dist/src/types/DataFormatterMultiValue.d.ts +0 -18
  159. package/dist/src/types/DataFormatterRelationship.d.ts +0 -10
  160. package/dist/src/types/DataFormatterSeries.d.ts +0 -19
  161. package/dist/src/types/DataFormatterTree.d.ts +0 -7
  162. package/dist/src/types/DataGrid.d.ts +0 -6
  163. package/dist/src/types/DataMultiGrid.d.ts +0 -6
  164. package/dist/src/types/DataMultiValue.d.ts +0 -7
  165. package/dist/src/types/DataRelationship.d.ts +0 -21
  166. package/dist/src/types/DataSeries.d.ts +0 -6
  167. package/dist/src/types/DataTree.d.ts +0 -15
  168. package/dist/src/types/Event.d.ts +0 -56
  169. package/dist/src/types/Layout.d.ts +0 -8
  170. package/dist/src/types/Padding.d.ts +0 -6
  171. package/dist/src/types/Plugin.d.ts +0 -37
  172. package/dist/src/types/TransformData.d.ts +0 -8
  173. package/dist/src/types/index.d.ts +0 -37
  174. package/src/types/Axis.ts +0 -1
  175. package/src/types/Chart.ts +0 -54
  176. package/src/types/ChartParams.ts +0 -51
  177. package/src/types/ComputedData.ts +0 -84
  178. package/src/types/ComputedDataGrid.ts +0 -14
  179. package/src/types/ComputedDataMultiGrid.ts +0 -3
  180. package/src/types/ComputedDataMultiValue.ts +0 -9
  181. package/src/types/ComputedDataRelationship.ts +0 -20
  182. package/src/types/ComputedDataSeries.ts +0 -8
  183. package/src/types/ComputedDataTree.ts +0 -20
  184. package/src/types/ContextObserver.ts +0 -38
  185. package/src/types/ContextObserverGrid.ts +0 -43
  186. package/src/types/ContextObserverMultiGrid.ts +0 -17
  187. package/src/types/ContextObserverMultiValue.ts +0 -5
  188. package/src/types/ContextObserverRelationship.ts +0 -5
  189. package/src/types/ContextObserverSeries.ts +0 -29
  190. package/src/types/ContextObserverTree.ts +0 -11
  191. package/src/types/ContextSubject.ts +0 -18
  192. package/src/types/Data.ts +0 -45
  193. package/src/types/DataFormatter.ts +0 -74
  194. package/src/types/DataFormatterGrid.ts +0 -68
  195. package/src/types/DataFormatterMultiGrid.ts +0 -45
  196. package/src/types/DataFormatterMultiValue.ts +0 -24
  197. package/src/types/DataFormatterRelationship.ts +0 -26
  198. package/src/types/DataFormatterSeries.ts +0 -20
  199. package/src/types/DataFormatterTree.ts +0 -12
  200. package/src/types/DataGrid.ts +0 -11
  201. package/src/types/DataMultiGrid.ts +0 -7
  202. package/src/types/DataMultiValue.ts +0 -12
  203. package/src/types/DataRelationship.ts +0 -28
  204. package/src/types/DataSeries.ts +0 -11
  205. package/src/types/DataTree.ts +0 -20
  206. package/src/types/Event.ts +0 -153
  207. package/src/types/Layout.ts +0 -12
  208. package/src/types/Padding.ts +0 -6
  209. package/src/types/Plugin.ts +0 -60
  210. package/src/types/TransformData.ts +0 -8
  211. package/src/types/index.ts +0 -37
  212. /package/dist/src/{multiValue → utils}/multiValueObservables.d.ts +0 -0
  213. /package/dist/src/{relationship → utils}/relationshipObservables.d.ts +0 -0
  214. /package/src/{multiValue → utils}/multiValueObservables.ts +0 -0
  215. /package/src/{relationship → utils}/relationshipObservables.ts +0 -0
@@ -0,0 +1,102 @@
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.grid, {
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.grid.valueAxis) {
42
+ const valueAxisResult = validateColumns(dataFormatter.grid.valueAxis, {
43
+ position: {
44
+ toBe: '"left" | "right"',
45
+ test: (value) => value === 'left' || 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.grid.groupAxis) {
64
+ const groupAxisResult = validateColumns(dataFormatter.grid.groupAxis, {
65
+ position: {
66
+ toBe: '"top" | "bottom"',
67
+ test: (value) => value === 'top' || value === 'bottom'
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
102
+ }
@@ -0,0 +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
13
+ }
package/src/index.ts CHANGED
@@ -1,21 +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 './types'
18
- export * from './utils'
19
-
20
-
21
-
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,130 +1,123 @@
1
- import type { DataGrid, DataGridDatum } from '../types/DataGrid'
2
- import type { ComputedDataFn } from '../types/ComputedData'
3
- import type { ComputedDatumGrid } from '../types/ComputedDataGrid'
4
- import type { DataFormatterContext } from '../types/DataFormatter'
5
- import type { DataFormatterGridGrid } from '../types/DataFormatterGrid'
6
- import type { ComputedDataMultiGrid } from '../types/ComputedDataMultiGrid'
7
- // import { computeBaseGridData } from '../grid/computeGridData'
8
- import { DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT } from '../defaults'
9
- import {
10
- createDefaultDatumId,
11
- seriesColorPredicate,
12
- createGridSeriesLabels,
13
- createMultiGridSeriesLabels,
14
- createMultiGridGroupLabels
15
- } from '../utils/orbchartsUtils'
16
- // import type { DataGridDatumTemp } from '../grid/computeGridData'
17
- import { createTransposedDataGrid } from '../grid/computeGridData'
18
-
19
- export const computeMultiGridData: ComputedDataFn<'multiGrid'> = (context) => {
20
- const { data = [], dataFormatter, chartParams } = context
21
- if (!data.length) {
22
- return []
23
- }
24
-
25
- let multiGridData: ComputedDataMultiGrid = []
26
-
27
- try {
28
- const defaultGrid = dataFormatter.gridList[0] || DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT
29
-
30
- // 計算每個grid的dataFormatter
31
- const gridDataFormatterList: DataFormatterGridGrid[] = data.map((gridData, gridIndex) => {
32
- return dataFormatter.gridList[gridIndex] || defaultGrid
33
- })
34
-
35
- const transposedDataGridList = data.map((gridData, gridIndex) => {
36
- // 依seriesDirection轉置資料矩陣
37
- return createTransposedDataGrid(gridData, gridDataFormatterList[gridIndex])
38
- })
39
-
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
- })
66
-
67
- const SeriesLabelColorMap: Map<string, string> = new Map()
68
- let accIndex = 0
69
- multiGridSeriesLabels.flat().forEach((label, i) => {
70
- if (!SeriesLabelColorMap.has(label)) {
71
- const color = seriesColorPredicate(accIndex, chartParams)
72
- SeriesLabelColorMap.set(label, color)
73
- accIndex ++
74
- }
75
- })
76
-
77
- // 計算每個grid的資料
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
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
121
- })
122
-
123
-
124
- } catch (e) {
125
- // console.error(e)
126
- throw Error(e)
127
- }
128
-
129
- return multiGridData
130
- }
1
+ import type { ComputedDataFn, ComputedDatumGrid, DataFormatterGridGrid, ComputedDataMultiGrid } from '../../lib/core-types'
2
+ import { DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT } 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] || DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT
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,41 @@
1
- import {
2
- map,
3
- shareReplay } from 'rxjs'
4
- import type { ContextObserverFn } from '../types'
5
- import { multiGridEachDetailObservable, multiGridContainerObservable } from './multiGridObservables'
6
- import { textSizePxObservable } from '../utils/observables'
7
-
8
- export const createMultiGridContextObserver: ContextObserverFn<'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 } 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
+ }
@@ -0,0 +1,116 @@
1
+ import type { DataFormatterValidator, DataFormatterTypeMap, ValidatorResult } from '../../lib/core-types'
2
+ import { validateColumns } from '../utils/validator'
3
+
4
+ export const dataFormatterValidator: DataFormatterValidator<'multiGrid'> = (dataFormatter: DataFormatterTypeMap<'multiGrid'>) => {
5
+ const result = validateColumns(dataFormatter, {
6
+ visibleFilter: {
7
+ toBeTypes: ['Function']
8
+ },
9
+ gridList: {
10
+ toBeTypes: ['object[]']
11
+ },
12
+ container: {
13
+ toBeTypes: ['object']
14
+ },
15
+ separateGrid: {
16
+ toBeTypes: ['boolean']
17
+ }
18
+ })
19
+ if (dataFormatter.gridList) {
20
+ const gridListResultArr = dataFormatter.gridList.map((grid, index) => {
21
+ const gridResult = validateColumns(grid, {
22
+ seriesDirection: {
23
+ toBe: '"row" | "column"',
24
+ test: (value) => value === 'row' || value === 'column'
25
+ },
26
+ rowLabels: {
27
+ toBeTypes: ['string[]']
28
+ },
29
+ columnLabels: {
30
+ toBeTypes: ['string[]']
31
+ },
32
+ valueAxis: {
33
+ toBeTypes: ['object']
34
+ },
35
+ groupAxis: {
36
+ toBeTypes: ['object']
37
+ },
38
+ separateSeries: {
39
+ toBeTypes: ['boolean']
40
+ }
41
+ })
42
+ if (gridResult.status === 'error') {
43
+ return gridResult
44
+ } else {
45
+ if (grid.valueAxis) {
46
+ const valueAxisResult = validateColumns(grid.valueAxis, {
47
+ position: {
48
+ toBe: '"top" | "bottom" | "left" | "right"',
49
+ test: (value) => value === 'top' || value === 'bottom' || value === 'left' || value === 'right'
50
+ },
51
+ scaleDomain: {
52
+ toBe: '[number | "min" | "auto", number | "max" | "auto"]',
53
+ 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')
54
+ },
55
+ scaleRange: {
56
+ toBe: '[number, number]',
57
+ test: (value) => Array.isArray(value) && value.length === 2 && typeof value[0] === 'number' && typeof value[1] === 'number'
58
+ },
59
+ label: {
60
+ toBeTypes: ['string']
61
+ }
62
+ })
63
+ if (valueAxisResult.status === 'error') {
64
+ return valueAxisResult
65
+ }
66
+ } else if (grid.groupAxis) {
67
+ const groupAxisResult = validateColumns(grid.groupAxis, {
68
+ position: {
69
+ toBe: '"top" | "bottom" | "left" | "right"',
70
+ test: (value) => value === 'top' || value === 'bottom' || value === 'left' || value === 'right'
71
+ },
72
+ scaleDomain: {
73
+ toBe: '[number, number | "max"]',
74
+ test: (value) => Array.isArray(value) && value.length === 2 && typeof value[0] === 'number' && (typeof value[1] === 'number' || value[1] === 'max')
75
+ },
76
+ scalePadding: {
77
+ toBeTypes: ['number']
78
+ },
79
+ label: {
80
+ toBeTypes: ['string']
81
+ }
82
+ })
83
+ if (groupAxisResult.status === 'error') {
84
+ return groupAxisResult
85
+ }
86
+ }
87
+ return <ValidatorResult>{
88
+ status: 'success',
89
+ columnName: '',
90
+ expectToBe: ''
91
+ }
92
+ }
93
+ })
94
+ const gridListResult = gridListResultArr.find((gridResult) => gridResult.status === 'error')
95
+ if (gridListResult.status === 'error') {
96
+ return gridListResult
97
+ }
98
+ }
99
+ if (dataFormatter.container) {
100
+ const containerResult = validateColumns(dataFormatter.container, {
101
+ gap: {
102
+ toBeTypes: ['number']
103
+ },
104
+ rowAmount: {
105
+ toBeTypes: ['number']
106
+ },
107
+ columnAmount: {
108
+ toBeTypes: ['number']
109
+ }
110
+ })
111
+ if (containerResult.status === 'error') {
112
+ return containerResult
113
+ }
114
+ }
115
+ return result
116
+ }
@@ -0,0 +1,13 @@
1
+ import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
+ import { validateColumns } from '../utils/validator'
3
+
4
+ export const dataValidator: DataValidator<'multiGrid'> = (data: DataTypeMap<'multiGrid'>) => {
5
+ const result = validateColumns({ data }, {
6
+ data: {
7
+ toBe: 'DataGrid[]',
8
+ // 畢免資料量過大檢查不完,不深度檢查
9
+ test: (value) => Array.isArray(value)
10
+ }
11
+ })
12
+ return result
13
+ }