@orbcharts/core 4.0.0-alpha.0 → 4.0.0-beta.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 (47) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +876 -865
  3. package/dist/orbcharts-core.umd.js +3 -3
  4. package/dist/src/types/Plugin.d.ts +1 -1
  5. package/package.json +1 -1
  6. package/src/OrbCharts.ts +34 -34
  7. package/src/chart/createChart.ts +1013 -996
  8. package/src/chart/createGraphData.ts +391 -391
  9. package/src/chart/createGridData.ts +247 -247
  10. package/src/chart/createMultivariateData.ts +181 -181
  11. package/src/chart/createSeriesData.ts +297 -297
  12. package/src/chart/createTreeData.ts +344 -344
  13. package/src/chart/defaults.ts +119 -119
  14. package/src/defineCanvasLayer.ts +23 -23
  15. package/src/defineCanvasPlugin.ts +38 -38
  16. package/src/defineSVGLayer.ts +23 -23
  17. package/src/defineSVGPlugin.ts +38 -38
  18. package/src/index.ts +8 -8
  19. package/src/layer/createLayer.ts +137 -137
  20. package/src/plugin/createPlugin.ts +487 -469
  21. package/src/test/createGraphData.test.ts +103 -103
  22. package/src/test/createTreeData.test.ts +97 -97
  23. package/src/test/simple-graph-test.js +51 -51
  24. package/src/test/simple-tree-test.js +58 -58
  25. package/src/types/Chart.ts +62 -62
  26. package/src/types/ChartContext.ts +41 -41
  27. package/src/types/Common.ts +4 -4
  28. package/src/types/Encoding.ts +42 -42
  29. package/src/types/Event.ts +25 -25
  30. package/src/types/Layers.ts +92 -92
  31. package/src/types/ModelData.ts +94 -94
  32. package/src/types/Plugin.ts +101 -98
  33. package/src/types/RawData.ts +67 -67
  34. package/src/types/RenderData.ts +15 -15
  35. package/src/types/Theme.ts +20 -20
  36. package/src/types/Validator.ts +35 -35
  37. package/src/types/index.ts +12 -12
  38. package/src/utils/aggregateUtils.ts +99 -99
  39. package/src/utils/colorUtils.ts +63 -63
  40. package/src/utils/commonUtils.ts +56 -56
  41. package/src/utils/dom-lifecycle.ts +164 -164
  42. package/src/utils/dom.ts +54 -54
  43. package/src/utils/errorMessage.ts +40 -40
  44. package/src/utils/index.ts +7 -7
  45. package/src/utils/observables.ts +16 -16
  46. package/src/utils/orbchartsUtils.ts +8 -8
  47. package/src/utils/validator.ts +127 -127
