@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
@@ -1,179 +1,176 @@
1
- import type { DataMultiValue, DataMultiValueDatum } from '../types/DataMultiValue'
2
- import type { DataFormatterContext } from '../types/DataFormatter'
3
- import type { ComputedDataFn } from '../types/ComputedData'
4
- import type { ComputedDataMultiValue, ComputedDatumMultiValue } from '../types/ComputedDataMultiValue'
5
- import { formatValueToLabel, createDefaultDatumId } from '../utils/orbchartsUtils'
6
- import { createAxisLinearScale, createAxisPointScale } from '../utils/d3Utils'
7
- import { getMinAndMaxValue } from '../utils/orbchartsUtils'
8
-
9
- export const computeMultiValueData: ComputedDataFn<'multiValue'> = (context) => {
10
- const { data, dataFormatter, chartParams } = context
11
- if (!data.length) {
12
- return []
13
- }
14
-
15
- // @Q@ 假資料待改寫
16
- const layout = {
17
- width: 1000,
18
- height: 1000
19
- }
20
-
21
- let computedDataMultiValue: ComputedDatumMultiValue[][] = []
22
-
23
- try {
24
- const dataMultiValue: DataMultiValueDatum[][] = data.map((d, i) => {
25
- return d.map((_d, _i) => {
26
- const datum: DataMultiValueDatum = typeof _d === 'number'
27
- ? {
28
- id: '',
29
- label: '',
30
- description: '',
31
- // tooltipContent: '',
32
- data: {},
33
- categoryLabel: '',
34
- value: _d
35
- }
36
- : {
37
- id: _d.id ?? '',
38
- label: _d.label ?? '',
39
- description: _d.description ?? '',
40
- // tooltipContent: _d.tooltipContent ?? '',
41
- data: _d.data ?? {},
42
- categoryLabel: _d.categoryLabel ??'',
43
- value: _d.value
44
- }
45
-
46
- return datum
47
- })
48
- })
49
-
50
- // x軸資料最小及最大值(第二維陣列中的第1筆為x軸資料)
51
- const [xMinValue, xMaxValue] = getMinAndMaxValue(dataMultiValue.map(d => d[0]))
52
- // y軸資料最小及最大值(第二維陣列中的第2筆為y軸資料)
53
- const [yMinValue, yMaxValue] = getMinAndMaxValue(dataMultiValue.map(d => d[1]))
54
-
55
- // const axisWidth = layout.width - dataFormatter.padding.left - dataFormatter.padding.right
56
- // const axisHeight = layout.height - dataFormatter.padding.top - dataFormatter.padding.bottom
57
- // const axisWidth = layout.width
58
- // const axisHeight = layout.height
59
- const xAxisWidth = (dataFormatter.xAxis.position === 'top' || dataFormatter.xAxis.position === 'bottom')
60
- ? layout.width
61
- : layout.height
62
- const yAxisWidth = (dataFormatter.yAxis.position === 'left' || dataFormatter.yAxis.position === 'right')
63
- ? layout.height
64
- : layout.width
65
-
66
- const xScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
67
- maxValue: xMaxValue,
68
- minValue: xMinValue,
69
- axisWidth: xAxisWidth,
70
- // scaleDomain: dataFormatter.xAxis.scaleDomain,
71
- // scaleRange: dataFormatter.xAxis.scaleRange
72
- scaleDomain: [xMinValue, xMaxValue],
73
- scaleRange: [0, 1]
74
- })
75
- const yScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
76
- maxValue: yMaxValue,
77
- minValue: yMinValue,
78
- axisWidth: yAxisWidth,
79
- // scaleDomain: dataFormatter.yAxis.scaleDomain,
80
- // scaleRange: dataFormatter.yAxis.scaleRange
81
- scaleDomain: [yMinValue, yMaxValue],
82
- scaleRange: [0, 1]
83
- })
84
-
85
- const _xScaleDoamin: [number, number] = [
86
- // dataFormatter.xAxis.scaleDomain[0] === 'auto' ? xMinValue : dataFormatter.xAxis.scaleDomain[0],
87
- (() => {
88
- if (dataFormatter.xAxis.scaleDomain[0] === 'auto') {
89
- return xMinValue < 0 ? xMinValue : 0
90
- } else if (dataFormatter.xAxis.scaleDomain[0] === 'min') {
91
- return xMinValue
92
- } else {
93
- return dataFormatter.xAxis.scaleDomain[0]
94
- }
95
- })(),
96
- // dataFormatter.xAxis.scaleDomain[1] === 'auto' ? xMaxValue : dataFormatter.xAxis.scaleDomain[1]
97
- (() => {
98
- if (dataFormatter.xAxis.scaleDomain[1] === 'auto') {
99
- return xMaxValue >= 0 ? xMaxValue : 0
100
- } else if (dataFormatter.xAxis.scaleDomain[1] === 'max') {
101
- return xMaxValue
102
- } else {
103
- return dataFormatter.xAxis.scaleDomain[1]
104
- }
105
- })()
106
- ]
107
- const _yScaleDoamin: [number, number] = [
108
- // dataFormatter.yAxis.scaleDomain[0] === 'auto' ? yMinValue : dataFormatter.yAxis.scaleDomain[0],
109
- (() => {
110
- if (dataFormatter.yAxis.scaleDomain[0] === 'auto') {
111
- return xMinValue < 0 ? xMinValue : 0
112
- } else if (dataFormatter.yAxis.scaleDomain[0] === 'min') {
113
- return xMinValue
114
- } else {
115
- return dataFormatter.yAxis.scaleDomain[0]
116
- }
117
- })(),
118
- // dataFormatter.yAxis.scaleDomain[1] === 'auto' ? yMaxValue : dataFormatter.yAxis.scaleDomain[1]
119
- (() => {
120
- if (dataFormatter.yAxis.scaleDomain[1] === 'auto') {
121
- return xMaxValue >= 0 ? xMaxValue : 0
122
- } else if (dataFormatter.yAxis.scaleDomain[1] === 'max') {
123
- return xMaxValue
124
- } else {
125
- return dataFormatter.yAxis.scaleDomain[1]
126
- }
127
- })()
128
- ]
129
-
130
- // // 篩選顯示狀態
131
- // const visibleFilter = (datum: DataMultiValueDatum, rowIndex: number, columnIndex: number, context: DataFormatterContext<"multiValue">) => {
132
- // // 如果不在scale的範圍內則為false,不再做visibleFilter的判斷
133
- // if (columnIndex === 0 && datum.value != null && ((datum.value as number) < _xScaleDoamin[0] || datum.value > _xScaleDoamin[1])) {
134
- // return false
135
- // }
136
- // if (columnIndex === 1 && datum.value != null && (datum.value < _yScaleDoamin[0] || datum.value > _yScaleDoamin[1])) {
137
- // return false
138
- // }
139
-
140
- // return dataFormatter.visibleFilter(datum, rowIndex, columnIndex, context)
141
- // }
142
-
143
- let index = 0
144
-
145
- computedDataMultiValue = dataMultiValue.map((d, i) => {
146
- return d.map((_d, _i) => {
147
- const currentIndex = index
148
- index++
149
-
150
- const defaultId = createDefaultDatumId(dataFormatter.type, i, _i)
151
-
152
- const computedDatum: ComputedDatumMultiValue = {
153
- id: _d.id ? _d.id : defaultId,
154
- index: currentIndex,
155
- label: _d.label ? _d.label : defaultId,
156
- description: _d.description ?? '',
157
- // tooltipContent: _d.tooltipContent ? _d.tooltipContent : dataFormatter.tooltipContentFormat(_d, i, _i, context),
158
- data: _d.data,
159
- value: _d.value,
160
- categoryIndex: 0, // @Q@ 未完成
161
- categoryLabel: '', // @Q@ 未完成
162
- // valueLabel: formatValueToLabel(_d.value, dataFormatter.multiValue[_i].valueFormat),
163
- axis: _i == 0 ? xScale(_d.value) : yScale(_d.value),
164
- visible: true, // 先給預設值
165
- color: '' // @Q@ 未完成
166
- }
167
-
168
- computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
169
-
170
- return computedDatum
171
- })
172
- })
173
- } catch (e) {
174
- // console.error(e)
175
- throw Error(e)
176
- }
177
-
178
- return computedDataMultiValue
179
- }
1
+ import type { DataMultiValueDatum, ComputedDataFn, ComputedDatumMultiValue } from '../../lib/core-types'
2
+ import { formatValueToLabel, createDefaultDatumId } from '../utils/orbchartsUtils'
3
+ import { createAxisLinearScale, createAxisPointScale } from '../utils/d3Utils'
4
+ import { getMinAndMaxValue } from '../utils/orbchartsUtils'
5
+
6
+ export const computedDataFn: ComputedDataFn<'multiValue'> = (context) => {
7
+ const { data, dataFormatter, chartParams } = context
8
+ if (!data.length) {
9
+ return []
10
+ }
11
+
12
+ // @Q@ 假資料待改寫
13
+ const layout = {
14
+ width: 1000,
15
+ height: 1000
16
+ }
17
+
18
+ let computedDataMultiValue: ComputedDatumMultiValue[][] = []
19
+
20
+ try {
21
+ const dataMultiValue: DataMultiValueDatum[][] = data.map((d, i) => {
22
+ return d.map((_d, _i) => {
23
+ const datum: DataMultiValueDatum = typeof _d === 'number'
24
+ ? {
25
+ id: '',
26
+ label: '',
27
+ description: '',
28
+ // tooltipContent: '',
29
+ data: {},
30
+ categoryLabel: '',
31
+ value: _d
32
+ }
33
+ : {
34
+ id: _d.id ?? '',
35
+ label: _d.label ?? '',
36
+ description: _d.description ?? '',
37
+ // tooltipContent: _d.tooltipContent ?? '',
38
+ data: _d.data ?? {},
39
+ categoryLabel: _d.categoryLabel ??'',
40
+ value: _d.value
41
+ }
42
+
43
+ return datum
44
+ })
45
+ })
46
+
47
+ // x軸資料最小及最大值(第二維陣列中的第1筆為x軸資料)
48
+ const [xMinValue, xMaxValue] = getMinAndMaxValue(dataMultiValue.map(d => d[0]))
49
+ // y軸資料最小及最大值(第二維陣列中的第2筆為y軸資料)
50
+ const [yMinValue, yMaxValue] = getMinAndMaxValue(dataMultiValue.map(d => d[1]))
51
+
52
+ // const axisWidth = layout.width - dataFormatter.padding.left - dataFormatter.padding.right
53
+ // const axisHeight = layout.height - dataFormatter.padding.top - dataFormatter.padding.bottom
54
+ // const axisWidth = layout.width
55
+ // const axisHeight = layout.height
56
+ const xAxisWidth = (dataFormatter.xAxis.position === 'top' || dataFormatter.xAxis.position === 'bottom')
57
+ ? layout.width
58
+ : layout.height
59
+ const yAxisWidth = (dataFormatter.yAxis.position === 'left' || dataFormatter.yAxis.position === 'right')
60
+ ? layout.height
61
+ : layout.width
62
+
63
+ const xScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
64
+ maxValue: xMaxValue,
65
+ minValue: xMinValue,
66
+ axisWidth: xAxisWidth,
67
+ // scaleDomain: dataFormatter.xAxis.scaleDomain,
68
+ // scaleRange: dataFormatter.xAxis.scaleRange
69
+ scaleDomain: [xMinValue, xMaxValue],
70
+ scaleRange: [0, 1]
71
+ })
72
+ const yScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
73
+ maxValue: yMaxValue,
74
+ minValue: yMinValue,
75
+ axisWidth: yAxisWidth,
76
+ // scaleDomain: dataFormatter.yAxis.scaleDomain,
77
+ // scaleRange: dataFormatter.yAxis.scaleRange
78
+ scaleDomain: [yMinValue, yMaxValue],
79
+ scaleRange: [0, 1]
80
+ })
81
+
82
+ const _xScaleDoamin: [number, number] = [
83
+ // dataFormatter.xAxis.scaleDomain[0] === 'auto' ? xMinValue : dataFormatter.xAxis.scaleDomain[0],
84
+ (() => {
85
+ if (dataFormatter.xAxis.scaleDomain[0] === 'auto') {
86
+ return xMinValue < 0 ? xMinValue : 0
87
+ } else if (dataFormatter.xAxis.scaleDomain[0] === 'min') {
88
+ return xMinValue
89
+ } else {
90
+ return dataFormatter.xAxis.scaleDomain[0]
91
+ }
92
+ })(),
93
+ // dataFormatter.xAxis.scaleDomain[1] === 'auto' ? xMaxValue : dataFormatter.xAxis.scaleDomain[1]
94
+ (() => {
95
+ if (dataFormatter.xAxis.scaleDomain[1] === 'auto') {
96
+ return xMaxValue >= 0 ? xMaxValue : 0
97
+ } else if (dataFormatter.xAxis.scaleDomain[1] === 'max') {
98
+ return xMaxValue
99
+ } else {
100
+ return dataFormatter.xAxis.scaleDomain[1]
101
+ }
102
+ })()
103
+ ]
104
+ const _yScaleDoamin: [number, number] = [
105
+ // dataFormatter.yAxis.scaleDomain[0] === 'auto' ? yMinValue : dataFormatter.yAxis.scaleDomain[0],
106
+ (() => {
107
+ if (dataFormatter.yAxis.scaleDomain[0] === 'auto') {
108
+ return xMinValue < 0 ? xMinValue : 0
109
+ } else if (dataFormatter.yAxis.scaleDomain[0] === 'min') {
110
+ return xMinValue
111
+ } else {
112
+ return dataFormatter.yAxis.scaleDomain[0]
113
+ }
114
+ })(),
115
+ // dataFormatter.yAxis.scaleDomain[1] === 'auto' ? yMaxValue : dataFormatter.yAxis.scaleDomain[1]
116
+ (() => {
117
+ if (dataFormatter.yAxis.scaleDomain[1] === 'auto') {
118
+ return xMaxValue >= 0 ? xMaxValue : 0
119
+ } else if (dataFormatter.yAxis.scaleDomain[1] === 'max') {
120
+ return xMaxValue
121
+ } else {
122
+ return dataFormatter.yAxis.scaleDomain[1]
123
+ }
124
+ })()
125
+ ]
126
+
127
+ // // 篩選顯示狀態
128
+ // const visibleFilter = (datum: DataMultiValueDatum, rowIndex: number, columnIndex: number, context: DataFormatterContext<"multiValue">) => {
129
+ // // 如果不在scale的範圍內則為false,不再做visibleFilter的判斷
130
+ // if (columnIndex === 0 && datum.value != null && ((datum.value as number) < _xScaleDoamin[0] || datum.value > _xScaleDoamin[1])) {
131
+ // return false
132
+ // }
133
+ // if (columnIndex === 1 && datum.value != null && (datum.value < _yScaleDoamin[0] || datum.value > _yScaleDoamin[1])) {
134
+ // return false
135
+ // }
136
+
137
+ // return dataFormatter.visibleFilter(datum, rowIndex, columnIndex, context)
138
+ // }
139
+
140
+ let index = 0
141
+
142
+ computedDataMultiValue = dataMultiValue.map((d, i) => {
143
+ return d.map((_d, _i) => {
144
+ const currentIndex = index
145
+ index++
146
+
147
+ const defaultId = createDefaultDatumId(dataFormatter.type, i, _i)
148
+
149
+ const computedDatum: ComputedDatumMultiValue = {
150
+ id: _d.id ? _d.id : defaultId,
151
+ index: currentIndex,
152
+ label: _d.label ? _d.label : defaultId,
153
+ description: _d.description ?? '',
154
+ // tooltipContent: _d.tooltipContent ? _d.tooltipContent : dataFormatter.tooltipContentFormat(_d, i, _i, context),
155
+ data: _d.data,
156
+ value: _d.value,
157
+ categoryIndex: 0, // @Q@ 未完成
158
+ categoryLabel: '', // @Q@ 未完成
159
+ // valueLabel: formatValueToLabel(_d.value, dataFormatter.multiValue[_i].valueFormat),
160
+ axis: _i == 0 ? xScale(_d.value) : yScale(_d.value),
161
+ visible: true, // 先給預設值
162
+ color: '' // @Q@ 未完成
163
+ }
164
+
165
+ computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
166
+
167
+ return computedDatum
168
+ })
169
+ })
170
+ } catch (e) {
171
+ // console.error(e)
172
+ throw Error(e)
173
+ }
174
+
175
+ return computedDataMultiValue
176
+ }
@@ -1,12 +1,12 @@
1
- import type { ContextObserverFn } from '../types'
2
-
3
- export const createMultiValueContextObserver: ContextObserverFn<'multiValue'> = ({ subject, observer }) => {
4
-
5
- return {
6
- fullParams$: observer.fullParams$,
7
- fullChartParams$: observer.fullChartParams$,
8
- fullDataFormatter$: observer.fullDataFormatter$,
9
- computedData$: observer.computedData$,
10
- layout$: observer.layout$,
11
- }
12
- }
1
+ import type { ContextObserverCallback } from '../../lib/core-types'
2
+
3
+ export const contextObserverCallback: ContextObserverCallback<'multiValue'> = ({ subject, observer }) => {
4
+
5
+ return {
6
+ fullParams$: observer.fullParams$,
7
+ fullChartParams$: observer.fullChartParams$,
8
+ fullDataFormatter$: observer.fullDataFormatter$,
9
+ computedData$: observer.computedData$,
10
+ layout$: observer.layout$,
11
+ }
12
+ }
@@ -0,0 +1,10 @@
1
+ import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
2
+
3
+ export const dataFormatterValidator: DataFormatterValidator<'multiValue'> = (dataFormatter: DataFormatterTypeMap<'multiValue'>) => {
4
+
5
+ return {
6
+ status: 'success',
7
+ columnName: '',
8
+ expectToBe: ''
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
+
3
+ export const dataValidator: DataValidator<'multiValue'> = (data: DataTypeMap<'multiValue'>) => {
4
+
5
+ return {
6
+ status: 'success',
7
+ columnName: '',
8
+ expectToBe: ''
9
+ }
10
+ }