@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.
Files changed (76) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +2734 -2353
  3. package/dist/orbcharts-core.umd.js +4 -4
  4. package/dist/src/defaults.d.ts +2 -1
  5. package/dist/src/utils/gridObservables.d.ts +8 -4
  6. package/dist/src/utils/index.d.ts +0 -3
  7. package/dist/src/utils/multiGridObservables.d.ts +3 -2
  8. package/dist/src/utils/multiValueObservables.d.ts +76 -29
  9. package/dist/src/utils/observables.d.ts +8 -1
  10. package/dist/src/utils/orbchartsUtils.d.ts +9 -9
  11. package/dist/src/utils/seriesObservables.d.ts +1 -1
  12. package/lib/core-types.ts +7 -7
  13. package/package.json +42 -42
  14. package/src/AbstractChart.ts +57 -57
  15. package/src/GridChart.ts +24 -24
  16. package/src/MultiGridChart.ts +24 -24
  17. package/src/MultiValueChart.ts +24 -24
  18. package/src/RelationshipChart.ts +24 -24
  19. package/src/SeriesChart.ts +24 -24
  20. package/src/TreeChart.ts +24 -24
  21. package/src/base/createBaseChart.ts +506 -505
  22. package/src/base/createBasePlugin.ts +154 -153
  23. package/src/base/validators/chartOptionsValidator.ts +23 -23
  24. package/src/base/validators/chartParamsValidator.ts +133 -133
  25. package/src/base/validators/elementValidator.ts +13 -13
  26. package/src/base/validators/pluginsValidator.ts +14 -14
  27. package/src/defaults.ts +282 -238
  28. package/src/defineGridPlugin.ts +3 -3
  29. package/src/defineMultiGridPlugin.ts +3 -3
  30. package/src/defineMultiValuePlugin.ts +3 -3
  31. package/src/defineNoneDataPlugin.ts +4 -4
  32. package/src/defineRelationshipPlugin.ts +3 -3
  33. package/src/defineSeriesPlugin.ts +3 -3
  34. package/src/defineTreePlugin.ts +3 -3
  35. package/src/grid/computedDataFn.ts +129 -129
  36. package/src/grid/contextObserverCallback.ts +198 -176
  37. package/src/grid/dataFormatterValidator.ts +120 -101
  38. package/src/grid/dataValidator.ts +12 -12
  39. package/src/index.ts +20 -20
  40. package/src/multiGrid/computedDataFn.ts +123 -123
  41. package/src/multiGrid/contextObserverCallback.ts +72 -41
  42. package/src/multiGrid/dataFormatterValidator.ts +115 -115
  43. package/src/multiGrid/dataValidator.ts +12 -12
  44. package/src/multiValue/computedDataFn.ts +113 -110
  45. package/src/multiValue/contextObserverCallback.ts +276 -160
  46. package/src/multiValue/dataFormatterValidator.ts +89 -9
  47. package/src/multiValue/dataValidator.ts +12 -9
  48. package/src/relationship/computedDataFn.ts +159 -144
  49. package/src/relationship/contextObserverCallback.ts +80 -80
  50. package/src/relationship/dataFormatterValidator.ts +13 -9
  51. package/src/relationship/dataValidator.ts +13 -9
  52. package/src/series/computedDataFn.ts +88 -88
  53. package/src/series/contextObserverCallback.ts +107 -100
  54. package/src/series/dataFormatterValidator.ts +41 -41
  55. package/src/series/dataValidator.ts +12 -12
  56. package/src/tree/computedDataFn.ts +129 -129
  57. package/src/tree/contextObserverCallback.ts +58 -58
  58. package/src/tree/dataFormatterValidator.ts +13 -13
  59. package/src/tree/dataValidator.ts +13 -13
  60. package/src/utils/commonUtils.ts +55 -55
  61. package/src/utils/d3Scale.ts +198 -198
  62. package/src/utils/errorMessage.ts +42 -42
  63. package/src/utils/gridObservables.ts +705 -683
  64. package/src/utils/index.ts +10 -10
  65. package/src/utils/multiGridObservables.ts +401 -392
  66. package/src/utils/multiValueObservables.ts +1044 -662
  67. package/src/utils/observables.ts +281 -219
  68. package/src/utils/orbchartsUtils.ts +377 -377
  69. package/src/utils/relationshipObservables.ts +84 -84
  70. package/src/utils/seriesObservables.ts +175 -175
  71. package/src/utils/treeObservables.ts +105 -105
  72. package/src/utils/validator.ts +126 -126
  73. package/tsconfig.base.json +13 -13
  74. package/tsconfig.json +2 -2
  75. package/vite-env.d.ts +6 -6
  76. 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
- 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
+ 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
- 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
+ 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
  }