@orbcharts/core 3.0.0-alpha.62 → 3.0.0-alpha.63
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/orbcharts-core.es.js +1814 -1567
- package/dist/orbcharts-core.umd.js +3 -3
- package/package.json +1 -1
- package/src/grid/dataFormatterValidator.ts +97 -4
- package/src/grid/dataValidator.ts +9 -5
- package/src/multiGrid/dataFormatterValidator.ts +112 -5
- package/src/multiGrid/dataValidator.ts +9 -5
- package/src/multiValue/dataFormatterValidator.ts +2 -1
- package/src/multiValue/dataValidator.ts +2 -1
- package/src/relationship/dataFormatterValidator.ts +2 -1
- package/src/relationship/dataValidator.ts +2 -1
- package/src/series/dataFormatterValidator.ts +37 -4
- package/src/series/dataValidator.ts +9 -5
- package/src/tree/dataFormatterValidator.ts +10 -5
- package/src/tree/dataValidator.ts +10 -5
- package/src/utils/observables.ts +7 -6
package/package.json
CHANGED
@@ -1,9 +1,102 @@
|
|
1
1
|
import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
|
2
|
+
import { validateColumns } from '../utils/validator'
|
2
3
|
|
3
4
|
export const dataFormatterValidator: DataFormatterValidator<'grid'> = (dataFormatter: DataFormatterTypeMap<'grid'>) => {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
const result = validateColumns(dataFormatter, {
|
6
|
+
visibleFilter: {
|
7
|
+
toBeTypes: ['Function']
|
8
|
+
},
|
9
|
+
grid: {
|
10
|
+
toBeTypes: ['object']
|
11
|
+
},
|
12
|
+
container: {
|
13
|
+
toBeTypes: ['object']
|
14
|
+
}
|
15
|
+
})
|
16
|
+
if (dataFormatter.grid) {
|
17
|
+
const visibleFilterResult = validateColumns(dataFormatter.grid, {
|
18
|
+
seriesDirection: {
|
19
|
+
toBe: '"row" | "column"',
|
20
|
+
test: (value) => value === 'row' || value === 'column'
|
21
|
+
},
|
22
|
+
rowLabels: {
|
23
|
+
toBeTypes: ['string[]']
|
24
|
+
},
|
25
|
+
columnLabels: {
|
26
|
+
toBeTypes: ['string[]']
|
27
|
+
},
|
28
|
+
valueAxis: {
|
29
|
+
toBeTypes: ['object']
|
30
|
+
},
|
31
|
+
groupAxis: {
|
32
|
+
toBeTypes: ['object']
|
33
|
+
},
|
34
|
+
separateSeries: {
|
35
|
+
toBeTypes: ['boolean']
|
36
|
+
}
|
37
|
+
})
|
38
|
+
if (visibleFilterResult.status === 'error') {
|
39
|
+
return visibleFilterResult
|
40
|
+
}
|
41
|
+
if (dataFormatter.grid.valueAxis) {
|
42
|
+
const valueAxisResult = validateColumns(dataFormatter.grid.valueAxis, {
|
43
|
+
position: {
|
44
|
+
toBe: '"left" | "right"',
|
45
|
+
test: (value) => value === 'left' || value === 'right'
|
46
|
+
},
|
47
|
+
scaleDomain: {
|
48
|
+
toBe: '[number | "min" | "auto", number | "max" | "auto"]',
|
49
|
+
test: (value) => Array.isArray(value) && value.length === 2 && (typeof value[0] === 'number' || value[0] === 'min' || value[0] === 'auto') && (typeof value[1] === 'number' || value[1] === 'max' || value[1] === 'auto')
|
50
|
+
},
|
51
|
+
scaleRange: {
|
52
|
+
toBe: '[number, number]',
|
53
|
+
test: (value) => Array.isArray(value) && value.length === 2 && typeof value[0] === 'number' && typeof value[1] === 'number'
|
54
|
+
},
|
55
|
+
label: {
|
56
|
+
toBeTypes: ['string']
|
57
|
+
}
|
58
|
+
})
|
59
|
+
if (valueAxisResult.status === 'error') {
|
60
|
+
return valueAxisResult
|
61
|
+
}
|
62
|
+
}
|
63
|
+
if (dataFormatter.grid.groupAxis) {
|
64
|
+
const groupAxisResult = validateColumns(dataFormatter.grid.groupAxis, {
|
65
|
+
position: {
|
66
|
+
toBe: '"top" | "bottom"',
|
67
|
+
test: (value) => value === 'top' || value === 'bottom'
|
68
|
+
},
|
69
|
+
scaleDomain: {
|
70
|
+
toBe: '[number, number | "max"]',
|
71
|
+
test: (value) => Array.isArray(value) && value.length === 2 && typeof value[0] === 'number' && (typeof value[1] === 'number' || value[1] === 'max')
|
72
|
+
},
|
73
|
+
scalePadding: {
|
74
|
+
toBeTypes: ['number']
|
75
|
+
},
|
76
|
+
label: {
|
77
|
+
toBeTypes: ['string']
|
78
|
+
}
|
79
|
+
})
|
80
|
+
if (groupAxisResult.status === 'error') {
|
81
|
+
return groupAxisResult
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
if (dataFormatter.container) {
|
86
|
+
const containerResult = validateColumns(dataFormatter.container, {
|
87
|
+
gap: {
|
88
|
+
toBeTypes: ['number']
|
89
|
+
},
|
90
|
+
rowAmount: {
|
91
|
+
toBeTypes: ['number']
|
92
|
+
},
|
93
|
+
columnAmount: {
|
94
|
+
toBeTypes: ['number']
|
95
|
+
}
|
96
|
+
})
|
97
|
+
if (containerResult.status === 'error') {
|
98
|
+
return containerResult
|
99
|
+
}
|
8
100
|
}
|
101
|
+
return result
|
9
102
|
}
|
@@ -1,9 +1,13 @@
|
|
1
1
|
import type { DataValidator, DataTypeMap } from '../../lib/core-types'
|
2
|
+
import { validateColumns } from '../utils/validator'
|
2
3
|
|
3
4
|
export const dataValidator: DataValidator<'grid'> = (data: DataTypeMap<'grid'>) => {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
const result = validateColumns({ data }, {
|
6
|
+
data: {
|
7
|
+
toBe: '(DataGridDatum | DataGridValue)[][]',
|
8
|
+
// 畢免資料量過大檢查不完,不深度檢查
|
9
|
+
test: (value) => Array.isArray(value)
|
10
|
+
}
|
11
|
+
})
|
12
|
+
return result
|
9
13
|
}
|
@@ -1,9 +1,116 @@
|
|
1
|
-
import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
|
1
|
+
import type { DataFormatterValidator, DataFormatterTypeMap, ValidatorResult } from '../../lib/core-types'
|
2
|
+
import { validateColumns } from '../utils/validator'
|
2
3
|
|
3
4
|
export const dataFormatterValidator: DataFormatterValidator<'multiGrid'> = (dataFormatter: DataFormatterTypeMap<'multiGrid'>) => {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
const result = validateColumns(dataFormatter, {
|
6
|
+
visibleFilter: {
|
7
|
+
toBeTypes: ['Function']
|
8
|
+
},
|
9
|
+
gridList: {
|
10
|
+
toBeTypes: ['object[]']
|
11
|
+
},
|
12
|
+
container: {
|
13
|
+
toBeTypes: ['object']
|
14
|
+
},
|
15
|
+
separateGrid: {
|
16
|
+
toBeTypes: ['boolean']
|
17
|
+
}
|
18
|
+
})
|
19
|
+
if (dataFormatter.gridList) {
|
20
|
+
const gridListResultArr = dataFormatter.gridList.map((grid, index) => {
|
21
|
+
const gridResult = validateColumns(grid, {
|
22
|
+
seriesDirection: {
|
23
|
+
toBe: '"row" | "column"',
|
24
|
+
test: (value) => value === 'row' || value === 'column'
|
25
|
+
},
|
26
|
+
rowLabels: {
|
27
|
+
toBeTypes: ['string[]']
|
28
|
+
},
|
29
|
+
columnLabels: {
|
30
|
+
toBeTypes: ['string[]']
|
31
|
+
},
|
32
|
+
valueAxis: {
|
33
|
+
toBeTypes: ['object']
|
34
|
+
},
|
35
|
+
groupAxis: {
|
36
|
+
toBeTypes: ['object']
|
37
|
+
},
|
38
|
+
separateSeries: {
|
39
|
+
toBeTypes: ['boolean']
|
40
|
+
}
|
41
|
+
})
|
42
|
+
if (gridResult.status === 'error') {
|
43
|
+
return gridResult
|
44
|
+
} else {
|
45
|
+
if (grid.valueAxis) {
|
46
|
+
const valueAxisResult = validateColumns(grid.valueAxis, {
|
47
|
+
position: {
|
48
|
+
toBe: '"top" | "bottom" | "left" | "right"',
|
49
|
+
test: (value) => value === 'top' || value === 'bottom' || value === 'left' || value === 'right'
|
50
|
+
},
|
51
|
+
scaleDomain: {
|
52
|
+
toBe: '[number | "min" | "auto", number | "max" | "auto"]',
|
53
|
+
test: (value) => Array.isArray(value) && value.length === 2 && (typeof value[0] === 'number' || value[0] === 'min' || value[0] === 'auto') && (typeof value[1] === 'number' || value[1] === 'max' || value[1] === 'auto')
|
54
|
+
},
|
55
|
+
scaleRange: {
|
56
|
+
toBe: '[number, number]',
|
57
|
+
test: (value) => Array.isArray(value) && value.length === 2 && typeof value[0] === 'number' && typeof value[1] === 'number'
|
58
|
+
},
|
59
|
+
label: {
|
60
|
+
toBeTypes: ['string']
|
61
|
+
}
|
62
|
+
})
|
63
|
+
if (valueAxisResult.status === 'error') {
|
64
|
+
return valueAxisResult
|
65
|
+
}
|
66
|
+
} else if (grid.groupAxis) {
|
67
|
+
const groupAxisResult = validateColumns(grid.groupAxis, {
|
68
|
+
position: {
|
69
|
+
toBe: '"top" | "bottom" | "left" | "right"',
|
70
|
+
test: (value) => value === 'top' || value === 'bottom' || value === 'left' || value === 'right'
|
71
|
+
},
|
72
|
+
scaleDomain: {
|
73
|
+
toBe: '[number, number | "max"]',
|
74
|
+
test: (value) => Array.isArray(value) && value.length === 2 && typeof value[0] === 'number' && (typeof value[1] === 'number' || value[1] === 'max')
|
75
|
+
},
|
76
|
+
scalePadding: {
|
77
|
+
toBeTypes: ['number']
|
78
|
+
},
|
79
|
+
label: {
|
80
|
+
toBeTypes: ['string']
|
81
|
+
}
|
82
|
+
})
|
83
|
+
if (groupAxisResult.status === 'error') {
|
84
|
+
return groupAxisResult
|
85
|
+
}
|
86
|
+
}
|
87
|
+
return <ValidatorResult>{
|
88
|
+
status: 'success',
|
89
|
+
columnName: '',
|
90
|
+
expectToBe: ''
|
91
|
+
}
|
92
|
+
}
|
93
|
+
})
|
94
|
+
const gridListResult = gridListResultArr.find((gridResult) => gridResult.status === 'error')
|
95
|
+
if (gridListResult.status === 'error') {
|
96
|
+
return gridListResult
|
97
|
+
}
|
8
98
|
}
|
99
|
+
if (dataFormatter.container) {
|
100
|
+
const containerResult = validateColumns(dataFormatter.container, {
|
101
|
+
gap: {
|
102
|
+
toBeTypes: ['number']
|
103
|
+
},
|
104
|
+
rowAmount: {
|
105
|
+
toBeTypes: ['number']
|
106
|
+
},
|
107
|
+
columnAmount: {
|
108
|
+
toBeTypes: ['number']
|
109
|
+
}
|
110
|
+
})
|
111
|
+
if (containerResult.status === 'error') {
|
112
|
+
return containerResult
|
113
|
+
}
|
114
|
+
}
|
115
|
+
return result
|
9
116
|
}
|
@@ -1,9 +1,13 @@
|
|
1
1
|
import type { DataValidator, DataTypeMap } from '../../lib/core-types'
|
2
|
+
import { validateColumns } from '../utils/validator'
|
2
3
|
|
3
4
|
export const dataValidator: DataValidator<'multiGrid'> = (data: DataTypeMap<'multiGrid'>) => {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
const result = validateColumns({ data }, {
|
6
|
+
data: {
|
7
|
+
toBe: 'DataGrid[]',
|
8
|
+
// 畢免資料量過大檢查不完,不深度檢查
|
9
|
+
test: (value) => Array.isArray(value)
|
10
|
+
}
|
11
|
+
})
|
12
|
+
return result
|
9
13
|
}
|
@@ -1,9 +1,42 @@
|
|
1
1
|
import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
|
2
|
+
import { validateColumns } from '../utils/validator'
|
2
3
|
|
3
4
|
export const dataFormatterValidator: DataFormatterValidator<'series'> = (dataFormatter: DataFormatterTypeMap<'series'>) => {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
const result = validateColumns(dataFormatter, {
|
6
|
+
visibleFilter: {
|
7
|
+
toBeTypes: ['Function']
|
8
|
+
},
|
9
|
+
sort: {
|
10
|
+
toBeTypes: ['Function', 'null']
|
11
|
+
},
|
12
|
+
seriesLabels: {
|
13
|
+
toBeTypes: ['string[]']
|
14
|
+
},
|
15
|
+
container: {
|
16
|
+
toBeTypes: ['object']
|
17
|
+
},
|
18
|
+
separateSeries: {
|
19
|
+
toBeTypes: ['boolean']
|
20
|
+
},
|
21
|
+
sumSeries: {
|
22
|
+
toBeTypes: ['boolean']
|
23
|
+
}
|
24
|
+
})
|
25
|
+
if (dataFormatter.container) {
|
26
|
+
const containerResult = validateColumns(dataFormatter.container, {
|
27
|
+
gap: {
|
28
|
+
toBeTypes: ['number']
|
29
|
+
},
|
30
|
+
rowAmount: {
|
31
|
+
toBeTypes: ['number']
|
32
|
+
},
|
33
|
+
columnAmount: {
|
34
|
+
toBeTypes: ['number']
|
35
|
+
}
|
36
|
+
})
|
37
|
+
if (containerResult.status === 'error') {
|
38
|
+
return containerResult
|
39
|
+
}
|
8
40
|
}
|
41
|
+
return result
|
9
42
|
}
|
@@ -1,9 +1,13 @@
|
|
1
1
|
import type { DataValidator, DataTypeMap } from '../../lib/core-types'
|
2
|
+
import { validateColumns } from '../utils/validator'
|
2
3
|
|
3
4
|
export const dataValidator: DataValidator<'series'> = (data: DataTypeMap<'series'>) => {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
const result = validateColumns({ data }, {
|
6
|
+
data: {
|
7
|
+
toBe: '(DataSeriesDatum | DataSeriesValue)[][] | (DataSeriesDatum | DataSeriesValue)[]',
|
8
|
+
// 畢免資料量過大檢查不完,不深度檢查
|
9
|
+
test: (value) => Array.isArray(value)
|
10
|
+
}
|
11
|
+
})
|
12
|
+
return result
|
9
13
|
}
|
@@ -1,9 +1,14 @@
|
|
1
1
|
import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
|
2
|
+
import { validateColumns } from '../utils/validator'
|
2
3
|
|
3
4
|
export const dataFormatterValidator: DataFormatterValidator<'tree'> = (dataFormatter: DataFormatterTypeMap<'tree'>) => {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
const result = validateColumns(dataFormatter, {
|
6
|
+
visibleFilter: {
|
7
|
+
toBeTypes: ['Function']
|
8
|
+
},
|
9
|
+
categoryLabels: {
|
10
|
+
toBeTypes: ['string[]']
|
11
|
+
}
|
12
|
+
})
|
13
|
+
return result
|
9
14
|
}
|
@@ -1,9 +1,14 @@
|
|
1
1
|
import type { DataValidator, DataTypeMap } from '../../lib/core-types'
|
2
|
+
import { validateColumns } from '../utils/validator'
|
3
|
+
import { isPlainObject } from '../utils'
|
2
4
|
|
3
5
|
export const dataValidator: DataValidator<'tree'> = (data: DataTypeMap<'tree'>) => {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
const result = validateColumns({ data }, {
|
7
|
+
data: {
|
8
|
+
toBe: 'DataTreeObj | DataTreeDatum[]',
|
9
|
+
// 畢免資料量過大檢查不完,不深度檢查
|
10
|
+
test: (value) => isPlainObject(value) && value.id !== undefined
|
11
|
+
}
|
12
|
+
})
|
13
|
+
return result
|
9
14
|
}
|
package/src/utils/observables.ts
CHANGED
@@ -12,6 +12,7 @@ import {
|
|
12
12
|
import type {
|
13
13
|
ChartType,
|
14
14
|
ChartParams,
|
15
|
+
ComputedDatumBase,
|
15
16
|
ComputedDataTypeMap,
|
16
17
|
ComputedDatumTypeMap,
|
17
18
|
DataFormatterTypeMap,
|
@@ -74,12 +75,12 @@ export const highlightObservable = <T extends ChartType, D>({ datumList$, fullCh
|
|
74
75
|
filter(d => d.eventName === 'mouseover'),
|
75
76
|
// distinctUntilChanged((prev, current) => prev.eventName === current.eventName)
|
76
77
|
map(d => {
|
77
|
-
return d.datum
|
78
|
+
return (d as any).datum
|
78
79
|
? {
|
79
|
-
id: (d.datum as any).id,
|
80
|
-
seriesLabel: (d.datum as any).seriesLabel,
|
81
|
-
groupLabel: (d.datum as any).groupLabel,
|
82
|
-
categoryLabel: (d.datum as any).categoryLabel,
|
80
|
+
id: ((d as any).datum as any).id,
|
81
|
+
seriesLabel: ((d as any).datum as any).seriesLabel,
|
82
|
+
groupLabel: ((d as any).datum as any).groupLabel,
|
83
|
+
categoryLabel: ((d as any).datum as any).categoryLabel,
|
83
84
|
highlightDefault: null
|
84
85
|
}
|
85
86
|
: {
|
@@ -102,7 +103,7 @@ export const highlightObservable = <T extends ChartType, D>({ datumList$, fullCh
|
|
102
103
|
)
|
103
104
|
|
104
105
|
function getDatumIds (datumList: ComputedDatumTypeMap<T>[], id: string | null) {
|
105
|
-
const datum = datumList.find(d => d.id === id)
|
106
|
+
const datum = datumList.find(d => (d as ComputedDatumBase).id === id)
|
106
107
|
return datum ? [datum] : []
|
107
108
|
}
|
108
109
|
|