@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,95 +1,152 @@
|
|
1
|
-
import {
|
2
|
-
|
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
|
-
|
1
|
+
import {
|
2
|
+
catchError,
|
3
|
+
of,
|
4
|
+
takeUntil,
|
5
|
+
map,
|
6
|
+
switchMap,
|
7
|
+
shareReplay,
|
8
|
+
startWith,
|
9
|
+
EMPTY,
|
10
|
+
Subject,
|
11
|
+
BehaviorSubject,
|
12
|
+
Observable
|
13
|
+
} from 'rxjs'
|
14
|
+
import type {
|
15
|
+
ChartType,
|
16
|
+
CreateBasePlugin,
|
17
|
+
DefinePluginConfig,
|
18
|
+
PluginInitFn,
|
19
|
+
PluginContext,
|
20
|
+
PluginEntity } from '../../lib/core-types'
|
21
|
+
import { mergeOptionsWithDefault } from '../utils'
|
22
|
+
import { createValidatorErrorMessage, createValidatorWarningMessage, createOrbChartsErrorMessage } from '../utils/errorMessage'
|
23
|
+
import { validateColumns } from '../utils/validator'
|
24
|
+
|
25
|
+
// 建立plugin實例
|
26
|
+
function createPluginEntity <T extends ChartType, PluginName, PluginParams>({ chartType, config, initFn }: {
|
27
|
+
chartType: T
|
28
|
+
config: DefinePluginConfig<PluginName, PluginParams>
|
29
|
+
initFn: PluginInitFn<T, PluginName, PluginParams>
|
30
|
+
}): PluginEntity<T, PluginName, PluginParams> {
|
31
|
+
|
32
|
+
const destroy$ = new Subject()
|
33
|
+
const EntityWeakMap = new WeakMap() // <selection, pluginEntity> 避免只移除selection而沒回收pluginEntity的memory leak
|
34
|
+
let pluginDestroyFn = () => {}
|
35
|
+
let pluginContext: PluginContext<T, PluginName, PluginParams> | undefined
|
36
|
+
const mergedDefaultParams$ = new BehaviorSubject(config.defaultParams)
|
37
|
+
const params$: Subject<Partial<typeof config.defaultParams>> = new BehaviorSubject({})
|
38
|
+
const fullParams$ = mergedDefaultParams$.pipe(
|
39
|
+
switchMap(mergedDefaultParams => {
|
40
|
+
return params$
|
41
|
+
.pipe(
|
42
|
+
takeUntil(destroy$),
|
43
|
+
map(d => {
|
44
|
+
try {
|
45
|
+
// 檢查 data$ 資料格式是否正確
|
46
|
+
const { status, columnName, expectToBe } = config.validator(d, {
|
47
|
+
validateColumns
|
48
|
+
})
|
49
|
+
if (status === 'error') {
|
50
|
+
throw new Error(createValidatorErrorMessage({
|
51
|
+
columnName,
|
52
|
+
expectToBe,
|
53
|
+
from: 'Chart.constructor'
|
54
|
+
}))
|
55
|
+
} else if (status === 'warning') {
|
56
|
+
console.warn(createValidatorWarningMessage({
|
57
|
+
columnName,
|
58
|
+
expectToBe,
|
59
|
+
from: 'Chart.constructor'
|
60
|
+
}))
|
61
|
+
}
|
62
|
+
|
63
|
+
return mergeOptionsWithDefault(d, mergedDefaultParams)
|
64
|
+
} catch (e) {
|
65
|
+
throw new Error(e.message)
|
66
|
+
}
|
67
|
+
}),
|
68
|
+
catchError((e) => {
|
69
|
+
console.error(createOrbChartsErrorMessage(e))
|
70
|
+
return EMPTY
|
71
|
+
})
|
72
|
+
)
|
73
|
+
}),
|
74
|
+
shareReplay(1)
|
75
|
+
)
|
76
|
+
|
77
|
+
// 建立plugin實例
|
78
|
+
return {
|
79
|
+
params$,
|
80
|
+
name: config.name,
|
81
|
+
chartType,
|
82
|
+
defaultParams: config.defaultParams,
|
83
|
+
layerIndex: config.layerIndex,
|
84
|
+
init () {
|
85
|
+
if (!pluginContext) {
|
86
|
+
return
|
87
|
+
}
|
88
|
+
// 執行
|
89
|
+
pluginDestroyFn = (initFn(pluginContext) ?? (() => {})) // plugin執行會回傳destroy函式
|
90
|
+
EntityWeakMap.set(pluginContext.selection, pluginContext)
|
91
|
+
},
|
92
|
+
destroy () {
|
93
|
+
pluginDestroyFn()
|
94
|
+
if (pluginContext) {
|
95
|
+
pluginContext.selection.remove()
|
96
|
+
pluginContext = undefined
|
97
|
+
}
|
98
|
+
destroy$.next(undefined)
|
99
|
+
},
|
100
|
+
setPresetParams: (presetParams: Partial<PluginParams>) => {
|
101
|
+
mergedDefaultParams$.next(mergeOptionsWithDefault(presetParams, config.defaultParams))
|
102
|
+
|
103
|
+
},
|
104
|
+
setContext: (_pluginContext: PluginContext<T, PluginName, PluginParams>) => {
|
105
|
+
pluginContext = _pluginContext
|
106
|
+
pluginContext.observer.fullParams$ = fullParams$
|
107
|
+
}
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
// 建立plugin類別
|
112
|
+
export const createBasePlugin: CreateBasePlugin = <T extends ChartType>(chartType: T) => {
|
113
|
+
|
114
|
+
// 定義plugin
|
115
|
+
return function definePlugin<PluginName, PluginParams>(config: DefinePluginConfig<PluginName, PluginParams>) {
|
116
|
+
|
117
|
+
// 定義plugin的初始化function
|
118
|
+
return function definePluginInitFn (initFn: PluginInitFn<T, PluginName, PluginParams>) {
|
119
|
+
|
120
|
+
return class Plugin {
|
121
|
+
params$: Subject<Partial<PluginParams>>
|
122
|
+
name: PluginName
|
123
|
+
chartType: T
|
124
|
+
defaultParams: PluginParams
|
125
|
+
layerIndex: number
|
126
|
+
// presetParams: Partial<PluginParams>
|
127
|
+
init: () => void
|
128
|
+
destroy: () => void
|
129
|
+
setPresetParams: (presetParams: Partial<PluginParams>) => void
|
130
|
+
setContext: (pluginContext: PluginContext<T, PluginName, PluginParams>) => void
|
131
|
+
constructor () {
|
132
|
+
const pluginEntity = createPluginEntity<T, PluginName, PluginParams>({
|
133
|
+
chartType,
|
134
|
+
config,
|
135
|
+
initFn
|
136
|
+
})
|
137
|
+
|
138
|
+
this.params$ = pluginEntity.params$
|
139
|
+
this.name = pluginEntity.name
|
140
|
+
this.chartType = pluginEntity.chartType
|
141
|
+
this.defaultParams = pluginEntity.defaultParams
|
142
|
+
this.layerIndex = pluginEntity.layerIndex
|
143
|
+
// this.presetParams = pluginEntity.presetParams
|
144
|
+
this.init = pluginEntity.init
|
145
|
+
this.destroy = pluginEntity.destroy
|
146
|
+
this.setPresetParams = pluginEntity.setPresetParams
|
147
|
+
this.setContext = pluginEntity.setContext
|
148
|
+
}
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import type { ChartOptionsPartial, ChartType, ValidatorResult } from '../../../lib/core-types'
|
2
|
+
import { validateColumns } from '../../utils/validator'
|
3
|
+
|
4
|
+
export function chartOptionsValidator<T extends ChartType> (chartOptionsPartial: ChartOptionsPartial<T>): ValidatorResult {
|
5
|
+
if (!chartOptionsPartial) {
|
6
|
+
// chartOptions 可為空值
|
7
|
+
return { status: 'success', columnName: '', expectToBe: '' }
|
8
|
+
}
|
9
|
+
const result = validateColumns(chartOptionsPartial, {
|
10
|
+
width: {
|
11
|
+
toBe: '"auto" | number',
|
12
|
+
test: (value: any) => value === 'auto' || typeof value === 'number'
|
13
|
+
},
|
14
|
+
height: {
|
15
|
+
toBe: '"auto" | number',
|
16
|
+
test: (value: any) => value === 'auto' || typeof value === 'number'
|
17
|
+
},
|
18
|
+
preset: {
|
19
|
+
toBeTypes: ['object']
|
20
|
+
}
|
21
|
+
})
|
22
|
+
|
23
|
+
return result
|
24
|
+
}
|
@@ -0,0 +1,134 @@
|
|
1
|
+
import type { ChartParamsPartial, ChartType, ValidatorResult } from '../../../lib/core-types'
|
2
|
+
import { validateColumns } from '../../utils/validator'
|
3
|
+
|
4
|
+
export function chartParamsValidator (chartType: ChartType, chartParamsPartial: ChartParamsPartial | undefined): ValidatorResult {
|
5
|
+
const highlightTargetToBe: {[key in ChartType]: string[]} = {
|
6
|
+
series: ['series', 'datum', 'none'],
|
7
|
+
grid: ['series', 'group', 'datum', 'none'],
|
8
|
+
multiGrid: ['series', 'group', 'datum', 'none'],
|
9
|
+
multiValue: ['category', 'datum', 'none'],
|
10
|
+
relationship: ['category', 'datum', 'none'],
|
11
|
+
tree: ['category', 'datum', 'none'],
|
12
|
+
noneData: ['none']
|
13
|
+
}
|
14
|
+
|
15
|
+
const result = validateColumns(chartParamsPartial, {
|
16
|
+
padding: {
|
17
|
+
toBeTypes: ['object'],
|
18
|
+
},
|
19
|
+
highlightTarget: {
|
20
|
+
toBe: highlightTargetToBe[chartType].map(d => `"${d}"`).join(' | '),
|
21
|
+
test: (value: any) => {
|
22
|
+
return highlightTargetToBe[chartType].includes(value)
|
23
|
+
}
|
24
|
+
},
|
25
|
+
highlightDefault: {
|
26
|
+
toBeTypes: ['string', 'null']
|
27
|
+
},
|
28
|
+
colorScheme: {
|
29
|
+
toBe: '"dark" | "light"',
|
30
|
+
test: (value: any) => value === 'dark' || value === 'light'
|
31
|
+
},
|
32
|
+
colors: {
|
33
|
+
toBeTypes: ['object'],
|
34
|
+
test: (value: any) => {
|
35
|
+
return value.light && value.dark
|
36
|
+
}
|
37
|
+
},
|
38
|
+
styles: {
|
39
|
+
toBeTypes: ['object'],
|
40
|
+
},
|
41
|
+
transitionDuration: {
|
42
|
+
toBeTypes: ['number'],
|
43
|
+
},
|
44
|
+
transitionEase: {
|
45
|
+
toBeTypes: ['string'],
|
46
|
+
}
|
47
|
+
})
|
48
|
+
|
49
|
+
if (chartParamsPartial && chartParamsPartial.padding) {
|
50
|
+
const paddingResult = validateColumns(chartParamsPartial.padding, {
|
51
|
+
top: {
|
52
|
+
toBeTypes: ['number'],
|
53
|
+
},
|
54
|
+
right: {
|
55
|
+
toBeTypes: ['number'],
|
56
|
+
},
|
57
|
+
bottom: {
|
58
|
+
toBeTypes: ['number'],
|
59
|
+
},
|
60
|
+
left: {
|
61
|
+
toBeTypes: ['number'],
|
62
|
+
},
|
63
|
+
})
|
64
|
+
|
65
|
+
if (paddingResult.status === 'error') {
|
66
|
+
return paddingResult
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
if (chartParamsPartial && chartParamsPartial.colors) {
|
71
|
+
const colorsResult = validateColumns(chartParamsPartial.colors, {
|
72
|
+
light: {
|
73
|
+
toBeTypes: ['object'],
|
74
|
+
},
|
75
|
+
dark: {
|
76
|
+
toBeTypes: ['object'],
|
77
|
+
},
|
78
|
+
})
|
79
|
+
|
80
|
+
if (colorsResult.status === 'error') {
|
81
|
+
return colorsResult
|
82
|
+
}
|
83
|
+
|
84
|
+
if (chartParamsPartial.colors.light) {
|
85
|
+
const lightResult = validateColumns(chartParamsPartial.colors.light, {
|
86
|
+
series: {
|
87
|
+
toBeTypes: ['string[]'],
|
88
|
+
},
|
89
|
+
primary: {
|
90
|
+
toBeTypes: ['string'],
|
91
|
+
},
|
92
|
+
secondary: {
|
93
|
+
toBeTypes: ['string'],
|
94
|
+
},
|
95
|
+
white: {
|
96
|
+
toBeTypes: ['string'],
|
97
|
+
},
|
98
|
+
background: {
|
99
|
+
toBeTypes: ['string'],
|
100
|
+
},
|
101
|
+
})
|
102
|
+
|
103
|
+
if (lightResult.status === 'error') {
|
104
|
+
return lightResult
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
if (chartParamsPartial.colors.dark) {
|
109
|
+
const darkResult = validateColumns(chartParamsPartial.colors.dark, {
|
110
|
+
series: {
|
111
|
+
toBeTypes: ['string[]'],
|
112
|
+
},
|
113
|
+
primary: {
|
114
|
+
toBeTypes: ['string'],
|
115
|
+
},
|
116
|
+
secondary: {
|
117
|
+
toBeTypes: ['string'],
|
118
|
+
},
|
119
|
+
white: {
|
120
|
+
toBeTypes: ['string'],
|
121
|
+
},
|
122
|
+
background: {
|
123
|
+
toBeTypes: ['string'],
|
124
|
+
},
|
125
|
+
})
|
126
|
+
|
127
|
+
if (darkResult.status === 'error') {
|
128
|
+
return darkResult
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
return result
|
134
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { ValidatorResult } from '../../../lib/core-types'
|
2
|
+
import { validateColumns } from '../../utils/validator'
|
3
|
+
import { isDom } from '../../utils/commonUtils'
|
4
|
+
|
5
|
+
export function elementValidator (element: HTMLElement | Element): ValidatorResult {
|
6
|
+
const result = validateColumns({ element }, {
|
7
|
+
element: {
|
8
|
+
toBe: 'Dom',
|
9
|
+
test: (value: any) => isDom(value)
|
10
|
+
},
|
11
|
+
})
|
12
|
+
|
13
|
+
return result
|
14
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import type { ChartType, PluginEntity, ValidatorResult } from '../../../lib/core-types'
|
2
|
+
import { validateColumns } from '../../utils/validator'
|
3
|
+
|
4
|
+
export function pluginsValidator (chartType: ChartType, pluginEntities: PluginEntity<any, any, any>[]): ValidatorResult {
|
5
|
+
const result = validateColumns({ pluginEntities }, {
|
6
|
+
pluginEntities: {
|
7
|
+
toBe: `PluginEntity<'${chartType}'>[]`,
|
8
|
+
test: (value: PluginEntity<any, any, any>[]) => {
|
9
|
+
return Array.isArray(value) && value.every((v) => v.chartType === chartType || v.chartType === 'noneData')
|
10
|
+
}
|
11
|
+
}
|
12
|
+
})
|
13
|
+
|
14
|
+
return result
|
15
|
+
}
|