@@ -1,128 +1,128 @@
1
- import type {
2
- ColorType,
3
- ValidatorResult,
4
- ToBeTypes,
5
- ToBeOption,
6
- ValidatorRuleToBeTypes,
7
- ValidatorRuleToBe,
8
- ValidatorRuleToBeOption,
9
- ValidatorRule
10
- } from '../types'
11
- import { isFunction, isPlainObject } from './commonUtils'
12
-
13
- // function validateObject<T> (data: T, rules: Partial<ValidatorRule<T>>): ValidatorResult {
14
- // return { status: 'success', columnName: '', expectToBe: '' }
15
- // }
16
-
17
- // let test: ValidatorRule = {
18
- // name: {
19
- // toBeTypes: ['string']
20
- // },
21
- // labels: {
22
- // toBe: 'string | "auto"',
23
- // test: (value: any) => {
24
- // return value === 'auto' || typeof value === 'string'
25
- // }
26
- // }
27
- // }
28
-
29
- function getInvalidProperty<T> (data: T, rules: Partial<ValidatorRule<T>>) {
30
- // "toBeTypes" 的測試
31
- const testType: {[key in ToBeTypes]: (value: any) => boolean} = {
32
- string: (value: any) => typeof value === 'string',
33
- number: (value: any) => typeof value === 'number',
34
- boolean: (value: any) => typeof value === 'boolean',
35
- object: (value: any) => isPlainObject(value), // 嚴格判斷是否為純物件
36
- 'object[]': (value: any) => Array.isArray(value) && value.every((v: any) => isPlainObject(v)),
37
- 'string[]': (value: any) => Array.isArray(value) && value.every((v: any) => typeof v === 'string'),
38
- 'number[]': (value: any) => Array.isArray(value) && value.every((v: any) => typeof v === 'number'),
39
- Function: (value: any) => isFunction(value),
40
- null: (value: any) => value === null,
41
- undefined: (value: any) => value === undefined
42
- }
43
- // "toBeOption" 的測試
44
- const testOption: {[key in ToBeOption]: (value: any) => boolean} = {
45
- ColorType: (value: ColorType) => {
46
- return value === 'none'
47
- || value === 'data'
48
- || value === 'primary'
49
- || value === 'secondary'
50
- || value === 'dataContrast'
51
- || value === 'background'
52
- },
53
- }
54
-
55
- const failProperty = Object.keys(data).find((columnName: string) => {
56
- // 有定義規則
57
- if (rules[columnName as keyof T]) {
58
- const rule: ValidatorRuleToBeTypes | ValidatorRuleToBe | ValidatorRuleToBeOption = rules[columnName as keyof T]
59
- const value = data[columnName as keyof T]
60
- // 測試 "toBeTypes"
61
- if ((rule as ValidatorRuleToBeTypes).toBeTypes) {
62
- const toBeTypes = (rule as ValidatorRuleToBeTypes).toBeTypes
63
- const isCorrect = toBeTypes.some((toBeType) => testType[toBeType](value))
64
- if (isCorrect === false) {
65
- return true
66
- }
67
- }
68
- // 測試 "toBe"
69
- else if ((rule as ValidatorRuleToBe).toBe) {
70
- const { toBe, test } = rule as ValidatorRuleToBe
71
- const isCorrect = test(value)
72
- if (isCorrect === false) {
73
- return true
74
- }
75
- }
76
- // 測試 "toBeOption"
77
- else if ((rule as ValidatorRuleToBeOption).toBeOption) {
78
- const toBeOption = (rule as ValidatorRuleToBeOption).toBeOption
79
- const isCorrect = testOption[toBeOption](value)
80
- if (isCorrect === false) {
81
- return true
82
- }
83
- }
84
- }
85
- return false
86
- })
87
-
88
- return failProperty
89
- }
90
-
91
- export function validateObject<T> (data: T, rules: Partial<ValidatorRule<T>>): ValidatorResult {
92
- // if (data === undefined || data === null) {
93
- // // orbcharts所有的options都是允許空值的
94
- // return {
95
- // status: 'success',
96
- // columnName: '',
97
- // expectToBe: '',
98
- // }
99
- // }
100
- const invalidProperty = getInvalidProperty(data, rules)
101
- if (invalidProperty) {
102
- const rule = rules[invalidProperty as keyof T]
103
- const expectToBe = (rule as ValidatorRuleToBeTypes).toBeTypes
104
- ? (rule as ValidatorRuleToBeTypes).toBeTypes.join(' | ')
105
- : (rule as ValidatorRuleToBe).toBe
106
- ? (rule as ValidatorRuleToBe).toBe
107
- : (rule as ValidatorRuleToBeOption).toBeOption
108
- ? (rule as ValidatorRuleToBeOption).toBeOption
109
- : ''
110
-
111
- return {
112
- status: 'error',
113
- // message: createValidatorErrorMessage({
114
- // columnName: failProperty,
115
- // expect,
116
- // from
117
- // })
118
- columnName: invalidProperty as string,
119
- expectToBe: expectToBe,
120
- }
121
- } else {
122
- return {
123
- status: 'success',
124
- columnName: '',
125
- expectToBe: '',
126
- }
127
- }
1
+ import type {
2
+ ColorType,
3
+ ValidatorResult,
4
+ ToBeTypes,
5
+ ToBeOption,
6
+ ValidatorRuleToBeTypes,
7
+ ValidatorRuleToBe,
8
+ ValidatorRuleToBeOption,
9
+ ValidatorRule
10
+ } from '../types'
11
+ import { isFunction, isPlainObject } from './commonUtils'
12
+
13
+ // function validateObject<T> (data: T, rules: Partial<ValidatorRule<T>>): ValidatorResult {
14
+ // return { status: 'success', columnName: '', expectToBe: '' }
15
+ // }
16
+
17
+ // let test: ValidatorRule = {
18
+ // name: {
19
+ // toBeTypes: ['string']
20
+ // },
21
+ // labels: {
22
+ // toBe: 'string | "auto"',
23
+ // test: (value: any) => {
24
+ // return value === 'auto' || typeof value === 'string'
25
+ // }
26
+ // }
27
+ // }
28
+
29
+ function getInvalidProperty<T> (data: T, rules: Partial<ValidatorRule<T>>) {
30
+ // "toBeTypes" 的測試
31
+ const testType: {[key in ToBeTypes]: (value: any) => boolean} = {
32
+ string: (value: any) => typeof value === 'string',
33
+ number: (value: any) => typeof value === 'number',
34
+ boolean: (value: any) => typeof value === 'boolean',
35
+ object: (value: any) => isPlainObject(value), // 嚴格判斷是否為純物件
36
+ 'object[]': (value: any) => Array.isArray(value) && value.every((v: any) => isPlainObject(v)),
37
+ 'string[]': (value: any) => Array.isArray(value) && value.every((v: any) => typeof v === 'string'),
38
+ 'number[]': (value: any) => Array.isArray(value) && value.every((v: any) => typeof v === 'number'),
39
+ Function: (value: any) => isFunction(value),
40
+ null: (value: any) => value === null,
41
+ undefined: (value: any) => value === undefined
42
+ }
43
+ // "toBeOption" 的測試
44
+ const testOption: {[key in ToBeOption]: (value: any) => boolean} = {
45
+ ColorType: (value: ColorType) => {
46
+ return value === 'none'
47
+ || value === 'data'
48
+ || value === 'primary'
49
+ || value === 'secondary'
50
+ || value === 'dataContrast'
51
+ || value === 'background'
52
+ },
53
+ }
54
+
55
+ const failProperty = Object.keys(data).find((columnName: string) => {
56
+ // 有定義規則
57
+ if (rules[columnName as keyof T]) {
58
+ const rule: ValidatorRuleToBeTypes | ValidatorRuleToBe | ValidatorRuleToBeOption = rules[columnName as keyof T]
59
+ const value = data[columnName as keyof T]
60
+ // 測試 "toBeTypes"
61
+ if ((rule as ValidatorRuleToBeTypes).toBeTypes) {
62
+ const toBeTypes = (rule as ValidatorRuleToBeTypes).toBeTypes
63
+ const isCorrect = toBeTypes.some((toBeType) => testType[toBeType](value))
64
+ if (isCorrect === false) {
65
+ return true
66
+ }
67
+ }
68
+ // 測試 "toBe"
69
+ else if ((rule as ValidatorRuleToBe).toBe) {
70
+ const { toBe, test } = rule as ValidatorRuleToBe
71
+ const isCorrect = test(value)
72
+ if (isCorrect === false) {
73
+ return true
74
+ }
75
+ }
76
+ // 測試 "toBeOption"
77
+ else if ((rule as ValidatorRuleToBeOption).toBeOption) {
78
+ const toBeOption = (rule as ValidatorRuleToBeOption).toBeOption
79
+ const isCorrect = testOption[toBeOption](value)
80
+ if (isCorrect === false) {
81
+ return true
82
+ }
83
+ }
84
+ }
85
+ return false
86
+ })
87
+
88
+ return failProperty
89
+ }
90
+
91
+ export function validateObject<T> (data: T, rules: Partial<ValidatorRule<T>>): ValidatorResult {
92
+ // if (data === undefined || data === null) {
93
+ // // orbcharts所有的options都是允許空值的
94
+ // return {
95
+ // status: 'success',
96
+ // columnName: '',
97
+ // expectToBe: '',
98
+ // }
99
+ // }
100
+ const invalidProperty = getInvalidProperty(data, rules)
101
+ if (invalidProperty) {
102
+ const rule = rules[invalidProperty as keyof T]
103
+ const expectToBe = (rule as ValidatorRuleToBeTypes).toBeTypes
104
+ ? (rule as ValidatorRuleToBeTypes).toBeTypes.join(' | ')
105
+ : (rule as ValidatorRuleToBe).toBe
106
+ ? (rule as ValidatorRuleToBe).toBe
107
+ : (rule as ValidatorRuleToBeOption).toBeOption
108
+ ? (rule as ValidatorRuleToBeOption).toBeOption
109
+ : ''
110
+
111
+ return {
112
+ status: 'error',
113
+ // message: createValidatorErrorMessage({
114
+ // columnName: failProperty,
115
+ // expect,
116
+ // from
117
+ // })
118
+ columnName: invalidProperty as string,
119
+ expectToBe: expectToBe,
120
+ }
121
+ } else {
122
+ return {
123
+ status: 'success',
124
+ columnName: '',
125
+ expectToBe: '',
126
+ }
127
+ }
128
128
  }