@orbcharts/core 3.0.5 → 3.0.6
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.
- package/LICENSE +200 -200
- package/dist/orbcharts-core.es.js +2217 -2164
- package/dist/orbcharts-core.umd.js +5 -5
- package/lib/core-types.ts +7 -7
- package/package.json +46 -46
- package/src/AbstractChart.ts +57 -57
- package/src/GridChart.ts +24 -24
- package/src/MultiGridChart.ts +24 -24
- package/src/MultiValueChart.ts +24 -24
- package/src/RelationshipChart.ts +24 -24
- package/src/SeriesChart.ts +24 -24
- package/src/TreeChart.ts +24 -24
- package/src/base/createBaseChart.ts +524 -524
- package/src/base/createBasePlugin.ts +154 -154
- package/src/base/validators/chartOptionsValidator.ts +23 -23
- package/src/base/validators/chartParamsValidator.ts +133 -133
- package/src/base/validators/elementValidator.ts +13 -13
- package/src/base/validators/pluginsValidator.ts +14 -14
- package/src/defaults.ts +284 -284
- 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/computedDataFn.ts +129 -129
- package/src/grid/contextObserverCallback.ts +209 -201
- package/src/grid/dataFormatterValidator.ts +125 -125
- package/src/grid/dataValidator.ts +12 -12
- package/src/grid/gridObservables.ts +698 -694
- package/src/index.ts +20 -20
- package/src/multiGrid/computedDataFn.ts +123 -123
- package/src/multiGrid/contextObserverCallback.ts +109 -75
- package/src/multiGrid/dataFormatterValidator.ts +120 -120
- package/src/multiGrid/dataValidator.ts +12 -12
- package/src/multiGrid/multiGridObservables.ts +366 -357
- package/src/multiValue/computedDataFn.ts +113 -113
- package/src/multiValue/contextObserverCallback.ts +328 -328
- package/src/multiValue/dataFormatterValidator.ts +94 -94
- package/src/multiValue/dataValidator.ts +12 -12
- package/src/multiValue/multiValueObservables.ts +865 -865
- package/src/relationship/computedDataFn.ts +159 -159
- package/src/relationship/contextObserverCallback.ts +80 -80
- package/src/relationship/dataFormatterValidator.ts +13 -13
- package/src/relationship/dataValidator.ts +13 -13
- package/src/relationship/relationshipObservables.ts +84 -84
- package/src/series/computedDataFn.ts +88 -88
- package/src/series/contextObserverCallback.ts +132 -132
- package/src/series/dataFormatterValidator.ts +46 -46
- package/src/series/dataValidator.ts +12 -12
- package/src/series/seriesObservables.ts +209 -209
- package/src/tree/computedDataFn.ts +129 -129
- package/src/tree/contextObserverCallback.ts +58 -58
- package/src/tree/dataFormatterValidator.ts +13 -13
- package/src/tree/dataValidator.ts +13 -13
- package/src/tree/treeObservables.ts +105 -105
- package/src/utils/commonUtils.ts +55 -55
- package/src/utils/d3Scale.ts +198 -198
- package/src/utils/errorMessage.ts +40 -40
- package/src/utils/index.ts +3 -3
- package/src/utils/observables.ts +308 -308
- package/src/utils/orbchartsUtils.ts +396 -396
- package/src/utils/validator.ts +126 -126
- package/tsconfig.base.json +13 -13
- package/tsconfig.json +2 -2
- package/vite-env.d.ts +6 -6
- package/vite.config.js +22 -22
@@ -1,113 +1,113 @@
|
|
1
|
-
import type { DataMultiValueDatum, ComputedDataFn, ComputedDatumMultiValue } from '../../lib/core-types'
|
2
|
-
import { createDefaultCategoryLabel, createDefaultDatumId, seriesColorPredicate } from '../utils/orbchartsUtils'
|
3
|
-
import { isPlainObject } from '../utils'
|
4
|
-
|
5
|
-
export const computedDataFn: ComputedDataFn<'multiValue'> = (context) => {
|
6
|
-
const { data, dataFormatter, chartParams } = context
|
7
|
-
if (!data.length) {
|
8
|
-
return []
|
9
|
-
}
|
10
|
-
|
11
|
-
const defaultCategoryLabel = createDefaultCategoryLabel()
|
12
|
-
|
13
|
-
let computedDataMultiValue: ComputedDatumMultiValue[][] = []
|
14
|
-
|
15
|
-
try {
|
16
|
-
const dataMultiValue: DataMultiValueDatum[] = data.map((d, i) => {
|
17
|
-
if (Array.isArray(d)) {
|
18
|
-
return {
|
19
|
-
id: '',
|
20
|
-
label: '',
|
21
|
-
description: '',
|
22
|
-
// tooltipContent: '',
|
23
|
-
data: {},
|
24
|
-
categoryLabel: defaultCategoryLabel,
|
25
|
-
value: d
|
26
|
-
}
|
27
|
-
} else if (isPlainObject(d)) {
|
28
|
-
return {
|
29
|
-
id: d.id ?? '',
|
30
|
-
label: d.label ?? '',
|
31
|
-
description: d.description ?? '',
|
32
|
-
// tooltipContent: _d.tooltipContent ?? '',
|
33
|
-
data: d.data ?? {},
|
34
|
-
categoryLabel: d.categoryLabel ?? defaultCategoryLabel,
|
35
|
-
value: d.value
|
36
|
-
}
|
37
|
-
} else {
|
38
|
-
return {
|
39
|
-
id: '',
|
40
|
-
label: '',
|
41
|
-
description: '',
|
42
|
-
// tooltipContent: '',
|
43
|
-
data: {},
|
44
|
-
categoryLabel: defaultCategoryLabel,
|
45
|
-
value: []
|
46
|
-
}
|
47
|
-
}
|
48
|
-
})
|
49
|
-
|
50
|
-
const categoryLabels = (() => {
|
51
|
-
// 先使用 dataFormatter.categoryLabels
|
52
|
-
const CategoryLabelsSet = new Set(dataFormatter.categoryLabels)
|
53
|
-
// 再加入 datum 中的 categoryLabel
|
54
|
-
for (let datum of dataMultiValue) {
|
55
|
-
const categoryLabel = datum.categoryLabel ?? defaultCategoryLabel
|
56
|
-
CategoryLabelsSet.add(categoryLabel) // 不重覆
|
57
|
-
}
|
58
|
-
return Array.from(CategoryLabelsSet)
|
59
|
-
})()
|
60
|
-
|
61
|
-
// <categoryLabel, categoryIndex>
|
62
|
-
const CategoryIndexMap = new Map<string, number>(
|
63
|
-
categoryLabels.map((label, index) => [label, index])
|
64
|
-
)
|
65
|
-
|
66
|
-
|
67
|
-
// let index = 0
|
68
|
-
|
69
|
-
dataMultiValue.forEach((d, i) => {
|
70
|
-
// const currentIndex = index
|
71
|
-
// index++
|
72
|
-
|
73
|
-
const defaultId = createDefaultDatumId(dataFormatter.type, i)
|
74
|
-
|
75
|
-
const categoryIndex = CategoryIndexMap.get(d.categoryLabel) ?? 0
|
76
|
-
|
77
|
-
const color = seriesColorPredicate(categoryIndex, chartParams)
|
78
|
-
|
79
|
-
const computedDatum: ComputedDatumMultiValue = {
|
80
|
-
id: d.id ? d.id : defaultId,
|
81
|
-
index: i,
|
82
|
-
label: d.label ? d.label : defaultId,
|
83
|
-
description: d.description ?? '',
|
84
|
-
// tooltipContent: _d.tooltipContent ? _d.tooltipContent : dataFormatter.tooltipContentFormat(_d, i, _i, context),
|
85
|
-
data: d.data,
|
86
|
-
// datumIndex: i,
|
87
|
-
value: d.value,
|
88
|
-
categoryIndex,
|
89
|
-
categoryLabel: d.categoryLabel,
|
90
|
-
xValueIndex: dataFormatter.xAxis.valueIndex,
|
91
|
-
yValueIndex: dataFormatter.yAxis.valueIndex,
|
92
|
-
// valueLabel: formatValueToLabel(_d.value, dataFormatter.multiValue[_i].valueFormat),
|
93
|
-
// axis: _i == 0 ? xScale(_d.value) : yScale(_d.value),
|
94
|
-
visible: true, // 先給預設值
|
95
|
-
color,
|
96
|
-
// _visibleValue: d.value // 預設和value相同
|
97
|
-
}
|
98
|
-
|
99
|
-
computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
|
100
|
-
|
101
|
-
// 依 categoryIndex 分組
|
102
|
-
if (!computedDataMultiValue[categoryIndex]) {
|
103
|
-
computedDataMultiValue[categoryIndex] = []
|
104
|
-
}
|
105
|
-
computedDataMultiValue[categoryIndex].push(computedDatum)
|
106
|
-
})
|
107
|
-
} catch (e) {
|
108
|
-
// console.error(e)
|
109
|
-
throw Error(e)
|
110
|
-
}
|
111
|
-
|
112
|
-
return computedDataMultiValue
|
113
|
-
}
|
1
|
+
import type { DataMultiValueDatum, ComputedDataFn, ComputedDatumMultiValue } from '../../lib/core-types'
|
2
|
+
import { createDefaultCategoryLabel, createDefaultDatumId, seriesColorPredicate } from '../utils/orbchartsUtils'
|
3
|
+
import { isPlainObject } from '../utils'
|
4
|
+
|
5
|
+
export const computedDataFn: ComputedDataFn<'multiValue'> = (context) => {
|
6
|
+
const { data, dataFormatter, chartParams } = context
|
7
|
+
if (!data.length) {
|
8
|
+
return []
|
9
|
+
}
|
10
|
+
|
11
|
+
const defaultCategoryLabel = createDefaultCategoryLabel()
|
12
|
+
|
13
|
+
let computedDataMultiValue: ComputedDatumMultiValue[][] = []
|
14
|
+
|
15
|
+
try {
|
16
|
+
const dataMultiValue: DataMultiValueDatum[] = data.map((d, i) => {
|
17
|
+
if (Array.isArray(d)) {
|
18
|
+
return {
|
19
|
+
id: '',
|
20
|
+
label: '',
|
21
|
+
description: '',
|
22
|
+
// tooltipContent: '',
|
23
|
+
data: {},
|
24
|
+
categoryLabel: defaultCategoryLabel,
|
25
|
+
value: d
|
26
|
+
}
|
27
|
+
} else if (isPlainObject(d)) {
|
28
|
+
return {
|
29
|
+
id: d.id ?? '',
|
30
|
+
label: d.label ?? '',
|
31
|
+
description: d.description ?? '',
|
32
|
+
// tooltipContent: _d.tooltipContent ?? '',
|
33
|
+
data: d.data ?? {},
|
34
|
+
categoryLabel: d.categoryLabel ?? defaultCategoryLabel,
|
35
|
+
value: d.value
|
36
|
+
}
|
37
|
+
} else {
|
38
|
+
return {
|
39
|
+
id: '',
|
40
|
+
label: '',
|
41
|
+
description: '',
|
42
|
+
// tooltipContent: '',
|
43
|
+
data: {},
|
44
|
+
categoryLabel: defaultCategoryLabel,
|
45
|
+
value: []
|
46
|
+
}
|
47
|
+
}
|
48
|
+
})
|
49
|
+
|
50
|
+
const categoryLabels = (() => {
|
51
|
+
// 先使用 dataFormatter.categoryLabels
|
52
|
+
const CategoryLabelsSet = new Set(dataFormatter.categoryLabels)
|
53
|
+
// 再加入 datum 中的 categoryLabel
|
54
|
+
for (let datum of dataMultiValue) {
|
55
|
+
const categoryLabel = datum.categoryLabel ?? defaultCategoryLabel
|
56
|
+
CategoryLabelsSet.add(categoryLabel) // 不重覆
|
57
|
+
}
|
58
|
+
return Array.from(CategoryLabelsSet)
|
59
|
+
})()
|
60
|
+
|
61
|
+
// <categoryLabel, categoryIndex>
|
62
|
+
const CategoryIndexMap = new Map<string, number>(
|
63
|
+
categoryLabels.map((label, index) => [label, index])
|
64
|
+
)
|
65
|
+
|
66
|
+
|
67
|
+
// let index = 0
|
68
|
+
|
69
|
+
dataMultiValue.forEach((d, i) => {
|
70
|
+
// const currentIndex = index
|
71
|
+
// index++
|
72
|
+
|
73
|
+
const defaultId = createDefaultDatumId(dataFormatter.type, i)
|
74
|
+
|
75
|
+
const categoryIndex = CategoryIndexMap.get(d.categoryLabel) ?? 0
|
76
|
+
|
77
|
+
const color = seriesColorPredicate(categoryIndex, chartParams)
|
78
|
+
|
79
|
+
const computedDatum: ComputedDatumMultiValue = {
|
80
|
+
id: d.id ? d.id : defaultId,
|
81
|
+
index: i,
|
82
|
+
label: d.label ? d.label : defaultId,
|
83
|
+
description: d.description ?? '',
|
84
|
+
// tooltipContent: _d.tooltipContent ? _d.tooltipContent : dataFormatter.tooltipContentFormat(_d, i, _i, context),
|
85
|
+
data: d.data,
|
86
|
+
// datumIndex: i,
|
87
|
+
value: d.value,
|
88
|
+
categoryIndex,
|
89
|
+
categoryLabel: d.categoryLabel,
|
90
|
+
xValueIndex: dataFormatter.xAxis.valueIndex,
|
91
|
+
yValueIndex: dataFormatter.yAxis.valueIndex,
|
92
|
+
// valueLabel: formatValueToLabel(_d.value, dataFormatter.multiValue[_i].valueFormat),
|
93
|
+
// axis: _i == 0 ? xScale(_d.value) : yScale(_d.value),
|
94
|
+
visible: true, // 先給預設值
|
95
|
+
color,
|
96
|
+
// _visibleValue: d.value // 預設和value相同
|
97
|
+
}
|
98
|
+
|
99
|
+
computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
|
100
|
+
|
101
|
+
// 依 categoryIndex 分組
|
102
|
+
if (!computedDataMultiValue[categoryIndex]) {
|
103
|
+
computedDataMultiValue[categoryIndex] = []
|
104
|
+
}
|
105
|
+
computedDataMultiValue[categoryIndex].push(computedDatum)
|
106
|
+
})
|
107
|
+
} catch (e) {
|
108
|
+
// console.error(e)
|
109
|
+
throw Error(e)
|
110
|
+
}
|
111
|
+
|
112
|
+
return computedDataMultiValue
|
113
|
+
}
|