@orbcharts/core 3.0.0-alpha.60 → 3.0.0-alpha.62
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +200 -200
- package/dist/lib/core-types.d.ts +1 -0
- package/dist/orbcharts-core.es.js +3056 -2609
- package/dist/orbcharts-core.umd.js +6 -2
- package/dist/src/AbstractChart.d.ts +5 -3
- package/dist/src/GridChart.d.ts +1 -1
- package/dist/src/MultiGridChart.d.ts +1 -1
- package/dist/src/MultiValueChart.d.ts +1 -1
- package/dist/src/RelationshipChart.d.ts +1 -1
- package/dist/src/SeriesChart.d.ts +1 -1
- package/dist/src/TreeChart.d.ts +1 -1
- package/dist/src/base/createBaseChart.d.ts +1 -1
- package/dist/src/base/createBasePlugin.d.ts +1 -1
- package/dist/src/base/validators/chartOptionsValidator.d.ts +3 -0
- package/dist/src/base/validators/chartParamsValidator.d.ts +3 -0
- package/dist/src/base/validators/elementValidator.d.ts +3 -0
- package/dist/src/base/validators/pluginsValidator.d.ts +3 -0
- package/dist/src/defaults.d.ts +1 -16
- package/dist/src/defineGridPlugin.d.ts +1 -1
- package/dist/src/defineMultiGridPlugin.d.ts +1 -1
- package/dist/src/defineMultiValuePlugin.d.ts +1 -1
- package/dist/src/defineNoneDataPlugin.d.ts +1 -1
- package/dist/src/defineRelationshipPlugin.d.ts +1 -1
- package/dist/src/defineSeriesPlugin.d.ts +1 -1
- package/dist/src/defineTreePlugin.d.ts +1 -1
- package/dist/src/grid/computedDataFn.d.ts +4 -0
- package/dist/src/grid/contextObserverCallback.d.ts +3 -0
- package/dist/src/grid/dataFormatterValidator.d.ts +3 -0
- package/dist/src/grid/dataValidator.d.ts +3 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/multiGrid/computedDataFn.d.ts +3 -0
- package/dist/src/multiGrid/contextObserverCallback.d.ts +3 -0
- package/dist/src/multiGrid/dataFormatterValidator.d.ts +3 -0
- package/dist/src/multiGrid/dataValidator.d.ts +3 -0
- package/dist/src/multiValue/computedDataFn.d.ts +3 -0
- package/dist/src/multiValue/contextObserverCallback.d.ts +3 -0
- package/dist/src/multiValue/dataFormatterValidator.d.ts +3 -0
- package/dist/src/multiValue/dataValidator.d.ts +3 -0
- package/dist/src/relationship/computedDataFn.d.ts +3 -0
- package/dist/src/relationship/contextObserverCallback.d.ts +3 -0
- package/dist/src/relationship/dataFormatterValidator.d.ts +3 -0
- package/dist/src/relationship/dataValidator.d.ts +3 -0
- package/dist/src/series/computedDataFn.d.ts +3 -0
- package/dist/src/series/contextObserverCallback.d.ts +3 -0
- package/dist/src/series/dataFormatterValidator.d.ts +3 -0
- package/dist/src/series/dataValidator.d.ts +3 -0
- package/dist/src/tree/computedDataFn.d.ts +3 -0
- package/dist/src/tree/contextObserverCallback.d.ts +3 -0
- package/dist/src/tree/dataFormatterValidator.d.ts +3 -0
- package/dist/src/tree/dataValidator.d.ts +3 -0
- package/dist/src/utils/commonUtils.d.ts +1 -0
- package/dist/src/utils/errorMessage.d.ts +14 -0
- package/dist/src/{grid → utils}/gridObservables.d.ts +2 -2
- package/dist/src/utils/index.d.ts +7 -3
- package/dist/src/{multiGrid → utils}/multiGridObservables.d.ts +1 -1
- package/dist/src/utils/observables.d.ts +2 -1
- package/dist/src/utils/orbchartsUtils.d.ts +1 -12
- package/dist/src/{series → utils}/seriesObservables.d.ts +3 -3
- package/dist/src/{tree → utils}/treeObservables.d.ts +1 -1
- package/dist/src/utils/validator.d.ts +3 -0
- package/lib/core-types.ts +7 -0
- package/package.json +42 -41
- package/src/AbstractChart.ts +57 -48
- package/src/GridChart.ts +24 -20
- package/src/MultiGridChart.ts +24 -20
- package/src/MultiValueChart.ts +24 -20
- package/src/RelationshipChart.ts +24 -20
- package/src/SeriesChart.ts +24 -20
- package/src/TreeChart.ts +24 -20
- package/src/base/createBaseChart.ts +500 -386
- package/src/base/createBasePlugin.ts +152 -95
- package/src/base/validators/chartOptionsValidator.ts +24 -0
- package/src/base/validators/chartParamsValidator.ts +134 -0
- package/src/base/validators/elementValidator.ts +14 -0
- package/src/base/validators/pluginsValidator.ts +15 -0
- package/src/defaults.ts +232 -226
- package/src/defineGridPlugin.ts +3 -3
- package/src/defineMultiGridPlugin.ts +3 -3
- package/src/defineMultiValuePlugin.ts +3 -3
- package/src/defineNoneDataPlugin.ts +4 -4
- package/src/defineRelationshipPlugin.ts +3 -3
- package/src/defineSeriesPlugin.ts +3 -3
- package/src/defineTreePlugin.ts +3 -3
- package/src/grid/{computeGridData.ts → computedDataFn.ts} +129 -134
- package/src/grid/{createGridContextObserver.ts → contextObserverCallback.ts} +155 -155
- package/src/grid/dataFormatterValidator.ts +9 -0
- package/src/grid/dataValidator.ts +9 -0
- package/src/index.ts +20 -21
- package/src/multiGrid/{computeMultiGridData.ts → computedDataFn.ts} +123 -130
- package/src/multiGrid/{createMultiGridContextObserver.ts → contextObserverCallback.ts} +41 -41
- package/src/multiGrid/dataFormatterValidator.ts +9 -0
- package/src/multiGrid/dataValidator.ts +9 -0
- package/src/multiValue/{computeMultiValueData.ts → computedDataFn.ts} +176 -179
- package/src/multiValue/{createMultiValueContextObserver.ts → contextObserverCallback.ts} +12 -12
- package/src/multiValue/dataFormatterValidator.ts +9 -0
- package/src/multiValue/dataValidator.ts +9 -0
- package/src/relationship/{computeRelationshipData.ts → computedDataFn.ts} +125 -118
- package/src/relationship/{createRelationshipContextObserver.ts → contextObserverCallback.ts} +12 -12
- package/src/relationship/dataFormatterValidator.ts +9 -0
- package/src/relationship/dataValidator.ts +9 -0
- package/src/series/{computeSeriesData.ts → computedDataFn.ts} +88 -90
- package/src/series/{createSeriesContextObserver.ts → contextObserverCallback.ts} +100 -93
- package/src/series/dataFormatterValidator.ts +9 -0
- package/src/series/dataValidator.ts +9 -0
- package/src/tree/{computeTreeData.ts → computedDataFn.ts} +130 -132
- package/src/tree/{createTreeContextObserver.ts → contextObserverCallback.ts} +61 -61
- package/src/tree/dataFormatterValidator.ts +9 -0
- package/src/tree/dataValidator.ts +9 -0
- package/src/utils/commonUtils.ts +54 -50
- package/src/utils/d3Utils.ts +108 -108
- package/src/utils/errorMessage.ts +43 -0
- package/src/{grid → utils}/gridObservables.ts +611 -614
- package/src/utils/index.ts +10 -4
- package/src/{multiGrid → utils}/multiGridObservables.ts +366 -365
- package/src/utils/observables.ts +218 -202
- package/src/utils/orbchartsUtils.ts +352 -349
- package/src/{series → utils}/seriesObservables.ts +175 -175
- package/src/{tree → utils}/treeObservables.ts +94 -94
- package/src/utils/validator.ts +126 -0
- package/tsconfig.base.json +13 -13
- package/tsconfig.json +2 -2
- package/vite-env.d.ts +7 -0
- package/vite.config.js +22 -22
- package/dist/src/grid/computeGridData.d.ts +0 -6
- package/dist/src/grid/createGridContextObserver.d.ts +0 -3
- package/dist/src/multiGrid/computeMultiGridData.d.ts +0 -3
- package/dist/src/multiGrid/createMultiGridContextObserver.d.ts +0 -3
- package/dist/src/multiValue/computeMultiValueData.d.ts +0 -3
- package/dist/src/multiValue/createMultiValueContextObserver.d.ts +0 -3
- package/dist/src/relationship/computeRelationshipData.d.ts +0 -3
- package/dist/src/relationship/createRelationshipContextObserver.d.ts +0 -3
- package/dist/src/series/computeSeriesData.d.ts +0 -3
- package/dist/src/series/createSeriesContextObserver.d.ts +0 -3
- package/dist/src/tree/computeTreeData.d.ts +0 -3
- package/dist/src/tree/createTreeContextObserver.d.ts +0 -3
- package/dist/src/types/Axis.d.ts +0 -1
- package/dist/src/types/Chart.d.ts +0 -45
- package/dist/src/types/ChartParams.d.ts +0 -36
- package/dist/src/types/ComputedData.d.ts +0 -42
- package/dist/src/types/ComputedDataGrid.d.ts +0 -5
- package/dist/src/types/ComputedDataMultiGrid.d.ts +0 -3
- package/dist/src/types/ComputedDataMultiValue.d.ts +0 -6
- package/dist/src/types/ComputedDataRelationship.d.ts +0 -18
- package/dist/src/types/ComputedDataSeries.d.ts +0 -5
- package/dist/src/types/ComputedDataTree.d.ts +0 -7
- package/dist/src/types/ContextObserver.d.ts +0 -28
- package/dist/src/types/ContextObserverGrid.d.ts +0 -41
- package/dist/src/types/ContextObserverMultiGrid.d.ts +0 -15
- package/dist/src/types/ContextObserverMultiValue.d.ts +0 -4
- package/dist/src/types/ContextObserverRelationship.d.ts +0 -4
- package/dist/src/types/ContextObserverSeries.d.ts +0 -27
- package/dist/src/types/ContextObserverTree.d.ts +0 -11
- package/dist/src/types/ContextSubject.d.ts +0 -15
- package/dist/src/types/Data.d.ts +0 -19
- package/dist/src/types/DataFormatter.d.ts +0 -41
- package/dist/src/types/DataFormatterGrid.d.ts +0 -34
- package/dist/src/types/DataFormatterMultiGrid.d.ts +0 -20
- package/dist/src/types/DataFormatterMultiValue.d.ts +0 -18
- package/dist/src/types/DataFormatterRelationship.d.ts +0 -10
- package/dist/src/types/DataFormatterSeries.d.ts +0 -19
- package/dist/src/types/DataFormatterTree.d.ts +0 -7
- package/dist/src/types/DataGrid.d.ts +0 -6
- package/dist/src/types/DataMultiGrid.d.ts +0 -6
- package/dist/src/types/DataMultiValue.d.ts +0 -7
- package/dist/src/types/DataRelationship.d.ts +0 -21
- package/dist/src/types/DataSeries.d.ts +0 -6
- package/dist/src/types/DataTree.d.ts +0 -15
- package/dist/src/types/Event.d.ts +0 -56
- package/dist/src/types/Layout.d.ts +0 -8
- package/dist/src/types/Padding.d.ts +0 -6
- package/dist/src/types/Plugin.d.ts +0 -37
- package/dist/src/types/TransformData.d.ts +0 -8
- package/dist/src/types/index.d.ts +0 -37
- package/src/types/Axis.ts +0 -1
- package/src/types/Chart.ts +0 -54
- package/src/types/ChartParams.ts +0 -51
- package/src/types/ComputedData.ts +0 -84
- package/src/types/ComputedDataGrid.ts +0 -14
- package/src/types/ComputedDataMultiGrid.ts +0 -3
- package/src/types/ComputedDataMultiValue.ts +0 -9
- package/src/types/ComputedDataRelationship.ts +0 -20
- package/src/types/ComputedDataSeries.ts +0 -8
- package/src/types/ComputedDataTree.ts +0 -20
- package/src/types/ContextObserver.ts +0 -38
- package/src/types/ContextObserverGrid.ts +0 -43
- package/src/types/ContextObserverMultiGrid.ts +0 -17
- package/src/types/ContextObserverMultiValue.ts +0 -5
- package/src/types/ContextObserverRelationship.ts +0 -5
- package/src/types/ContextObserverSeries.ts +0 -29
- package/src/types/ContextObserverTree.ts +0 -11
- package/src/types/ContextSubject.ts +0 -18
- package/src/types/Data.ts +0 -45
- package/src/types/DataFormatter.ts +0 -74
- package/src/types/DataFormatterGrid.ts +0 -68
- package/src/types/DataFormatterMultiGrid.ts +0 -45
- package/src/types/DataFormatterMultiValue.ts +0 -24
- package/src/types/DataFormatterRelationship.ts +0 -26
- package/src/types/DataFormatterSeries.ts +0 -20
- package/src/types/DataFormatterTree.ts +0 -12
- package/src/types/DataGrid.ts +0 -11
- package/src/types/DataMultiGrid.ts +0 -7
- package/src/types/DataMultiValue.ts +0 -12
- package/src/types/DataRelationship.ts +0 -28
- package/src/types/DataSeries.ts +0 -11
- package/src/types/DataTree.ts +0 -20
- package/src/types/Event.ts +0 -153
- package/src/types/Layout.ts +0 -12
- package/src/types/Padding.ts +0 -6
- package/src/types/Plugin.ts +0 -60
- package/src/types/TransformData.ts +0 -8
- package/src/types/index.ts +0 -37
- /package/dist/src/{multiValue → utils}/multiValueObservables.d.ts +0 -0
- /package/dist/src/{relationship → utils}/relationshipObservables.d.ts +0 -0
- /package/src/{multiValue → utils}/multiValueObservables.ts +0 -0
- /package/src/{relationship → utils}/relationshipObservables.ts +0 -0
@@ -1,349 +1,352 @@
|
|
1
|
-
import * as d3 from 'd3'
|
2
|
-
import type {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
34
|
-
|
35
|
-
}
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
const
|
143
|
-
.
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
//
|
180
|
-
|
181
|
-
|
182
|
-
//
|
183
|
-
|
184
|
-
|
185
|
-
//
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
//
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
}
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
]
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
//
|
224
|
-
// const
|
225
|
-
// const
|
226
|
-
//
|
227
|
-
|
228
|
-
//
|
229
|
-
//
|
230
|
-
|
231
|
-
//
|
232
|
-
//
|
233
|
-
//
|
234
|
-
//
|
235
|
-
//
|
236
|
-
//
|
237
|
-
//
|
238
|
-
|
239
|
-
//
|
240
|
-
//
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
const
|
264
|
-
const
|
265
|
-
|
266
|
-
const
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
//
|
288
|
-
// const
|
289
|
-
// const
|
290
|
-
// const
|
291
|
-
// const
|
292
|
-
|
293
|
-
//
|
294
|
-
//
|
295
|
-
|
296
|
-
//
|
297
|
-
//
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
const
|
312
|
-
const
|
313
|
-
|
314
|
-
const
|
315
|
-
const
|
316
|
-
const
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
//
|
332
|
-
//
|
333
|
-
//
|
334
|
-
//
|
335
|
-
//
|
336
|
-
//
|
337
|
-
//
|
338
|
-
//
|
339
|
-
//
|
340
|
-
//
|
341
|
-
//
|
342
|
-
//
|
343
|
-
//
|
344
|
-
//
|
345
|
-
|
346
|
-
//
|
347
|
-
//
|
348
|
-
|
349
|
-
|
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
|
+
DataFormatterContainer,
|
17
|
+
SeriesDirection,
|
18
|
+
DataFormatterGridGrid,
|
19
|
+
SeriesContainerPosition,
|
20
|
+
GridContainerPosition,
|
21
|
+
Layout
|
22
|
+
} from '../../lib/core-types'
|
23
|
+
import { isPlainObject } from './commonUtils'
|
24
|
+
|
25
|
+
export function formatValueToLabel (value: any, valueFormatter: string | ((text: d3.NumberValue) => string)) {
|
26
|
+
if (valueFormatter! instanceof Function == true) {
|
27
|
+
return (valueFormatter as ((text: d3.NumberValue) => string))(value)
|
28
|
+
}
|
29
|
+
return d3.format(valueFormatter as string)!(value)
|
30
|
+
}
|
31
|
+
|
32
|
+
export function createDefaultDatumId (chartTypeOrPrefix: string, levelOneIndex: number, levelTwoIndex: number, levelThreeIndex?: number) {
|
33
|
+
let text = `${chartTypeOrPrefix}_${levelOneIndex}_${levelTwoIndex}`
|
34
|
+
if (levelThreeIndex != null) {
|
35
|
+
text += `_${levelThreeIndex}`
|
36
|
+
}
|
37
|
+
return text
|
38
|
+
}
|
39
|
+
|
40
|
+
export function createDefaultSeriesLabel (chartTypeOrPrefix: string, seriesIndex: number) {
|
41
|
+
return `${chartTypeOrPrefix}_series${seriesIndex}`
|
42
|
+
}
|
43
|
+
|
44
|
+
export function createDefaultGroupLabel (chartTypeOrPrefix: string, groupIndex: number) {
|
45
|
+
return `${chartTypeOrPrefix}_group${groupIndex}`
|
46
|
+
}
|
47
|
+
|
48
|
+
export function createGridSeriesLabels ({ transposedDataGrid, dataFormatterGrid, chartType = 'grid' }: {
|
49
|
+
transposedDataGrid: DataGridDatum[][],
|
50
|
+
dataFormatterGrid: DataFormatterGridGrid
|
51
|
+
chartType?: ChartType
|
52
|
+
}) {
|
53
|
+
const labels = dataFormatterGrid.seriesDirection === 'row'
|
54
|
+
? dataFormatterGrid.rowLabels
|
55
|
+
: dataFormatterGrid.columnLabels
|
56
|
+
return transposedDataGrid.map((_, rowIndex) => {
|
57
|
+
return labels[rowIndex] != null
|
58
|
+
? labels[rowIndex]
|
59
|
+
: createDefaultSeriesLabel(chartType, rowIndex)
|
60
|
+
})
|
61
|
+
}
|
62
|
+
|
63
|
+
export function createMultiGridSeriesLabels ({ transposedDataGrid, dataFormatterGrid, chartType = 'multiGrid', gridIndex = 0 }: {
|
64
|
+
transposedDataGrid: DataGridDatum[][],
|
65
|
+
dataFormatterGrid: DataFormatterGridGrid
|
66
|
+
chartType?: ChartType
|
67
|
+
gridIndex?: number
|
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}_grid${gridIndex}`, rowIndex)
|
76
|
+
})
|
77
|
+
}
|
78
|
+
|
79
|
+
export function createGridGroupLabels ({ transposedDataGrid, dataFormatterGrid, chartType = 'grid' }: {
|
80
|
+
transposedDataGrid: DataGridDatum[][],
|
81
|
+
dataFormatterGrid: DataFormatterGridGrid
|
82
|
+
chartType?: ChartType
|
83
|
+
}) {
|
84
|
+
if (transposedDataGrid[0] == null) {
|
85
|
+
return []
|
86
|
+
}
|
87
|
+
const labels = dataFormatterGrid.seriesDirection === 'row'
|
88
|
+
? dataFormatterGrid.columnLabels
|
89
|
+
: dataFormatterGrid.rowLabels
|
90
|
+
return transposedDataGrid[0].map((_, columnLabels) => {
|
91
|
+
return labels[columnLabels] != null
|
92
|
+
? labels[columnLabels]
|
93
|
+
: createDefaultGroupLabel(chartType, columnLabels)
|
94
|
+
})
|
95
|
+
}
|
96
|
+
|
97
|
+
export function createMultiGridGroupLabels ({ transposedDataGrid, dataFormatterGrid, chartType = 'multiGrid', gridIndex = 0 }: {
|
98
|
+
transposedDataGrid: DataGridDatum[][],
|
99
|
+
dataFormatterGrid: DataFormatterGridGrid
|
100
|
+
chartType?: ChartType
|
101
|
+
gridIndex?: number
|
102
|
+
}) {
|
103
|
+
if (transposedDataGrid[0] == null) {
|
104
|
+
return []
|
105
|
+
}
|
106
|
+
const labels = dataFormatterGrid.seriesDirection === 'row'
|
107
|
+
? dataFormatterGrid.columnLabels
|
108
|
+
: dataFormatterGrid.rowLabels
|
109
|
+
return transposedDataGrid[0].map((_, columnLabels) => {
|
110
|
+
return labels[columnLabels] != null
|
111
|
+
? labels[columnLabels]
|
112
|
+
: createDefaultGroupLabel(`${chartType}_grid${gridIndex}`, columnLabels)
|
113
|
+
})
|
114
|
+
}
|
115
|
+
|
116
|
+
// 取得最小及最大值 - 數字陣列
|
117
|
+
export function getMinAndMax (data: number[]): [number, number] {
|
118
|
+
const defaultMinAndMax: [number, number] = [0, 0] // default
|
119
|
+
if (!data.length) {
|
120
|
+
return defaultMinAndMax
|
121
|
+
}
|
122
|
+
const minAndMax: [number, number] = data.reduce((prev, current) => {
|
123
|
+
// [min, max]
|
124
|
+
return [
|
125
|
+
current < prev[0] ? current : prev[0],
|
126
|
+
current > prev[1] ? current : prev[1]
|
127
|
+
]
|
128
|
+
}, [data[0], data[0]])
|
129
|
+
return minAndMax
|
130
|
+
}
|
131
|
+
|
132
|
+
// 取得最小及最大值 - datum格式陣列資料
|
133
|
+
export function getMinAndMaxValue (data: DatumValue[]): [number, number] {
|
134
|
+
const arr = data
|
135
|
+
.filter(d => d != null && d.value != null)
|
136
|
+
.map(d => d.value )
|
137
|
+
return getMinAndMax(arr)
|
138
|
+
}
|
139
|
+
|
140
|
+
// 取得最小及最大值 - Series Data
|
141
|
+
export function getMinAndMaxSeries (data: DataSeries): [number, number] {
|
142
|
+
const flatData: (DataSeriesValue | DataSeriesDatum)[] = data[0] && Array.isArray((data as (DataSeriesValue | DataSeriesDatum)[][])[0])
|
143
|
+
? data.flat()
|
144
|
+
: data as (DataSeriesValue | DataSeriesDatum)[]
|
145
|
+
const arr = flatData
|
146
|
+
.filter(d => (d == null || (isPlainObject(d) && (d as DataSeriesDatum).value == null)) === false) // 過濾掉null &
|
147
|
+
.map(d => typeof d === 'number' ? d : d.value )
|
148
|
+
return getMinAndMax(arr)
|
149
|
+
}
|
150
|
+
|
151
|
+
// 取得最小及最大值 - Grid Data
|
152
|
+
export function getMinAndMaxGrid (data: DataGrid): [number, number] {
|
153
|
+
const flatData: (DataGridValue | DataGridDatum)[] = data.flat()
|
154
|
+
const arr = flatData
|
155
|
+
.filter(d => (d == null || (isPlainObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
|
156
|
+
.map(d => typeof d === 'number' ? d : d.value )
|
157
|
+
return getMinAndMax(arr)
|
158
|
+
}
|
159
|
+
|
160
|
+
// 取得最小及最大值 - MultiGrid Data
|
161
|
+
export function getMinAndMaxMultiGrid (data: DataMultiGrid): [number, number] {
|
162
|
+
const flatData: (DataGridValue | DataGridDatum)[] = data.flat().flat()
|
163
|
+
const arr = flatData
|
164
|
+
.filter(d => (d == null || (isPlainObject(d) && (d as DataGridDatum).value == null)) === false) // 過濾掉null
|
165
|
+
.map(d => typeof d === 'number' ? d : d.value )
|
166
|
+
return getMinAndMax(arr)
|
167
|
+
}
|
168
|
+
|
169
|
+
// 取得最小及最大值 - MultiValue Data
|
170
|
+
export function getMinAndMaxMultiValue (data: DataMultiValue, valueIndex: number = 2): [number, number] {
|
171
|
+
const flatData: (DataMultiValueDatum | DataMultiValueValue)[] = data.flat().filter((d, i) => i == valueIndex)
|
172
|
+
const arr = flatData
|
173
|
+
.filter(d => (d == null || (isPlainObject(d) && (d as DataMultiValueDatum).value == null)) === false) // 過濾掉null
|
174
|
+
.map(d => typeof d === 'number' ? d : d.value )
|
175
|
+
return getMinAndMax(arr)
|
176
|
+
}
|
177
|
+
|
178
|
+
// @Q@ 待處理
|
179
|
+
// // 取得最小及最大值 - Relationship Data
|
180
|
+
// export function getMinAndMaxRelationship (data: DataRelationship, target: 'nodes' | 'edges' = 'nodes'): [number, number] {
|
181
|
+
|
182
|
+
// }
|
183
|
+
|
184
|
+
// @Q@ 待處理
|
185
|
+
// // 取得最小及最大值 - Tree Data
|
186
|
+
// export function getMinAndMaxTree (data: DataTree): [number, number] {
|
187
|
+
|
188
|
+
// }
|
189
|
+
|
190
|
+
// 轉置成seriesDirection為main的陣列格式
|
191
|
+
export function transposeData<T> (seriesDirection: SeriesDirection, data: T[][]): T[][] {
|
192
|
+
if (seriesDirection === 'row') {
|
193
|
+
return Object.assign([], data)
|
194
|
+
}
|
195
|
+
// 取得原始陣列的維度
|
196
|
+
const rows = data.length;
|
197
|
+
const cols = data.reduce((prev, current) => {
|
198
|
+
return Math.max(prev, current.length)
|
199
|
+
}, 0)
|
200
|
+
|
201
|
+
// 初始化轉換後的陣列
|
202
|
+
const transposedArray = new Array(cols).fill(null).map(() => new Array(rows).fill(null))
|
203
|
+
|
204
|
+
// 遍歷原始陣列,進行轉換
|
205
|
+
for (let i = 0; i < rows; i++) {
|
206
|
+
for (let j = 0; j < cols; j++) {
|
207
|
+
transposedArray[j][i] = data[i][j]
|
208
|
+
}
|
209
|
+
}
|
210
|
+
|
211
|
+
return transposedArray
|
212
|
+
}
|
213
|
+
|
214
|
+
|
215
|
+
export function seriesColorPredicate (seriesIndex: number, chartParams: ChartParams) {
|
216
|
+
return seriesIndex < chartParams.colors[chartParams.colorScheme].series.length
|
217
|
+
? chartParams.colors[chartParams.colorScheme].series[seriesIndex]
|
218
|
+
: chartParams.colors[chartParams.colorScheme].series[
|
219
|
+
seriesIndex % chartParams.colors[chartParams.colorScheme].series.length
|
220
|
+
]
|
221
|
+
}
|
222
|
+
|
223
|
+
// export function calcSeriesContainerPosition (layout: Layout, container: DataFormatterContainer, rowIndex: number, columnIndex: number) {
|
224
|
+
// const { gap, rowAmount, columnAmount } = container
|
225
|
+
// const width = (layout.width - (gap * (columnAmount - 1))) / columnAmount
|
226
|
+
// const height = (layout.height - (gap * (rowAmount - 1))) / rowAmount
|
227
|
+
// const x = columnIndex * width + (columnIndex * gap)
|
228
|
+
// const y = rowIndex * height + (rowIndex * gap)
|
229
|
+
// // const translate: [number, number] = [x, y]
|
230
|
+
|
231
|
+
// return {
|
232
|
+
// // translate,
|
233
|
+
// startX: x,
|
234
|
+
// startY: y,
|
235
|
+
// centerX: x + width / 2,
|
236
|
+
// centerY: y + height / 2,
|
237
|
+
// width,
|
238
|
+
// height
|
239
|
+
// }
|
240
|
+
// }
|
241
|
+
|
242
|
+
// 計算預設欄列數量
|
243
|
+
// 規則1.rowAmount*columnAmount要大於或等於amount,並且數字要盡可能小
|
244
|
+
// 規則2.columnAmount要大於或等於rowAmount,並且數字要盡可能小
|
245
|
+
function calcGridDimensions (amount: number): { rowAmount: number; columnAmount: number } {
|
246
|
+
let rowAmount = Math.floor(Math.sqrt(amount))
|
247
|
+
let columnAmount = Math.ceil(amount / rowAmount)
|
248
|
+
while (rowAmount * columnAmount < amount) {
|
249
|
+
columnAmount++
|
250
|
+
}
|
251
|
+
return { rowAmount, columnAmount }
|
252
|
+
}
|
253
|
+
|
254
|
+
export function calcSeriesContainerLayout (layout: Layout, container: DataFormatterContainer, amount: number): SeriesContainerPosition[] {
|
255
|
+
const { gap } = container
|
256
|
+
const { rowAmount, columnAmount } = (container.rowAmount * container.columnAmount) >= amount
|
257
|
+
// 如果container設定的rowAmount和columnAmount的乘積大於或等於amount,則使用目前設定
|
258
|
+
? container
|
259
|
+
// 否則計算一個合適的預設值
|
260
|
+
: calcGridDimensions(amount)
|
261
|
+
|
262
|
+
return new Array(amount).fill(null).map((_, index) => {
|
263
|
+
const columnIndex = index % columnAmount
|
264
|
+
const rowIndex = Math.floor(index / columnAmount)
|
265
|
+
|
266
|
+
const width = (layout.width - (gap * (columnAmount - 1))) / columnAmount
|
267
|
+
const height = (layout.height - (gap * (rowAmount - 1))) / rowAmount
|
268
|
+
const x = columnIndex * width + (columnIndex * gap)
|
269
|
+
const y = rowIndex * height + (rowIndex * gap)
|
270
|
+
// const translate: [number, number] = [x, y]
|
271
|
+
|
272
|
+
return {
|
273
|
+
slotIndex: index,
|
274
|
+
rowIndex,
|
275
|
+
columnIndex,
|
276
|
+
// translate,
|
277
|
+
startX: x,
|
278
|
+
startY: y,
|
279
|
+
centerX: x + width / 2,
|
280
|
+
centerY: y + height / 2,
|
281
|
+
width,
|
282
|
+
height
|
283
|
+
}
|
284
|
+
})
|
285
|
+
}
|
286
|
+
|
287
|
+
// export function calcGridContainerPosition (layout: Layout, container: DataFormatterContainer, rowIndex: number, columnIndex: number) {
|
288
|
+
// const { gap, rowAmount, columnAmount } = container
|
289
|
+
// const width = (layout.width - (gap * (columnAmount - 1))) / columnAmount
|
290
|
+
// const height = (layout.height - (gap * (rowAmount - 1))) / rowAmount
|
291
|
+
// const x = columnIndex * width + (columnIndex * gap)
|
292
|
+
// const y = rowIndex * height + (rowIndex * gap)
|
293
|
+
// const translate: [number, number] = [x, y]
|
294
|
+
// const scale: [number, number] = [width / layout.width, height / layout.height]
|
295
|
+
|
296
|
+
// return {
|
297
|
+
// translate,
|
298
|
+
// scale
|
299
|
+
// }
|
300
|
+
// }
|
301
|
+
|
302
|
+
export function calcGridContainerLayout (layout: Layout, container: DataFormatterContainer, amount: number): GridContainerPosition[] {
|
303
|
+
const { gap } = container
|
304
|
+
const { rowAmount, columnAmount } = (container.rowAmount * container.columnAmount) >= amount
|
305
|
+
// 如果container設定的rowAmount和columnAmount的乘積大於或等於amount,則使用目前設定
|
306
|
+
? container
|
307
|
+
// 否則計算一個合適的預設值
|
308
|
+
: calcGridDimensions(amount)
|
309
|
+
|
310
|
+
return new Array(amount).fill(null).map((_, index) => {
|
311
|
+
const columnIndex = index % columnAmount
|
312
|
+
const rowIndex = Math.floor(index / columnAmount)
|
313
|
+
|
314
|
+
const width = (layout.width - (gap * (columnAmount - 1))) / columnAmount
|
315
|
+
const height = (layout.height - (gap * (rowAmount - 1))) / rowAmount
|
316
|
+
const x = columnIndex * width + (columnIndex * gap)
|
317
|
+
const y = rowIndex * height + (rowIndex * gap)
|
318
|
+
const translate: [number, number] = [x, y]
|
319
|
+
const scale: [number, number] = [width / layout.width, height / layout.height]
|
320
|
+
|
321
|
+
return {
|
322
|
+
slotIndex: index,
|
323
|
+
rowIndex,
|
324
|
+
columnIndex,
|
325
|
+
translate,
|
326
|
+
scale
|
327
|
+
}
|
328
|
+
})
|
329
|
+
}
|
330
|
+
|
331
|
+
// // multiGrid datum color
|
332
|
+
// export function multiGridColorPredicate ({ seriesIndex, groupIndex, data, chartParams }: {
|
333
|
+
// seriesIndex: number
|
334
|
+
// groupIndex: number
|
335
|
+
// data: ComputedDataMultiGrid
|
336
|
+
// chartParams: ChartParams
|
337
|
+
// }) {
|
338
|
+
// // 累加前面的grid的seriesIndex
|
339
|
+
// const accSeriesIndex = data.reduce((prev, current) => {
|
340
|
+
// if (current[0] && current[0][0] && groupIndex > current[0][0].gridIndex) {
|
341
|
+
// return prev + current[0].length
|
342
|
+
// } else if (current[0] && current[0][0] && groupIndex == current[0][0].gridIndex) {
|
343
|
+
// return prev + seriesIndex
|
344
|
+
// } else {
|
345
|
+
// return prev
|
346
|
+
// }
|
347
|
+
// }, 0)
|
348
|
+
|
349
|
+
// return seriesColorPredicate(accSeriesIndex, chartParams)
|
350
|
+
// }
|
351
|
+
|
352
|
+
|