@orbcharts/core 3.0.7 → 4.0.0-pre-alpha.1

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 (196) hide show
  1. package/dist/orbcharts-core.es.js +2795 -6591
  2. package/dist/orbcharts-core.umd.js +6 -6
  3. package/dist/src/OrbCharts.d.ts +18 -0
  4. package/dist/src/chart/createChart.d.ts +3 -0
  5. package/dist/src/chart/createGraphData.d.ts +3 -0
  6. package/dist/src/chart/createGridData.d.ts +3 -0
  7. package/dist/src/chart/createMultivariateData.d.ts +3 -0
  8. package/dist/src/chart/createSeriesData.d.ts +3 -0
  9. package/dist/src/chart/createTreeData.d.ts +3 -0
  10. package/dist/src/chart/defaults.d.ts +5 -0
  11. package/dist/src/defineCanvasLayer.d.ts +16 -0
  12. package/dist/src/defineCanvasPlugin.d.ts +22 -0
  13. package/dist/src/defineSVGLayer.d.ts +16 -0
  14. package/dist/src/defineSVGPlugin.d.ts +22 -0
  15. package/dist/src/index.d.ts +6 -14
  16. package/dist/src/layer/createLayer.d.ts +3 -0
  17. package/dist/src/plugin/createPlugin.d.ts +3 -0
  18. package/dist/src/test/createGraphData.test.d.ts +1 -0
  19. package/dist/src/test/createTreeData.test.d.ts +1 -0
  20. package/dist/src/test/simple-graph-test.d.ts +74 -0
  21. package/dist/src/test/simple-tree-test.d.ts +13 -0
  22. package/dist/src/types/Chart.d.ts +39 -0
  23. package/dist/src/types/ChartContext.d.ts +27 -0
  24. package/dist/src/types/Common.d.ts +3 -0
  25. package/dist/src/types/Encoding.d.ts +33 -0
  26. package/dist/src/types/Event.d.ts +12 -0
  27. package/dist/src/types/Layers.d.ts +55 -0
  28. package/dist/src/types/ModelData.d.ts +70 -0
  29. package/dist/src/types/Plugin.d.ts +39 -0
  30. package/dist/src/types/RawData.d.ts +18 -0
  31. package/dist/src/types/RenderData.d.ts +4 -0
  32. package/dist/src/types/Theme.d.ts +17 -0
  33. package/dist/src/types/Validator.d.ts +20 -0
  34. package/dist/src/types/index.d.ts +12 -0
  35. package/dist/src/utils/aggregateUtils.d.ts +37 -0
  36. package/dist/src/utils/colorUtils.d.ts +22 -0
  37. package/dist/src/utils/commonUtils.d.ts +3 -5
  38. package/dist/src/utils/dom-lifecycle.d.ts +37 -0
  39. package/dist/src/utils/dom.d.ts +6 -0
  40. package/dist/src/utils/index.d.ts +5 -1
  41. package/dist/src/utils/observables.d.ts +1 -25
  42. package/dist/src/utils/orbchartsUtils.d.ts +2 -53
  43. package/dist/src/utils/validator.d.ts +2 -2
  44. package/dist/test/aggregateTest.d.ts +1 -0
  45. package/package.json +26 -13
  46. package/src/OrbCharts.ts +35 -0
  47. package/src/chart/createChart.ts +997 -0
  48. package/src/chart/createGraphData.ts +391 -0
  49. package/src/chart/createGridData.ts +247 -0
  50. package/src/chart/createMultivariateData.ts +181 -0
  51. package/src/chart/createSeriesData.ts +297 -0
  52. package/src/chart/createTreeData.ts +344 -0
  53. package/src/chart/defaults.ts +100 -0
  54. package/src/defineCanvasLayer.ts +24 -0
  55. package/src/defineCanvasPlugin.ts +39 -0
  56. package/src/defineSVGLayer.ts +24 -0
  57. package/src/defineSVGPlugin.ts +39 -0
  58. package/src/index.ts +6 -18
  59. package/src/layer/createLayer.ts +138 -0
  60. package/src/plugin/createPlugin.ts +470 -0
  61. package/src/test/createGraphData.test.ts +103 -0
  62. package/src/test/createTreeData.test.ts +97 -0
  63. package/src/test/simple-graph-test.js +51 -0
  64. package/src/test/simple-tree-test.js +58 -0
  65. package/src/types/Chart.ts +62 -0
  66. package/src/types/ChartContext.ts +42 -0
  67. package/src/types/Common.ts +5 -0
  68. package/src/types/Encoding.ts +43 -0
  69. package/src/types/Event.ts +26 -0
  70. package/src/types/Layers.ts +93 -0
  71. package/src/types/ModelData.ts +95 -0
  72. package/src/types/Plugin.ts +98 -0
  73. package/src/types/RawData.ts +67 -0
  74. package/src/types/RenderData.ts +16 -0
  75. package/src/types/Theme.ts +21 -0
  76. package/src/types/Validator.ts +36 -0
  77. package/src/types/index.ts +12 -0
  78. package/src/utils/aggregateUtils.ts +99 -0
  79. package/src/utils/colorUtils.ts +63 -0
  80. package/src/utils/commonUtils.ts +12 -11
  81. package/src/utils/dom-lifecycle.ts +164 -0
  82. package/src/utils/dom.ts +55 -0
  83. package/src/utils/index.ts +6 -2
  84. package/src/utils/observables.ts +1 -292
  85. package/src/utils/orbchartsUtils.ts +6 -393
  86. package/src/utils/validator.ts +15 -14
  87. package/dist/lib/core-types.d.ts +0 -1
  88. package/dist/src/AbstractChart.d.ts +0 -19
  89. package/dist/src/GridChart.d.ts +0 -6
  90. package/dist/src/MultiGridChart.d.ts +0 -6
  91. package/dist/src/MultiValueChart.d.ts +0 -6
  92. package/dist/src/RelationshipChart.d.ts +0 -6
  93. package/dist/src/SeriesChart.d.ts +0 -6
  94. package/dist/src/TreeChart.d.ts +0 -6
  95. package/dist/src/base/createBaseChart.d.ts +0 -3
  96. package/dist/src/base/createBasePlugin.d.ts +0 -3
  97. package/dist/src/base/validators/chartOptionsValidator.d.ts +0 -3
  98. package/dist/src/base/validators/chartParamsValidator.d.ts +0 -3
  99. package/dist/src/base/validators/elementValidator.d.ts +0 -3
  100. package/dist/src/base/validators/pluginsValidator.d.ts +0 -3
  101. package/dist/src/defaults.d.ts +0 -25
  102. package/dist/src/defineGridPlugin.d.ts +0 -1
  103. package/dist/src/defineMultiGridPlugin.d.ts +0 -1
  104. package/dist/src/defineMultiValuePlugin.d.ts +0 -1
  105. package/dist/src/defineNoneDataPlugin.d.ts +0 -1
  106. package/dist/src/defineRelationshipPlugin.d.ts +0 -1
  107. package/dist/src/defineSeriesPlugin.d.ts +0 -1
  108. package/dist/src/defineTreePlugin.d.ts +0 -1
  109. package/dist/src/grid/computedDataFn.d.ts +0 -4
  110. package/dist/src/grid/contextObserverCallback.d.ts +0 -3
  111. package/dist/src/grid/dataFormatterValidator.d.ts +0 -3
  112. package/dist/src/grid/dataValidator.d.ts +0 -3
  113. package/dist/src/grid/gridObservables.d.ts +0 -64
  114. package/dist/src/multiGrid/computedDataFn.d.ts +0 -3
  115. package/dist/src/multiGrid/contextObserverCallback.d.ts +0 -3
  116. package/dist/src/multiGrid/dataFormatterValidator.d.ts +0 -3
  117. package/dist/src/multiGrid/dataValidator.d.ts +0 -3
  118. package/dist/src/multiGrid/multiGridObservables.d.ts +0 -16
  119. package/dist/src/multiValue/computedDataFn.d.ts +0 -3
  120. package/dist/src/multiValue/contextObserverCallback.d.ts +0 -3
  121. package/dist/src/multiValue/dataFormatterValidator.d.ts +0 -3
  122. package/dist/src/multiValue/dataValidator.d.ts +0 -3
  123. package/dist/src/multiValue/multiValueObservables.d.ts +0 -130
  124. package/dist/src/relationship/computedDataFn.d.ts +0 -3
  125. package/dist/src/relationship/contextObserverCallback.d.ts +0 -3
  126. package/dist/src/relationship/dataFormatterValidator.d.ts +0 -3
  127. package/dist/src/relationship/dataValidator.d.ts +0 -3
  128. package/dist/src/relationship/relationshipObservables.d.ts +0 -13
  129. package/dist/src/series/computedDataFn.d.ts +0 -3
  130. package/dist/src/series/contextObserverCallback.d.ts +0 -3
  131. package/dist/src/series/dataFormatterValidator.d.ts +0 -3
  132. package/dist/src/series/dataValidator.d.ts +0 -3
  133. package/dist/src/series/seriesObservables.d.ts +0 -37
  134. package/dist/src/tree/computedDataFn.d.ts +0 -3
  135. package/dist/src/tree/contextObserverCallback.d.ts +0 -3
  136. package/dist/src/tree/dataFormatterValidator.d.ts +0 -3
  137. package/dist/src/tree/dataValidator.d.ts +0 -3
  138. package/dist/src/tree/treeObservables.d.ts +0 -10
  139. package/dist/src/utils/d3Scale.d.ts +0 -28
  140. package/lib/core-types.ts +0 -7
  141. package/src/AbstractChart.ts +0 -57
  142. package/src/GridChart.ts +0 -25
  143. package/src/MultiGridChart.ts +0 -25
  144. package/src/MultiValueChart.ts +0 -25
  145. package/src/RelationshipChart.ts +0 -25
  146. package/src/SeriesChart.ts +0 -25
  147. package/src/TreeChart.ts +0 -25
  148. package/src/base/createBaseChart.ts +0 -524
  149. package/src/base/createBasePlugin.ts +0 -154
  150. package/src/base/validators/chartOptionsValidator.ts +0 -24
  151. package/src/base/validators/chartParamsValidator.ts +0 -134
  152. package/src/base/validators/elementValidator.ts +0 -14
  153. package/src/base/validators/pluginsValidator.ts +0 -15
  154. package/src/defaults.ts +0 -284
  155. package/src/defineGridPlugin.ts +0 -3
  156. package/src/defineMultiGridPlugin.ts +0 -3
  157. package/src/defineMultiValuePlugin.ts +0 -3
  158. package/src/defineNoneDataPlugin.ts +0 -4
  159. package/src/defineRelationshipPlugin.ts +0 -3
  160. package/src/defineSeriesPlugin.ts +0 -3
  161. package/src/defineTreePlugin.ts +0 -3
  162. package/src/grid/computedDataFn.ts +0 -129
  163. package/src/grid/contextObserverCallback.ts +0 -209
  164. package/src/grid/dataFormatterValidator.ts +0 -126
  165. package/src/grid/dataValidator.ts +0 -13
  166. package/src/grid/gridObservables.ts +0 -699
  167. package/src/multiGrid/computedDataFn.ts +0 -123
  168. package/src/multiGrid/contextObserverCallback.ts +0 -109
  169. package/src/multiGrid/dataFormatterValidator.ts +0 -121
  170. package/src/multiGrid/dataValidator.ts +0 -13
  171. package/src/multiGrid/multiGridObservables.ts +0 -367
  172. package/src/multiValue/computedDataFn.ts +0 -113
  173. package/src/multiValue/contextObserverCallback.ts +0 -328
  174. package/src/multiValue/dataFormatterValidator.ts +0 -95
  175. package/src/multiValue/dataValidator.ts +0 -13
  176. package/src/multiValue/multiValueObservables.ts +0 -865
  177. package/src/relationship/computedDataFn.ts +0 -159
  178. package/src/relationship/contextObserverCallback.ts +0 -80
  179. package/src/relationship/dataFormatterValidator.ts +0 -14
  180. package/src/relationship/dataValidator.ts +0 -14
  181. package/src/relationship/relationshipObservables.ts +0 -85
  182. package/src/series/computedDataFn.ts +0 -88
  183. package/src/series/contextObserverCallback.ts +0 -132
  184. package/src/series/dataFormatterValidator.ts +0 -47
  185. package/src/series/dataValidator.ts +0 -13
  186. package/src/series/seriesObservables.ts +0 -210
  187. package/src/tree/computedDataFn.ts +0 -129
  188. package/src/tree/contextObserverCallback.ts +0 -58
  189. package/src/tree/dataFormatterValidator.ts +0 -14
  190. package/src/tree/dataValidator.ts +0 -14
  191. package/src/tree/treeObservables.ts +0 -106
  192. package/src/utils/d3Scale.ts +0 -198
  193. package/tsconfig.base.json +0 -14
  194. package/tsconfig.json +0 -3
  195. package/vite-env.d.ts +0 -7
  196. package/vite.config.js +0 -23
