@orbcharts/core 3.0.0-beta.7 → 3.0.0-beta.8
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 +402 -399
- package/dist/orbcharts-core.umd.js +3 -3
- 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 +505 -505
- package/src/base/createBasePlugin.ts +153 -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 +238 -235
- 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 +176 -176
- package/src/grid/dataFormatterValidator.ts +101 -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 +41 -41
- package/src/multiGrid/dataFormatterValidator.ts +115 -115
- package/src/multiGrid/dataValidator.ts +12 -12
- package/src/multiValue/computedDataFn.ts +110 -110
- package/src/multiValue/contextObserverCallback.ts +160 -160
- package/src/multiValue/dataFormatterValidator.ts +9 -9
- package/src/multiValue/dataValidator.ts +9 -9
- package/src/relationship/computedDataFn.ts +144 -144
- package/src/relationship/contextObserverCallback.ts +80 -80
- package/src/relationship/dataFormatterValidator.ts +9 -9
- package/src/relationship/dataValidator.ts +9 -9
- package/src/series/computedDataFn.ts +88 -88
- package/src/series/contextObserverCallback.ts +100 -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 +683 -683
- package/src/utils/index.ts +9 -9
- package/src/utils/multiGridObservables.ts +392 -392
- package/src/utils/multiValueObservables.ts +661 -661
- package/src/utils/observables.ts +219 -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,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
|
-
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: `${config.name}.params$`
|
54
|
-
}))
|
55
|
-
} else if (status === 'warning') {
|
56
|
-
console.warn(createValidatorWarningMessage({
|
57
|
-
columnName,
|
58
|
-
expectToBe,
|
59
|
-
from: `${config.name}.params$`
|
60
|
-
}))
|
61
|
-
}
|
62
|
-
} catch (e) {
|
63
|
-
// throw new Error(e.message)
|
64
|
-
// 驗證失敗仍繼續執行,才不會把 Observable 資料流給中斷掉
|
65
|
-
console.error(createOrbChartsErrorMessage(e))
|
66
|
-
}
|
67
|
-
return mergeOptionsWithDefault(d, mergedDefaultParams)
|
68
|
-
}),
|
69
|
-
// catchError((e) => {
|
70
|
-
// console.error(createOrbChartsErrorMessage(e))
|
71
|
-
// return EMPTY
|
72
|
-
// })
|
73
|
-
)
|
74
|
-
}),
|
75
|
-
shareReplay(1)
|
76
|
-
)
|
77
|
-
|
78
|
-
// 建立plugin實例
|
79
|
-
return {
|
80
|
-
params$,
|
81
|
-
name: config.name,
|
82
|
-
chartType,
|
83
|
-
defaultParams: config.defaultParams,
|
84
|
-
layerIndex: config.layerIndex,
|
85
|
-
init () {
|
86
|
-
if (!pluginContext) {
|
87
|
-
return
|
88
|
-
}
|
89
|
-
// 執行
|
90
|
-
pluginDestroyFn = (initFn(pluginContext) ?? (() => {})) // plugin執行會回傳destroy函式
|
91
|
-
EntityWeakMap.set(pluginContext.selection, pluginContext)
|
92
|
-
},
|
93
|
-
destroy () {
|
94
|
-
pluginDestroyFn()
|
95
|
-
if (pluginContext) {
|
96
|
-
pluginContext.selection.remove()
|
97
|
-
pluginContext = undefined
|
98
|
-
}
|
99
|
-
destroy$.next(undefined)
|
100
|
-
},
|
101
|
-
setPresetParams: (presetParams: Partial<PluginParams>) => {
|
102
|
-
mergedDefaultParams$.next(mergeOptionsWithDefault(presetParams, config.defaultParams))
|
103
|
-
|
104
|
-
},
|
105
|
-
setContext: (_pluginContext: PluginContext<T, PluginName, PluginParams>) => {
|
106
|
-
pluginContext = _pluginContext
|
107
|
-
pluginContext.observer.fullParams$ = fullParams$
|
108
|
-
}
|
109
|
-
}
|
110
|
-
}
|
111
|
-
|
112
|
-
// 建立plugin類別
|
113
|
-
export const createBasePlugin: CreateBasePlugin = <T extends ChartType>(chartType: T) => {
|
114
|
-
|
115
|
-
// 定義plugin
|
116
|
-
return function definePlugin<PluginName, PluginParams>(config: DefinePluginConfig<PluginName, PluginParams>) {
|
117
|
-
|
118
|
-
// 定義plugin的初始化function
|
119
|
-
return function definePluginInitFn (initFn: PluginInitFn<T, PluginName, PluginParams>) {
|
120
|
-
|
121
|
-
return class Plugin {
|
122
|
-
params$: Subject<Partial<PluginParams>>
|
123
|
-
name: PluginName
|
124
|
-
chartType: T
|
125
|
-
defaultParams: PluginParams
|
126
|
-
layerIndex: number
|
127
|
-
// presetParams: Partial<PluginParams>
|
128
|
-
init: () => void
|
129
|
-
destroy: () => void
|
130
|
-
setPresetParams: (presetParams: Partial<PluginParams>) => void
|
131
|
-
setContext: (pluginContext: PluginContext<T, PluginName, PluginParams>) => void
|
132
|
-
constructor () {
|
133
|
-
const pluginEntity = createPluginEntity<T, PluginName, PluginParams>({
|
134
|
-
chartType,
|
135
|
-
config,
|
136
|
-
initFn
|
137
|
-
})
|
138
|
-
|
139
|
-
this.params$ = pluginEntity.params$
|
140
|
-
this.name = pluginEntity.name
|
141
|
-
this.chartType = pluginEntity.chartType
|
142
|
-
this.defaultParams = pluginEntity.defaultParams
|
143
|
-
this.layerIndex = pluginEntity.layerIndex
|
144
|
-
// this.presetParams = pluginEntity.presetParams
|
145
|
-
this.init = pluginEntity.init
|
146
|
-
this.destroy = pluginEntity.destroy
|
147
|
-
this.setPresetParams = pluginEntity.setPresetParams
|
148
|
-
this.setContext = pluginEntity.setContext
|
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
|
+
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: `${config.name}.params$`
|
54
|
+
}))
|
55
|
+
} else if (status === 'warning') {
|
56
|
+
console.warn(createValidatorWarningMessage({
|
57
|
+
columnName,
|
58
|
+
expectToBe,
|
59
|
+
from: `${config.name}.params$`
|
60
|
+
}))
|
61
|
+
}
|
62
|
+
} catch (e) {
|
63
|
+
// throw new Error(e.message)
|
64
|
+
// 驗證失敗仍繼續執行,才不會把 Observable 資料流給中斷掉
|
65
|
+
console.error(createOrbChartsErrorMessage(e))
|
66
|
+
}
|
67
|
+
return mergeOptionsWithDefault(d, mergedDefaultParams)
|
68
|
+
}),
|
69
|
+
// catchError((e) => {
|
70
|
+
// console.error(createOrbChartsErrorMessage(e))
|
71
|
+
// return EMPTY
|
72
|
+
// })
|
73
|
+
)
|
74
|
+
}),
|
75
|
+
shareReplay(1)
|
76
|
+
)
|
77
|
+
|
78
|
+
// 建立plugin實例
|
79
|
+
return {
|
80
|
+
params$,
|
81
|
+
name: config.name,
|
82
|
+
chartType,
|
83
|
+
defaultParams: config.defaultParams,
|
84
|
+
layerIndex: config.layerIndex,
|
85
|
+
init () {
|
86
|
+
if (!pluginContext) {
|
87
|
+
return
|
88
|
+
}
|
89
|
+
// 執行
|
90
|
+
pluginDestroyFn = (initFn(pluginContext) ?? (() => {})) // plugin執行會回傳destroy函式
|
91
|
+
EntityWeakMap.set(pluginContext.selection, pluginContext)
|
92
|
+
},
|
93
|
+
destroy () {
|
94
|
+
pluginDestroyFn()
|
95
|
+
if (pluginContext) {
|
96
|
+
pluginContext.selection.remove()
|
97
|
+
pluginContext = undefined
|
98
|
+
}
|
99
|
+
destroy$.next(undefined)
|
100
|
+
},
|
101
|
+
setPresetParams: (presetParams: Partial<PluginParams>) => {
|
102
|
+
mergedDefaultParams$.next(mergeOptionsWithDefault(presetParams, config.defaultParams))
|
103
|
+
|
104
|
+
},
|
105
|
+
setContext: (_pluginContext: PluginContext<T, PluginName, PluginParams>) => {
|
106
|
+
pluginContext = _pluginContext
|
107
|
+
pluginContext.observer.fullParams$ = fullParams$
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
// 建立plugin類別
|
113
|
+
export const createBasePlugin: CreateBasePlugin = <T extends ChartType>(chartType: T) => {
|
114
|
+
|
115
|
+
// 定義plugin
|
116
|
+
return function definePlugin<PluginName, PluginParams>(config: DefinePluginConfig<PluginName, PluginParams>) {
|
117
|
+
|
118
|
+
// 定義plugin的初始化function
|
119
|
+
return function definePluginInitFn (initFn: PluginInitFn<T, PluginName, PluginParams>) {
|
120
|
+
|
121
|
+
return class Plugin {
|
122
|
+
params$: Subject<Partial<PluginParams>>
|
123
|
+
name: PluginName
|
124
|
+
chartType: T
|
125
|
+
defaultParams: PluginParams
|
126
|
+
layerIndex: number
|
127
|
+
// presetParams: Partial<PluginParams>
|
128
|
+
init: () => void
|
129
|
+
destroy: () => void
|
130
|
+
setPresetParams: (presetParams: Partial<PluginParams>) => void
|
131
|
+
setContext: (pluginContext: PluginContext<T, PluginName, PluginParams>) => void
|
132
|
+
constructor () {
|
133
|
+
const pluginEntity = createPluginEntity<T, PluginName, PluginParams>({
|
134
|
+
chartType,
|
135
|
+
config,
|
136
|
+
initFn
|
137
|
+
})
|
138
|
+
|
139
|
+
this.params$ = pluginEntity.params$
|
140
|
+
this.name = pluginEntity.name
|
141
|
+
this.chartType = pluginEntity.chartType
|
142
|
+
this.defaultParams = pluginEntity.defaultParams
|
143
|
+
this.layerIndex = pluginEntity.layerIndex
|
144
|
+
// this.presetParams = pluginEntity.presetParams
|
145
|
+
this.init = pluginEntity.init
|
146
|
+
this.destroy = pluginEntity.destroy
|
147
|
+
this.setPresetParams = pluginEntity.setPresetParams
|
148
|
+
this.setContext = pluginEntity.setContext
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
}
|
@@ -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
|
-
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
|
-
label: {
|
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
|
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
|
+
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
|
+
label: {
|
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
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
|
}
|