@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.
Files changed (68) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +2217 -2164
  3. package/dist/orbcharts-core.umd.js +5 -5
  4. package/lib/core-types.ts +7 -7
  5. package/package.json +46 -46
  6. package/src/AbstractChart.ts +57 -57
  7. package/src/GridChart.ts +24 -24
  8. package/src/MultiGridChart.ts +24 -24
  9. package/src/MultiValueChart.ts +24 -24
  10. package/src/RelationshipChart.ts +24 -24
  11. package/src/SeriesChart.ts +24 -24
  12. package/src/TreeChart.ts +24 -24
  13. package/src/base/createBaseChart.ts +524 -524
  14. package/src/base/createBasePlugin.ts +154 -154
  15. package/src/base/validators/chartOptionsValidator.ts +23 -23
  16. package/src/base/validators/chartParamsValidator.ts +133 -133
  17. package/src/base/validators/elementValidator.ts +13 -13
  18. package/src/base/validators/pluginsValidator.ts +14 -14
  19. package/src/defaults.ts +284 -284
  20. package/src/defineGridPlugin.ts +3 -3
  21. package/src/defineMultiGridPlugin.ts +3 -3
  22. package/src/defineMultiValuePlugin.ts +3 -3
  23. package/src/defineNoneDataPlugin.ts +4 -4
  24. package/src/defineRelationshipPlugin.ts +3 -3
  25. package/src/defineSeriesPlugin.ts +3 -3
  26. package/src/defineTreePlugin.ts +3 -3
  27. package/src/grid/computedDataFn.ts +129 -129
  28. package/src/grid/contextObserverCallback.ts +209 -201
  29. package/src/grid/dataFormatterValidator.ts +125 -125
  30. package/src/grid/dataValidator.ts +12 -12
  31. package/src/grid/gridObservables.ts +698 -694
  32. package/src/index.ts +20 -20
  33. package/src/multiGrid/computedDataFn.ts +123 -123
  34. package/src/multiGrid/contextObserverCallback.ts +109 -75
  35. package/src/multiGrid/dataFormatterValidator.ts +120 -120
  36. package/src/multiGrid/dataValidator.ts +12 -12
  37. package/src/multiGrid/multiGridObservables.ts +366 -357
  38. package/src/multiValue/computedDataFn.ts +113 -113
  39. package/src/multiValue/contextObserverCallback.ts +328 -328
  40. package/src/multiValue/dataFormatterValidator.ts +94 -94
  41. package/src/multiValue/dataValidator.ts +12 -12
  42. package/src/multiValue/multiValueObservables.ts +865 -865
  43. package/src/relationship/computedDataFn.ts +159 -159
  44. package/src/relationship/contextObserverCallback.ts +80 -80
  45. package/src/relationship/dataFormatterValidator.ts +13 -13
  46. package/src/relationship/dataValidator.ts +13 -13
  47. package/src/relationship/relationshipObservables.ts +84 -84
  48. package/src/series/computedDataFn.ts +88 -88
  49. package/src/series/contextObserverCallback.ts +132 -132
  50. package/src/series/dataFormatterValidator.ts +46 -46
  51. package/src/series/dataValidator.ts +12 -12
  52. package/src/series/seriesObservables.ts +209 -209
  53. package/src/tree/computedDataFn.ts +129 -129
  54. package/src/tree/contextObserverCallback.ts +58 -58
  55. package/src/tree/dataFormatterValidator.ts +13 -13
  56. package/src/tree/dataValidator.ts +13 -13
  57. package/src/tree/treeObservables.ts +105 -105
  58. package/src/utils/commonUtils.ts +55 -55
  59. package/src/utils/d3Scale.ts +198 -198
  60. package/src/utils/errorMessage.ts +40 -40
  61. package/src/utils/index.ts +3 -3
  62. package/src/utils/observables.ts +308 -308
  63. package/src/utils/orbchartsUtils.ts +396 -396
  64. package/src/utils/validator.ts +126 -126
  65. package/tsconfig.base.json +13 -13
  66. package/tsconfig.json +2 -2
  67. package/vite-env.d.ts +6 -6
  68. package/vite.config.js +22 -22
@@ -1,154 +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
- 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
+ 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
- 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
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
  }