@@ -1,396 +1,9 @@
1
- import * as d3 from 'd3'
2
- import type {
3
- ChartType,
4
- ChartParams,
5
- DatumValue,
6
- DataSeries,
7
- DataSeriesDatum,
8
- DataSeriesValue,
9
- DataGrid,
10
- DataGridDatum,
11
- DataGridValue,
12
- DataMultiGrid,
13
- DataMultiValue,
14
- DataMultiValueDatum,
15
- DataMultiValueValue,
16
- ComputedXYDatumMultiValue,
17
- DataFormatterContainer,
18
- SeriesDirection,
19
- DataFormatterGridGrid,
20
- ContainerPosition,
21
- ContainerPositionScaled,
22
- Layout
23
- } from '../../lib/core-types'
24
- import { isPlainObject } from './commonUtils'
25
1
 
26
- export function formatValueToLabel (value: any, valueFormatter: string | ((text: d3.NumberValue) => string)) {
27
- if (valueFormatter! instanceof Function == true) {
28
- return (valueFormatter as ((text: d3.NumberValue) => string))(value)
29
- }
30
- return d3.format(valueFormatter as string)!(value)
2
+ export function createPluginClassName (pluginName: string) {
3
+ return `orbcharts-${pluginName}`
31
4
  }
32
5
 
33
- export function createDefaultDatumId (chartTypeOrPrefix: string, levelOneIndex: number, levelTwoIndex?: number, levelThreeIndex?: number) {
34
- let text = `${chartTypeOrPrefix}_${levelOneIndex}`
35
- if (levelTwoIndex != null) {
36
- text += `_${levelTwoIndex}`
37
- }
38
- if (levelThreeIndex != null) {
39
- text += `_${levelThreeIndex}`
40
- }
41
- return text
42
- }
43
-
44
- export function createDefaultSeriesLabel (chartTypeOrPrefix: string, seriesIndex: number) {
45
- // return `${chartTypeOrPrefix}_series${seriesIndex}`
46
- return `series${seriesIndex}`
47
- }
48
-
49
- export function createDefaultGroupLabel (chartTypeOrPrefix: string, groupIndex: number) {
50
- // return `${chartTypeOrPrefix}_group${groupIndex}`
51
- return `group${groupIndex}`
52
- }
53
-
54
- export function createDefaultCategoryLabel () {
55
- // return `${chartTypeOrPrefix}_category`
56
- return '' // 空值
57
- }
58
-
59
- export function createDefaultValueLabel (chartTypeOrPrefix: string, valueIndex: number) {
60
- // return `${chartTypeOrPrefix}_value${valueIndex}`
61
- return `value${valueIndex}`
62
- }
63
-
64
- export function createGridSeriesLabels ({ transposedDataGrid, dataFormatterGrid, chartType = 'grid' }: {
65
- transposedDataGrid: DataGridDatum[][],
66
- dataFormatterGrid: DataFormatterGridGrid
67
- chartType?: ChartType
68
- }) {
69
- const labels = dataFormatterGrid.seriesDirection === 'row'
70
- ? dataFormatterGrid.rowLabels
71
- : dataFormatterGrid.columnLabels
72
- return transposedDataGrid.map((_, rowIndex) => {
73
- return labels[rowIndex] != null
74
- ? labels[rowIndex]
75
- : createDefaultSeriesLabel(chartType, rowIndex)
76
- })
77
- }
78
-
79
- export function createMultiGridSeriesLabels ({ transposedDataGrid, dataFormatterGrid, chartType = 'multiGrid', gridIndex = 0 }: {
80
- transposedDataGrid: DataGridDatum[][],
81
- dataFormatterGrid: DataFormatterGridGrid
82
- chartType?: ChartType
83
- gridIndex?: number
84
- }) {
85
- const labels = dataFormatterGrid.seriesDirection === 'row'
86
- ? dataFormatterGrid.rowLabels
87
- : dataFormatterGrid.columnLabels
88
- return transposedDataGrid.map((_, rowIndex) => {
89
- return labels[rowIndex] != null
90
- ? labels[rowIndex]
91
- : createDefaultSeriesLabel(`${chartType}_grid${gridIndex}`, rowIndex)
92
- })
93
- }
94
-
95
- export function createGridGroupLabels ({ transposedDataGrid, dataFormatterGrid, chartType = 'grid' }: {
96
- transposedDataGrid: DataGridDatum[][],
97
- dataFormatterGrid: DataFormatterGridGrid
98
- chartType?: ChartType
99
- }) {
100
- if (transposedDataGrid[0] == null) {
101
- return []
102
- }
103
- const labels = dataFormatterGrid.seriesDirection === 'row'
104
- ? dataFormatterGrid.columnLabels
105
- : dataFormatterGrid.rowLabels
106
- return transposedDataGrid[0].map((_, columnLabels) => {
107
- return labels[columnLabels] != null
108
- ? labels[columnLabels]
109
- : createDefaultGroupLabel(chartType, columnLabels)
110
- })
111
- }
112
-
113
- export function createMultiGridGroupLabels ({ transposedDataGrid, dataFormatterGrid, chartType = 'multiGrid', gridIndex = 0 }: {
114
- transposedDataGrid: DataGridDatum[][],
115
- dataFormatterGrid: DataFormatterGridGrid
116
- chartType?: ChartType
117
- gridIndex?: number
118
- }) {
119
- if (transposedDataGrid[0] == null) {
120
- return []
121
- }
122
- const labels = dataFormatterGrid.seriesDirection === 'row'
123
- ? dataFormatterGrid.columnLabels
124
- : dataFormatterGrid.rowLabels
125
- return transposedDataGrid[0].map((_, columnLabels) => {
126
- return labels[columnLabels] != null
127
- ? labels[columnLabels]
128
- : createDefaultGroupLabel(`${chartType}_grid${gridIndex}`, columnLabels)
129
- })
130
- }
131
-
132
- // 取得最小及最大值 - 數字陣列
133
- export function getMinMax (data: number[]): [number, number] {
134
- const defaultMinMax: [number, number] = [0, 0] // default
135
- if (!data.length) {
136
- return defaultMinMax
137
- }
138
- const minMax: [number, number] = data.reduce((prev, current) => {
139
- // [min, max]
140
- return [
141
- current < prev[0] ? current : prev[0],
142
- current > prev[1] ? current : prev[1]
143
- ]
144
- }, [data[0], data[0]])
145
- return minMax
146
- }
147
-
148
- // 取得最小及最大值 - datum格式陣列資料
149
- export function getMinMaxValue (data: DatumValue[]): [number, number] {
150
- const arr = data
151
- .filter(d => d != null && d.value != null)
152
- .map(d => d.value )
153
- return getMinMax(arr)
154
- }
155
-
156
- // 取得最小及最大值 - Series Data
157
- export function getMinMaxSeries (data: DataSeries): [number, number] {
158
- const flatData: (DataSeriesValue | DataSeriesDatum)[] = data[0] && Array.isArray((data as (DataSeriesValue | DataSeriesDatum)[][])[0])
159
- ? data.flat()
160
- : data as (DataSeriesValue | DataSeriesDatum)[]
161
- const arr = flatData
162
- .filter(d => (d == null || (isPlainObject(d) && (d as DataSeriesDatum).value == null)) === false) // 過濾掉null &
163
- .map(d => typeof d === 'number' ? d : d.value )
164
- return getMinMax(arr)
165
- }
166
-
167
- // 取得最小及最大值 - Grid Data
168
- export function getMinMaxGrid (data: DataGrid): [number, number] {
169
- const flatData: (DataGridValue | DataGridDatum)[] = data.flat()
170
- const arr = flatData
171
- .filter(d => (d == null || (isPlainObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
172
- .map(d => typeof d === 'number' ? d : d.value )
173
- return getMinMax(arr)
174
- }
175
-
176
- // 取得最小及最大值 - MultiGrid Data
177
- export function getMinMaxMultiGrid (data: DataMultiGrid): [number, number] {
178
- const flatData: (DataGridValue | DataGridDatum)[] = data.flat().flat()
179
- const arr = flatData
180
- .filter(d => (d == null || (isPlainObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
181
- .map(d => typeof d === 'number' ? d : d.value )
182
- return getMinMax(arr)
183
- }
184
-
185
- // 取得最小及最大值 - MultiValue Data
186
- export function getMinMaxMultiValue (data: DataMultiValue, valueIndex: number): [number, number] {
187
- const arr: number[] = data
188
- .map(d => {
189
- if (Array.isArray(d)) {
190
- return d[valueIndex] ?? null
191
- } else if (isPlainObject(d)) {
192
- return (d as DataMultiValueDatum).value[valueIndex] ?? null
193
- } else {
194
- return null
195
- }
196
- })
197
- .filter(d => d != null)
198
- return getMinMax(arr)
199
- }
200
-
201
- export function getMinMaxMultiValueXY ({ data, minX, maxX, minY, maxY }: {
202
- data: ComputedXYDatumMultiValue[][]
203
- minX: number
204
- maxX: number
205
- minY: number
206
- maxY: number
207
- }) {
208
- let filteredData: ComputedXYDatumMultiValue[][] = []
209
- let minXDatum: ComputedXYDatumMultiValue | null = null
210
- let maxXDatum: ComputedXYDatumMultiValue | null = null
211
- let minYDatum: ComputedXYDatumMultiValue | null = null
212
- let maxYDatum: ComputedXYDatumMultiValue | null = null
213
-
214
- for (let categoryData of data) {
215
- for (let datum of categoryData) {
216
- if (datum.axisX >= minX && datum.axisX <= maxX && datum.axisY >= minY && datum.axisY <= maxY) {
217
- filteredData.push(categoryData)
218
- if (minXDatum == null || datum.axisX < minXDatum.axisX) {
219
- minXDatum = datum
220
- }
221
- if (maxXDatum == null || datum.axisX > maxXDatum.axisX) {
222
- maxXDatum = datum
223
- }
224
- if (minYDatum == null || datum.axisY < minYDatum.axisY) {
225
- minYDatum = datum
226
- }
227
- if (maxYDatum == null || datum.axisY > maxYDatum.axisY) {
228
- maxYDatum = datum
229
- }
230
- }
231
- }
232
- }
233
-
234
- return {
235
- minXDatum,
236
- maxXDatum,
237
- minYDatum,
238
- maxYDatum,
239
- filteredData
240
- }
241
- }
242
-
243
- // @Q@ 待處理
244
- // // 取得最小及最大值 - Relationship Data
245
- // export function getMinMaxRelationship (data: DataRelationship, target: 'nodes' | 'edges' = 'nodes'): [number, number] {
246
-
247
- // }
248
-
249
- // @Q@ 待處理
250
- // // 取得最小及最大值 - Tree Data
251
- // export function getMinMaxTree (data: DataTree): [number, number] {
252
-
253
- // }
254
-
255
- // 轉置成seriesDirection為main的陣列格式
256
- export function transposeData<T> (seriesDirection: SeriesDirection, data: T[][]): T[][] {
257
- if (seriesDirection === 'row') {
258
- return Object.assign([], data)
259
- }
260
- // 取得原始陣列的維度
261
- const rows = data.length;
262
- const cols = data.reduce((prev, current) => {
263
- return Math.max(prev, current.length)
264
- }, 0)
265
-
266
- // 初始化轉換後的陣列
267
- const transposedArray = new Array(cols).fill(null).map(() => new Array(rows).fill(null))
268
-
269
- // 遍歷原始陣列,進行轉換
270
- for (let i = 0; i < rows; i++) {
271
- for (let j = 0; j < cols; j++) {
272
- transposedArray[j][i] = data[i][j]
273
- }
274
- }
275
-
276
- return transposedArray
277
- }
278
-
279
-
280
- export function seriesColorPredicate (seriesIndex: number, chartParams: ChartParams) {
281
- return seriesIndex < chartParams.colors[chartParams.colorScheme].label.length
282
- ? chartParams.colors[chartParams.colorScheme].label[seriesIndex]
283
- : chartParams.colors[chartParams.colorScheme].label[
284
- seriesIndex % chartParams.colors[chartParams.colorScheme].label.length
285
- ]
286
- }
287
-
288
-
289
- // 計算預設欄列數量
290
- // 規則1.rowAmount*columnAmount要大於或等於amount,並且數字要盡可能小
291
- // 規則2.columnAmount要大於或等於rowAmount,並且數字要盡可能小
292
- function calcGridDimensions (amount: number): { rowAmount: number; columnAmount: number } {
293
- let rowAmount = Math.floor(Math.sqrt(amount))
294
- let columnAmount = Math.ceil(amount / rowAmount)
295
- while (rowAmount * columnAmount < amount) {
296
- columnAmount++
297
- }
298
- return { rowAmount, columnAmount }
299
- }
300
-
301
- export function calcContainerPosition (layout: Layout, container: DataFormatterContainer, amount: number): ContainerPosition[] {
302
- // const { gap } = container
303
- const columnGap = container.columnGap === 'auto'
304
- ? layout.left + layout.right
305
- : container.columnGap
306
- const rowGap = container.rowGap === 'auto'
307
- ? layout.top + layout.bottom
308
- : container.rowGap
309
- const { rowAmount, columnAmount } = (container.rowAmount * container.columnAmount) >= amount
310
- // 如果container設定的rowAmount和columnAmount的乘積大於或等於amount,則使用目前設定
311
- ? container
312
- // 否則計算一個合適的預設值
313
- : calcGridDimensions(amount)
314
-
315
- return new Array(amount).fill(null).map((_, index) => {
316
- const columnIndex = index % columnAmount
317
- const rowIndex = Math.floor(index / columnAmount)
318
-
319
- const width = (layout.width - (columnGap * (columnAmount - 1))) / columnAmount
320
- const height = (layout.height - (rowGap * (rowAmount - 1))) / rowAmount
321
- const x = columnIndex * width + (columnIndex * columnGap)
322
- const y = rowIndex * height + (rowIndex * rowGap)
323
- // const translate: [number, number] = [x, y]
324
-
325
- return {
326
- slotIndex: index,
327
- rowIndex,
328
- columnIndex,
329
- // translate,
330
- startX: x,
331
- startY: y,
332
- centerX: x + width / 2,
333
- centerY: y + height / 2,
334
- width,
335
- height
336
- }
337
- })
338
- }
339
-
340
- export function calcContainerPositionScaled (layout: Layout, container: DataFormatterContainer, amount: number): ContainerPositionScaled[] {
341
- // const { gap } = container
342
- const columnGap = container.columnGap === 'auto'
343
- ? layout.left + layout.right
344
- : container.columnGap
345
- const rowGap = container.rowGap === 'auto'
346
- ? layout.top + layout.bottom
347
- : container.rowGap
348
- const { rowAmount, columnAmount } = (container.rowAmount * container.columnAmount) >= amount
349
- // 如果container設定的rowAmount和columnAmount的乘積大於或等於amount,則使用目前設定
350
- ? container
351
- // 否則計算一個合適的預設值
352
- : calcGridDimensions(amount)
353
-
354
- return new Array(amount).fill(null).map((_, index) => {
355
- const columnIndex = index % columnAmount
356
- const rowIndex = Math.floor(index / columnAmount)
357
-
358
- const width = (layout.width - (columnGap * (columnAmount - 1))) / columnAmount
359
- const height = (layout.height - (rowGap * (rowAmount - 1))) / rowAmount
360
- const x = columnIndex * width + (columnIndex * columnGap)
361
- const y = rowIndex * height + (rowIndex * rowGap)
362
- const translate: [number, number] = [x, y]
363
- const scale: [number, number] = [width / layout.width, height / layout.height]
364
-
365
- return {
366
- slotIndex: index,
367
- rowIndex,
368
- columnIndex,
369
- translate,
370
- scale
371
- }
372
- })
373
- }
374
-
375
- // // multiGrid datum color
376
- // export function multiGridColorPredicate ({ seriesIndex, groupIndex, data, chartParams }: {
377
- // seriesIndex: number
378
- // groupIndex: number
379
- // data: ComputedDataMultiGrid
380
- // chartParams: ChartParams
381
- // }) {
382
- // // 累加前面的grid的seriesIndex
383
- // const accSeriesIndex = data.reduce((prev, current) => {
384
- // if (current[0] && current[0][0] && groupIndex > current[0][0].gridIndex) {
385
- // return prev + current[0].length
386
- // } else if (current[0] && current[0][0] && groupIndex == current[0][0].gridIndex) {
387
- // return prev + seriesIndex
388
- // } else {
389
- // return prev
390
- // }
391
- // }, 0)
392
-
393
- // return seriesColorPredicate(accSeriesIndex, chartParams)
394
- // }
395
-
396
-
6
+ export function createLayerClassName (pluginName: string, layerName: string) {
7
+ // orbcharts-pluginName-layerName
8
+ return `${createPluginClassName(pluginName)}-${layerName}`
9
+ }
@@ -7,11 +7,12 @@ import type {
7
7
  ValidatorRuleToBe,
8
8
  ValidatorRuleToBeOption,
9
9
  ValidatorRule
10
- } from '../../lib/core-types'
10
+ } from '../types'
11
11
  import { isFunction, isPlainObject } from './commonUtils'
12
- import { createValidatorErrorMessage } from './errorMessage'
13
-
14
12
 
13
+ // function validateObject<T> (data: T, rules: Partial<ValidatorRule<T>>): ValidatorResult {
14
+ // return { status: 'success', columnName: '', expectToBe: '' }
15
+ // }
15
16
 
16
17
  // let test: ValidatorRule = {
17
18
  // name: {
@@ -25,7 +26,7 @@ import { createValidatorErrorMessage } from './errorMessage'
25
26
  // }
26
27
  // }
27
28
 
28
- function getInvalidColumn<T> (data: T, rules: Partial<ValidatorRule<T>>) {
29
+ function getInvalidProperty<T> (data: T, rules: Partial<ValidatorRule<T>>) {
29
30
  // "toBeTypes" 的測試
30
31
  const testType: {[key in ToBeTypes]: (value: any) => boolean} = {
31
32
  string: (value: any) => typeof value === 'string',
@@ -43,15 +44,15 @@ function getInvalidColumn<T> (data: T, rules: Partial<ValidatorRule<T>>) {
43
44
  const testOption: {[key in ToBeOption]: (value: any) => boolean} = {
44
45
  ColorType: (value: ColorType) => {
45
46
  return value === 'none'
46
- || value === 'label'
47
+ || value === 'data'
47
48
  || value === 'primary'
48
49
  || value === 'secondary'
49
- || value === 'labelContrast'
50
+ || value === 'dataContrast'
50
51
  || value === 'background'
51
52
  },
52
53
  }
53
54
 
54
- const failColumn = Object.keys(data).find((columnName: string) => {
55
+ const failProperty = Object.keys(data).find((columnName: string) => {
55
56
  // 有定義規則
56
57
  if (rules[columnName as keyof T]) {
57
58
  const rule: ValidatorRuleToBeTypes | ValidatorRuleToBe | ValidatorRuleToBeOption = rules[columnName as keyof T]
@@ -84,10 +85,10 @@ function getInvalidColumn<T> (data: T, rules: Partial<ValidatorRule<T>>) {
84
85
  return false
85
86
  })
86
87
 
87
- return failColumn
88
+ return failProperty
88
89
  }
89
90
 
90
- export function validateColumns<T> (data: T, rules: Partial<ValidatorRule<T>>): ValidatorResult {
91
+ export function validateObject<T> (data: T, rules: Partial<ValidatorRule<T>>): ValidatorResult {
91
92
  // if (data === undefined || data === null) {
92
93
  // // orbcharts所有的options都是允許空值的
93
94
  // return {
@@ -96,9 +97,9 @@ export function validateColumns<T> (data: T, rules: Partial<ValidatorRule<T>>):
96
97
  // expectToBe: '',
97
98
  // }
98
99
  // }
99
- const invalidColumn = getInvalidColumn(data, rules)
100
- if (invalidColumn) {
101
- const rule = rules[invalidColumn as keyof T]
100
+ const invalidProperty = getInvalidProperty(data, rules)
101
+ if (invalidProperty) {
102
+ const rule = rules[invalidProperty as keyof T]
102
103
  const expectToBe = (rule as ValidatorRuleToBeTypes).toBeTypes
103
104
  ? (rule as ValidatorRuleToBeTypes).toBeTypes.join(' | ')
104
105
  : (rule as ValidatorRuleToBe).toBe
@@ -110,11 +111,11 @@ export function validateColumns<T> (data: T, rules: Partial<ValidatorRule<T>>):
110
111
  return {
111
112
  status: 'error',
112
113
  // message: createValidatorErrorMessage({
113
- // columnName: failColumn,
114
+ // columnName: failProperty,
114
115
  // expect,
115
116
  // from
116
117
  // })
117
- columnName: invalidColumn as string,
118
+ columnName: invalidProperty as string,
118
119
  expectToBe: expectToBe,
119
120
  }
120
121
  } else {
@@ -1 +0,0 @@
1
- export * from '@orbcharts/core-types';
@@ -1,19 +0,0 @@
1
- import { Subject } from 'rxjs';
2
- import { ComputedDataFn, DataValidator, ChartEntity, ChartType, ChartParamsPartial, ContextObserverCallback, ChartOptionsPartial, DataTypeMap, DataFormatterTypeMap, DataFormatterPartialTypeMap, DataFormatterValidator, EventTypeMap, PluginEntity } from '../lib/core-types';
3
- import * as d3 from 'd3';
4
- export declare abstract class AbstractChart<T extends ChartType> implements ChartEntity<T> {
5
- selection: d3.Selection<SVGGElement, unknown, HTMLElement, unknown>;
6
- destroy: () => void;
7
- data$: Subject<DataTypeMap<T>>;
8
- dataFormatter$: Subject<DataFormatterPartialTypeMap<T>>;
9
- plugins$: Subject<PluginEntity<T, any, any>[]>;
10
- chartParams$: Subject<ChartParamsPartial>;
11
- event$: Subject<EventTypeMap<T>>;
12
- constructor({ defaultDataFormatter, dataFormatterValidator, computedDataFn, dataValidator, contextObserverCallback }: {
13
- defaultDataFormatter: DataFormatterTypeMap<T>;
14
- dataFormatterValidator: DataFormatterValidator<T>;
15
- computedDataFn: ComputedDataFn<T>;
16
- dataValidator: DataValidator<T>;
17
- contextObserverCallback: ContextObserverCallback<T>;
18
- }, element: HTMLElement | Element, options?: ChartOptionsPartial<T>);
19
- }
@@ -1,6 +0,0 @@
1
- import { ChartEntity, ChartOptionsPartial } from '../lib/core-types';
2
- import { AbstractChart } from './AbstractChart';
3
-
4
- export declare class GridChart extends AbstractChart<'grid'> implements ChartEntity<'grid'> {
5
- constructor(element: HTMLElement | Element, options?: ChartOptionsPartial<'grid'>);
6
- }
@@ -1,6 +0,0 @@
1
- import { ChartEntity, ChartOptionsPartial } from '../lib/core-types';
2
- import { AbstractChart } from './AbstractChart';
3
-
4
- export declare class MultiGridChart extends AbstractChart<'multiGrid'> implements ChartEntity<'multiGrid'> {
5
- constructor(element: HTMLElement | Element, options?: ChartOptionsPartial<'multiGrid'>);
6
- }
@@ -1,6 +0,0 @@
1
- import { ChartEntity, ChartOptionsPartial } from '../lib/core-types';
2
- import { AbstractChart } from './AbstractChart';
3
-
4
- export declare class MultiValueChart extends AbstractChart<'multiValue'> implements ChartEntity<'multiValue'> {
5
- constructor(element: HTMLElement | Element, options?: ChartOptionsPartial<'multiValue'>);
6
- }
@@ -1,6 +0,0 @@
1
- import { ChartEntity, ChartOptionsPartial } from '../lib/core-types';
2
- import { AbstractChart } from './AbstractChart';
3
-
4
- export declare class RelationshipChart extends AbstractChart<'relationship'> implements ChartEntity<'relationship'> {
5
- constructor(element: HTMLElement | Element, options?: ChartOptionsPartial<'relationship'>);
6
- }
@@ -1,6 +0,0 @@
1
- import { ChartEntity, ChartOptionsPartial } from '../lib/core-types';
2
- import { AbstractChart } from './AbstractChart';
3
-
4
- export declare class SeriesChart extends AbstractChart<'series'> implements ChartEntity<'series'> {
5
- constructor(element: HTMLElement | Element, options?: ChartOptionsPartial<'series'>);
6
- }
@@ -1,6 +0,0 @@
1
- import { ChartEntity, ChartOptionsPartial } from '../lib/core-types';
2
- import { AbstractChart } from './AbstractChart';
3
-
4
- export declare class TreeChart extends AbstractChart<'tree'> implements ChartEntity<'tree'> {
5
- constructor(element: HTMLElement | Element, options?: ChartOptionsPartial<'tree'>);
6
- }
@@ -1,3 +0,0 @@
1
- import { CreateBaseChart } from '../../lib/core-types';
2
-
3
- export declare const createBaseChart: CreateBaseChart;
@@ -1,3 +0,0 @@
1
- import { CreateBasePlugin } from '../../lib/core-types';
2
-
3
- export declare const createBasePlugin: CreateBasePlugin;
@@ -1,3 +0,0 @@
1
- import { ChartOptionsPartial, ChartType, ValidatorResult } from '../../../lib/core-types';
2
-
3
- export declare function chartOptionsValidator<T extends ChartType>(chartOptionsPartial: ChartOptionsPartial<T>): ValidatorResult;
@@ -1,3 +0,0 @@
1
- import { ChartParamsPartial, ChartType, ValidatorResult } from '../../../lib/core-types';
2
-
3
- export declare function chartParamsValidator(chartType: ChartType, chartParamsPartial: ChartParamsPartial | undefined): ValidatorResult;
@@ -1,3 +0,0 @@
1
- import { ValidatorResult } from '../../../lib/core-types';
2
-
3
- export declare function elementValidator(element: HTMLElement | Element): ValidatorResult;
@@ -1,3 +0,0 @@
1
- import { ChartType, PluginEntity, ValidatorResult } from '../../../lib/core-types';
2
-
3
- export declare function pluginsValidator(chartType: ChartType, pluginEntities: PluginEntity<any, any, any>[]): ValidatorResult;
@@ -1,25 +0,0 @@
1
- import { ChartOptionsPartial, DataSeries, DataGrid, DataMultiGrid, DataMultiValue, DataTree, DataRelationship, DataFormatterValueAxis, DataFormatterGroupAxis, DataFormatterXYAxis, DataFormatterContainer, DataFormatterSeries, DataFormatterGrid, DataFormatterGridGrid, DataFormatterMultiGrid, DataFormatterMultiGridGrid, DataFormatterMultiValue, DataFormatterTree, DataFormatterRelationship, ChartParams, Padding } from '../lib/core-types';
2
-
3
- export declare const DEFAULT_CHART_OPTIONS: ChartOptionsPartial<any>;
4
- export declare const DEFAULT_PADDING: Padding;
5
- export declare const DEFAULT_CHART_PARAMS: ChartParams;
6
- export declare const DEFAULT_CHART_WIDTH = 800;
7
- export declare const DEFAULT_CHART_HEIGHT = 500;
8
- export declare const DEFAULT_DATA_SERIES: DataSeries;
9
- export declare const DEFAULT_DATA_GRID: DataGrid;
10
- export declare const DEFAULT_DATA_MULTI_GRID: DataMultiGrid;
11
- export declare const DEFAULT_DATA_MULTI_VALUE: DataMultiValue;
12
- export declare const DEFAULT_DATA_TREE: DataTree;
13
- export declare const DEFAULTL_DATA_RELATIONA: DataRelationship;
14
- export declare const DEFAULT_DATA_FORMATTER_VALUE_AXIS: DataFormatterValueAxis;
15
- export declare const DEFAULT_DATA_FORMATTER_GROUP_AXIS: DataFormatterGroupAxis;
16
- export declare const DEFAULT_DATA_FORMATTER_X_Y_AXIS: DataFormatterXYAxis;
17
- export declare const DEFAULT_DATA_FORMATTER_CONTAINER: DataFormatterContainer;
18
- export declare const DEFAULT_DATA_FORMATTER_SERIES: DataFormatterSeries;
19
- export declare const DEFAULT_DATA_FORMATTER_GRID_GRID: DataFormatterGridGrid;
20
- export declare const DEFAULT_DATA_FORMATTER_GRID: DataFormatterGrid;
21
- export declare const DEFAULT_DATA_FORMATTER_MULTI_GRID_GRID: DataFormatterMultiGridGrid;
22
- export declare const DEFAULT_DATA_FORMATTER_MULTI_GRID: DataFormatterMultiGrid;
23
- export declare const DEFAULT_DATA_FORMATTER_MULTI_VALUE: DataFormatterMultiValue;
24
- export declare const DEFAULT_DATA_FORMATTER_TREE: DataFormatterTree;
25
- export declare const DEFAULT_DATA_FORMATTER_RELATIONSHIP: DataFormatterRelationship;
@@ -1 +0,0 @@
1
- export declare const defineGridPlugin: import('@orbcharts/core-types').DefinePlugin<"grid">;
@@ -1 +0,0 @@
1
- export declare const defineMultiGridPlugin: import('@orbcharts/core-types').DefinePlugin<"multiGrid">;
@@ -1 +0,0 @@
1
- export declare const defineMultiValuePlugin: import('@orbcharts/core-types').DefinePlugin<"multiValue">;
@@ -1 +0,0 @@
1
- export declare const defineNoneDataPlugin: import('@orbcharts/core-types').DefinePlugin<any>;
@@ -1 +0,0 @@
1
- export declare const defineRelationshipPlugin: import('@orbcharts/core-types').DefinePlugin<"relationship">;
@@ -1 +0,0 @@
1
- export declare const defineSeriesPlugin: import('@orbcharts/core-types').DefinePlugin<"series">;
@@ -1 +0,0 @@
1
- export declare const defineTreePlugin: import('@orbcharts/core-types').DefinePlugin<"tree">;
@@ -1,4 +0,0 @@
1
- import { ComputedDataFn, DataGrid, DataGridDatum, DataFormatterGridGrid } from '../../lib/core-types';
2
-
3
- export declare function createTransposedDataGrid(data: DataGrid, dataFormatterGrid: DataFormatterGridGrid): DataGridDatum[][];
4
- export declare const computedDataFn: ComputedDataFn<'grid'>;
@@ -1,3 +0,0 @@
1
- import { ContextObserverCallback } from '../../lib/core-types';
2
-
3
- export declare const contextObserverCallback: ContextObserverCallback<'grid'>;
@@ -1,3 +0,0 @@
1
- import { DataFormatterValidator } from '../../lib/core-types';
2
-
3
- export declare const dataFormatterValidator: DataFormatterValidator<'grid'>;
@@ -1,3 +0,0 @@
1
- import { DataValidator } from '../../lib/core-types';
2
-
3
- export declare const dataValidator: DataValidator<'grid'>;