@orbcharts/core 3.0.0-beta.8 → 3.0.0
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 +2734 -2353
- package/dist/orbcharts-core.umd.js +4 -4
- package/dist/src/defaults.d.ts +2 -1
- package/dist/src/utils/gridObservables.d.ts +8 -4
- package/dist/src/utils/index.d.ts +0 -3
- package/dist/src/utils/multiGridObservables.d.ts +3 -2
- package/dist/src/utils/multiValueObservables.d.ts +76 -29
- package/dist/src/utils/observables.d.ts +8 -1
- package/dist/src/utils/orbchartsUtils.d.ts +9 -9
- package/dist/src/utils/seriesObservables.d.ts +1 -1
- package/lib/core-types.ts +7 -7
- package/package.json +42 -42
- 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 +506 -505
- package/src/base/createBasePlugin.ts +154 -153
- 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 +282 -238
- 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 +198 -176
- package/src/grid/dataFormatterValidator.ts +120 -101
- package/src/grid/dataValidator.ts +12 -12
- package/src/index.ts +20 -20
- package/src/multiGrid/computedDataFn.ts +123 -123
- package/src/multiGrid/contextObserverCallback.ts +72 -41
- package/src/multiGrid/dataFormatterValidator.ts +115 -115
- package/src/multiGrid/dataValidator.ts +12 -12
- package/src/multiValue/computedDataFn.ts +113 -110
- package/src/multiValue/contextObserverCallback.ts +276 -160
- package/src/multiValue/dataFormatterValidator.ts +89 -9
- package/src/multiValue/dataValidator.ts +12 -9
- package/src/relationship/computedDataFn.ts +159 -144
- package/src/relationship/contextObserverCallback.ts +80 -80
- package/src/relationship/dataFormatterValidator.ts +13 -9
- package/src/relationship/dataValidator.ts +13 -9
- package/src/series/computedDataFn.ts +88 -88
- package/src/series/contextObserverCallback.ts +107 -100
- package/src/series/dataFormatterValidator.ts +41 -41
- package/src/series/dataValidator.ts +12 -12
- 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/utils/commonUtils.ts +55 -55
- package/src/utils/d3Scale.ts +198 -198
- package/src/utils/errorMessage.ts +42 -42
- package/src/utils/gridObservables.ts +705 -683
- package/src/utils/index.ts +10 -10
- package/src/utils/multiGridObservables.ts +401 -392
- package/src/utils/multiValueObservables.ts +1044 -662
- package/src/utils/observables.ts +281 -219
- package/src/utils/orbchartsUtils.ts +377 -377
- package/src/utils/relationshipObservables.ts +84 -84
- package/src/utils/seriesObservables.ts +175 -175
- package/src/utils/treeObservables.ts +105 -105
- 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,153 +1,154 @@
|
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
import {
|
23
|
-
import {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
const
|
34
|
-
|
35
|
-
let
|
36
|
-
|
37
|
-
const
|
38
|
-
const
|
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
|
-
pluginContext
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
pluginContext
|
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
|
-
this.
|
141
|
-
this.
|
142
|
-
this.
|
143
|
-
this.
|
144
|
-
|
145
|
-
this.
|
146
|
-
this.
|
147
|
-
this.
|
148
|
-
this.
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
}
|
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
|
+
DeepPartial,
|
18
|
+
DefinePluginConfig,
|
19
|
+
PluginInitFn,
|
20
|
+
PluginContext,
|
21
|
+
PluginEntity } from '../../lib/core-types'
|
22
|
+
import { mergeOptionsWithDefault } from '../utils'
|
23
|
+
import { createValidatorErrorMessage, createValidatorWarningMessage, createOrbChartsErrorMessage } from '../utils/errorMessage'
|
24
|
+
import { validateColumns } from '../utils/validator'
|
25
|
+
|
26
|
+
// 建立plugin實例
|
27
|
+
function createPluginEntity <T extends ChartType, PluginName, PluginParams>({ chartType, config, initFn }: {
|
28
|
+
chartType: T
|
29
|
+
config: DefinePluginConfig<PluginName, PluginParams>
|
30
|
+
initFn: PluginInitFn<T, PluginName, PluginParams>
|
31
|
+
}): PluginEntity<T, PluginName, PluginParams> {
|
32
|
+
|
33
|
+
const destroy$ = new Subject()
|
34
|
+
const EntityWeakMap = new WeakMap() // <selection, pluginEntity> 避免只移除selection而沒回收pluginEntity的memory leak
|
35
|
+
let pluginDestroyFn = () => {}
|
36
|
+
let pluginContext: PluginContext<T, PluginName, PluginParams> | undefined
|
37
|
+
const mergedDefaultParams$ = new BehaviorSubject(config.defaultParams)
|
38
|
+
const params$: Subject<DeepPartial<typeof config.defaultParams>> = new BehaviorSubject({})
|
39
|
+
const fullParams$ = mergedDefaultParams$.pipe(
|
40
|
+
switchMap(mergedDefaultParams => {
|
41
|
+
return params$
|
42
|
+
.pipe(
|
43
|
+
takeUntil(destroy$),
|
44
|
+
map(d => {
|
45
|
+
try {
|
46
|
+
// 檢查 data$ 資料格式是否正確
|
47
|
+
const { status, columnName, expectToBe } = config.validator(d, {
|
48
|
+
validateColumns
|
49
|
+
})
|
50
|
+
if (status === 'error') {
|
51
|
+
throw new Error(createValidatorErrorMessage({
|
52
|
+
columnName,
|
53
|
+
expectToBe,
|
54
|
+
from: `${config.name}.params$`
|
55
|
+
}))
|
56
|
+
} else if (status === 'warning') {
|
57
|
+
console.warn(createValidatorWarningMessage({
|
58
|
+
columnName,
|
59
|
+
expectToBe,
|
60
|
+
from: `${config.name}.params$`
|
61
|
+
}))
|
62
|
+
}
|
63
|
+
} catch (e) {
|
64
|
+
// throw new Error(e.message)
|
65
|
+
// 驗證失敗仍繼續執行,才不會把 Observable 資料流給中斷掉
|
66
|
+
console.error(createOrbChartsErrorMessage(e))
|
67
|
+
}
|
68
|
+
return mergeOptionsWithDefault(d, mergedDefaultParams)
|
69
|
+
}),
|
70
|
+
// catchError((e) => {
|
71
|
+
// console.error(createOrbChartsErrorMessage(e))
|
72
|
+
// return EMPTY
|
73
|
+
// })
|
74
|
+
)
|
75
|
+
}),
|
76
|
+
shareReplay(1)
|
77
|
+
)
|
78
|
+
|
79
|
+
// 建立plugin實例
|
80
|
+
return {
|
81
|
+
params$,
|
82
|
+
name: config.name,
|
83
|
+
chartType,
|
84
|
+
defaultParams: config.defaultParams,
|
85
|
+
layerIndex: config.layerIndex,
|
86
|
+
init () {
|
87
|
+
if (!pluginContext) {
|
88
|
+
return
|
89
|
+
}
|
90
|
+
// 執行
|
91
|
+
pluginDestroyFn = (initFn(pluginContext) ?? (() => {})) // plugin執行會回傳destroy函式
|
92
|
+
EntityWeakMap.set(pluginContext.selection, pluginContext)
|
93
|
+
},
|
94
|
+
destroy () {
|
95
|
+
pluginDestroyFn()
|
96
|
+
if (pluginContext) {
|
97
|
+
pluginContext.selection.remove()
|
98
|
+
pluginContext = undefined
|
99
|
+
}
|
100
|
+
destroy$.next(undefined)
|
101
|
+
},
|
102
|
+
setPresetParams: (presetParams: DeepPartial<PluginParams>) => {
|
103
|
+
mergedDefaultParams$.next(mergeOptionsWithDefault(presetParams, config.defaultParams))
|
104
|
+
|
105
|
+
},
|
106
|
+
setContext: (_pluginContext: PluginContext<T, PluginName, PluginParams>) => {
|
107
|
+
pluginContext = _pluginContext
|
108
|
+
pluginContext.observer.fullParams$ = fullParams$
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
// 建立plugin類別
|
114
|
+
export const createBasePlugin: CreateBasePlugin = <T extends ChartType>(chartType: T) => {
|
115
|
+
|
116
|
+
// 定義plugin
|
117
|
+
return function definePlugin<PluginName, PluginParams>(config: DefinePluginConfig<PluginName, PluginParams>) {
|
118
|
+
|
119
|
+
// 定義plugin的初始化function
|
120
|
+
return function definePluginInitFn (initFn: PluginInitFn<T, PluginName, PluginParams>) {
|
121
|
+
|
122
|
+
return class Plugin {
|
123
|
+
params$: Subject<DeepPartial<PluginParams>>
|
124
|
+
name: PluginName
|
125
|
+
chartType: T
|
126
|
+
defaultParams: PluginParams
|
127
|
+
layerIndex: number
|
128
|
+
// presetParams: Partial<PluginParams>
|
129
|
+
init: () => void
|
130
|
+
destroy: () => void
|
131
|
+
setPresetParams: (presetParams: DeepPartial<PluginParams>) => void
|
132
|
+
setContext: (pluginContext: PluginContext<T, PluginName, PluginParams>) => void
|
133
|
+
constructor () {
|
134
|
+
const pluginEntity = createPluginEntity<T, PluginName, PluginParams>({
|
135
|
+
chartType,
|
136
|
+
config,
|
137
|
+
initFn
|
138
|
+
})
|
139
|
+
|
140
|
+
this.params$ = pluginEntity.params$
|
141
|
+
this.name = pluginEntity.name
|
142
|
+
this.chartType = pluginEntity.chartType
|
143
|
+
this.defaultParams = pluginEntity.defaultParams
|
144
|
+
this.layerIndex = pluginEntity.layerIndex
|
145
|
+
// this.presetParams = pluginEntity.presetParams
|
146
|
+
this.init = pluginEntity.init
|
147
|
+
this.destroy = pluginEntity.destroy
|
148
|
+
this.setPresetParams = pluginEntity.setPresetParams
|
149
|
+
this.setContext = pluginEntity.setContext
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
}
|
154
|
+
}
|
@@ -1,24 +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
|
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
24
|
}
|
@@ -1,134 +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
|
-
label: {
|
87
|
-
toBeTypes: ['string[]'],
|
88
|
-
},
|
89
|
-
primary: {
|
90
|
-
toBeTypes: ['string'],
|
91
|
-
},
|
92
|
-
secondary: {
|
93
|
-
toBeTypes: ['string'],
|
94
|
-
},
|
95
|
-
|
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
|
-
label: {
|
111
|
-
toBeTypes: ['string[]'],
|
112
|
-
},
|
113
|
-
primary: {
|
114
|
-
toBeTypes: ['string'],
|
115
|
-
},
|
116
|
-
secondary: {
|
117
|
-
toBeTypes: ['string'],
|
118
|
-
},
|
119
|
-
|
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
|
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
|
+
label: {
|
87
|
+
toBeTypes: ['string[]'],
|
88
|
+
},
|
89
|
+
primary: {
|
90
|
+
toBeTypes: ['string'],
|
91
|
+
},
|
92
|
+
secondary: {
|
93
|
+
toBeTypes: ['string'],
|
94
|
+
},
|
95
|
+
labelContrast: {
|
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
|
+
label: {
|
111
|
+
toBeTypes: ['string[]'],
|
112
|
+
},
|
113
|
+
primary: {
|
114
|
+
toBeTypes: ['string'],
|
115
|
+
},
|
116
|
+
secondary: {
|
117
|
+
toBeTypes: ['string'],
|
118
|
+
},
|
119
|
+
labelContrast: {
|
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
134
|
}
|
@@ -1,14 +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
|
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
14
|
}
|