@orbcharts/core 3.0.0-beta.1 → 3.0.0-beta.2

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 (66) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +4 -3
  3. package/dist/orbcharts-core.umd.js +1 -1
  4. package/lib/core-types.ts +7 -7
  5. package/package.json +42 -42
  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 +505 -505
  14. package/src/base/createBasePlugin.ts +153 -153
  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 +232 -232
  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 +155 -155
  29. package/src/grid/dataFormatterValidator.ts +101 -101
  30. package/src/grid/dataValidator.ts +12 -12
  31. package/src/index.ts +20 -20
  32. package/src/multiGrid/computedDataFn.ts +123 -123
  33. package/src/multiGrid/contextObserverCallback.ts +41 -41
  34. package/src/multiGrid/dataFormatterValidator.ts +115 -115
  35. package/src/multiGrid/dataValidator.ts +12 -12
  36. package/src/multiValue/computedDataFn.ts +176 -176
  37. package/src/multiValue/contextObserverCallback.ts +12 -12
  38. package/src/multiValue/dataFormatterValidator.ts +9 -9
  39. package/src/multiValue/dataValidator.ts +9 -9
  40. package/src/relationship/computedDataFn.ts +125 -125
  41. package/src/relationship/contextObserverCallback.ts +12 -12
  42. package/src/relationship/dataFormatterValidator.ts +9 -9
  43. package/src/relationship/dataValidator.ts +9 -9
  44. package/src/series/computedDataFn.ts +88 -88
  45. package/src/series/contextObserverCallback.ts +100 -100
  46. package/src/series/dataFormatterValidator.ts +41 -41
  47. package/src/series/dataValidator.ts +12 -12
  48. package/src/tree/computedDataFn.ts +130 -130
  49. package/src/tree/contextObserverCallback.ts +61 -61
  50. package/src/tree/dataFormatterValidator.ts +13 -13
  51. package/src/tree/dataValidator.ts +13 -13
  52. package/src/utils/commonUtils.ts +55 -55
  53. package/src/utils/d3Utils.ts +108 -108
  54. package/src/utils/errorMessage.ts +42 -42
  55. package/src/utils/gridObservables.ts +614 -611
  56. package/src/utils/index.ts +9 -9
  57. package/src/utils/multiGridObservables.ts +366 -366
  58. package/src/utils/observables.ts +219 -219
  59. package/src/utils/orbchartsUtils.ts +352 -352
  60. package/src/utils/seriesObservables.ts +175 -175
  61. package/src/utils/treeObservables.ts +94 -94
  62. package/src/utils/validator.ts +125 -125
  63. package/tsconfig.base.json +13 -13
  64. package/tsconfig.json +2 -2
  65. package/vite-env.d.ts +6 -6
  66. package/vite.config.js +22 -22
@@ -1,126 +1,126 @@
1
- import type {
2
- ValidatorResult,
3
- ToBeTypes,
4
- ToBeOption,
5
- ValidatorRuleToBeTypes,
6
- ValidatorRuleToBe,
7
- ValidatorRuleToBeOption,
8
- ValidatorRule
9
- } from '../../lib/core-types'
10
- import { isFunction, isPlainObject } from './commonUtils'
11
- import { createValidatorErrorMessage } from './errorMessage'
12
-
13
-
14
-
15
- // let test: ValidatorRule = {
16
- // name: {
17
- // toBeTypes: ['string']
18
- // },
19
- // labels: {
20
- // toBe: 'string | "auto"',
21
- // test: (value: any) => {
22
- // return value === 'auto' || typeof value === 'string'
23
- // }
24
- // }
25
- // }
26
-
27
- function getInvalidColumn<T> (data: T, rules: Partial<ValidatorRule<T>>) {
28
- // "toBeTypes" 的測試
29
- const testType: {[key in ToBeTypes]: (value: any) => boolean} = {
30
- string: (value: any) => typeof value === 'string',
31
- number: (value: any) => typeof value === 'number',
32
- boolean: (value: any) => typeof value === 'boolean',
33
- object: (value: any) => isPlainObject(value), // 嚴格判斷是否為純物件
34
- 'object[]': (value: any) => Array.isArray(value) && value.every((v: any) => isPlainObject(v)),
35
- 'string[]': (value: any) => Array.isArray(value) && value.every((v: any) => typeof v === 'string'),
36
- 'number[]': (value: any) => Array.isArray(value) && value.every((v: any) => typeof v === 'number'),
37
- Function: (value: any) => isFunction(value),
38
- null: (value: any) => value === null,
39
- undefined: (value: any) => value === undefined
40
- }
41
- // "toBeOption" 的測試
42
- const testOption: {[key in ToBeOption]: (value: any) => boolean} = {
43
- ColorType: (value: any) => {
44
- return value === 'none'
45
- || value === 'series'
46
- || value === 'primary'
47
- || value === 'secondary'
48
- || value === 'white'
49
- || value === 'background'
50
- }
51
- }
52
-
53
- const failColumn = Object.keys(data).find((columnName: string) => {
54
- // 有定義規則
55
- if (rules[columnName as keyof T]) {
56
- const rule: ValidatorRuleToBeTypes | ValidatorRuleToBe | ValidatorRuleToBeOption = rules[columnName as keyof T]
57
- const value = data[columnName as keyof T]
58
- // 測試 "toBeTypes"
59
- if ((rule as ValidatorRuleToBeTypes).toBeTypes) {
60
- const toBeTypes = (rule as ValidatorRuleToBeTypes).toBeTypes
61
- const isCorrect = toBeTypes.some((toBeType) => testType[toBeType](value))
62
- if (isCorrect === false) {
63
- return true
64
- }
65
- }
66
- // 測試 "toBe"
67
- else if ((rule as ValidatorRuleToBe).toBe) {
68
- const { toBe, test } = rule as ValidatorRuleToBe
69
- const isCorrect = test(value)
70
- if (isCorrect === false) {
71
- return true
72
- }
73
- }
74
- // 測試 "toBeOption"
75
- else if ((rule as ValidatorRuleToBeOption).toBeOption) {
76
- const toBeOption = (rule as ValidatorRuleToBeOption).toBeOption
77
- const isCorrect = testOption[toBeOption](value)
78
- if (isCorrect === false) {
79
- return true
80
- }
81
- }
82
- }
83
- return false
84
- })
85
-
86
- return failColumn
87
- }
88
-
89
- export function validateColumns<T> (data: T, rules: Partial<ValidatorRule<T>>): ValidatorResult {
90
- // if (data === undefined || data === null) {
91
- // // orbcharts所有的options都是允許空值的
92
- // return {
93
- // status: 'success',
94
- // columnName: '',
95
- // expectToBe: '',
96
- // }
97
- // }
98
- const invalidColumn = getInvalidColumn(data, rules)
99
- if (invalidColumn) {
100
- const rule = rules[invalidColumn as keyof T]
101
- const expectToBe = (rule as ValidatorRuleToBeTypes).toBeTypes
102
- ? (rule as ValidatorRuleToBeTypes).toBeTypes.join(' | ')
103
- : (rule as ValidatorRuleToBe).toBe
104
- ? (rule as ValidatorRuleToBe).toBe
105
- : (rule as ValidatorRuleToBeOption).toBeOption
106
- ? (rule as ValidatorRuleToBeOption).toBeOption
107
- : ''
108
-
109
- return {
110
- status: 'error',
111
- // message: createValidatorErrorMessage({
112
- // columnName: failColumn,
113
- // expect,
114
- // from
115
- // })
116
- columnName: invalidColumn as string,
117
- expectToBe: expectToBe,
118
- }
119
- } else {
120
- return {
121
- status: 'success',
122
- columnName: '',
123
- expectToBe: '',
124
- }
125
- }
1
+ import type {
2
+ ValidatorResult,
3
+ ToBeTypes,
4
+ ToBeOption,
5
+ ValidatorRuleToBeTypes,
6
+ ValidatorRuleToBe,
7
+ ValidatorRuleToBeOption,
8
+ ValidatorRule
9
+ } from '../../lib/core-types'
10
+ import { isFunction, isPlainObject } from './commonUtils'
11
+ import { createValidatorErrorMessage } from './errorMessage'
12
+
13
+
14
+
15
+ // let test: ValidatorRule = {
16
+ // name: {
17
+ // toBeTypes: ['string']
18
+ // },
19
+ // labels: {
20
+ // toBe: 'string | "auto"',
21
+ // test: (value: any) => {
22
+ // return value === 'auto' || typeof value === 'string'
23
+ // }
24
+ // }
25
+ // }
26
+
27
+ function getInvalidColumn<T> (data: T, rules: Partial<ValidatorRule<T>>) {
28
+ // "toBeTypes" 的測試
29
+ const testType: {[key in ToBeTypes]: (value: any) => boolean} = {
30
+ string: (value: any) => typeof value === 'string',
31
+ number: (value: any) => typeof value === 'number',
32
+ boolean: (value: any) => typeof value === 'boolean',
33
+ object: (value: any) => isPlainObject(value), // 嚴格判斷是否為純物件
34
+ 'object[]': (value: any) => Array.isArray(value) && value.every((v: any) => isPlainObject(v)),
35
+ 'string[]': (value: any) => Array.isArray(value) && value.every((v: any) => typeof v === 'string'),
36
+ 'number[]': (value: any) => Array.isArray(value) && value.every((v: any) => typeof v === 'number'),
37
+ Function: (value: any) => isFunction(value),
38
+ null: (value: any) => value === null,
39
+ undefined: (value: any) => value === undefined
40
+ }
41
+ // "toBeOption" 的測試
42
+ const testOption: {[key in ToBeOption]: (value: any) => boolean} = {
43
+ ColorType: (value: any) => {
44
+ return value === 'none'
45
+ || value === 'series'
46
+ || value === 'primary'
47
+ || value === 'secondary'
48
+ || value === 'white'
49
+ || value === 'background'
50
+ }
51
+ }
52
+
53
+ const failColumn = Object.keys(data).find((columnName: string) => {
54
+ // 有定義規則
55
+ if (rules[columnName as keyof T]) {
56
+ const rule: ValidatorRuleToBeTypes | ValidatorRuleToBe | ValidatorRuleToBeOption = rules[columnName as keyof T]
57
+ const value = data[columnName as keyof T]
58
+ // 測試 "toBeTypes"
59
+ if ((rule as ValidatorRuleToBeTypes).toBeTypes) {
60
+ const toBeTypes = (rule as ValidatorRuleToBeTypes).toBeTypes
61
+ const isCorrect = toBeTypes.some((toBeType) => testType[toBeType](value))
62
+ if (isCorrect === false) {
63
+ return true
64
+ }
65
+ }
66
+ // 測試 "toBe"
67
+ else if ((rule as ValidatorRuleToBe).toBe) {
68
+ const { toBe, test } = rule as ValidatorRuleToBe
69
+ const isCorrect = test(value)
70
+ if (isCorrect === false) {
71
+ return true
72
+ }
73
+ }
74
+ // 測試 "toBeOption"
75
+ else if ((rule as ValidatorRuleToBeOption).toBeOption) {
76
+ const toBeOption = (rule as ValidatorRuleToBeOption).toBeOption
77
+ const isCorrect = testOption[toBeOption](value)
78
+ if (isCorrect === false) {
79
+ return true
80
+ }
81
+ }
82
+ }
83
+ return false
84
+ })
85
+
86
+ return failColumn
87
+ }
88
+
89
+ export function validateColumns<T> (data: T, rules: Partial<ValidatorRule<T>>): ValidatorResult {
90
+ // if (data === undefined || data === null) {
91
+ // // orbcharts所有的options都是允許空值的
92
+ // return {
93
+ // status: 'success',
94
+ // columnName: '',
95
+ // expectToBe: '',
96
+ // }
97
+ // }
98
+ const invalidColumn = getInvalidColumn(data, rules)
99
+ if (invalidColumn) {
100
+ const rule = rules[invalidColumn as keyof T]
101
+ const expectToBe = (rule as ValidatorRuleToBeTypes).toBeTypes
102
+ ? (rule as ValidatorRuleToBeTypes).toBeTypes.join(' | ')
103
+ : (rule as ValidatorRuleToBe).toBe
104
+ ? (rule as ValidatorRuleToBe).toBe
105
+ : (rule as ValidatorRuleToBeOption).toBeOption
106
+ ? (rule as ValidatorRuleToBeOption).toBeOption
107
+ : ''
108
+
109
+ return {
110
+ status: 'error',
111
+ // message: createValidatorErrorMessage({
112
+ // columnName: failColumn,
113
+ // expect,
114
+ // from
115
+ // })
116
+ columnName: invalidColumn as string,
117
+ expectToBe: expectToBe,
118
+ }
119
+ } else {
120
+ return {
121
+ status: 'success',
122
+ columnName: '',
123
+ expectToBe: '',
124
+ }
125
+ }
126
126
  }
@@ -1,14 +1,14 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "./dist/",
4
- "sourceMap": true,
5
- "noImplicitAny": true,
6
- "module": "esnext",
7
- "target": "es5",
8
- "jsx": "react",
9
- "allowJs": true,
10
- "moduleResolution": "node",
11
- "allowSyntheticDefaultImports" : true,
12
- "esModuleInterop" : true
13
- }
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./dist/",
4
+ "sourceMap": true,
5
+ "noImplicitAny": true,
6
+ "module": "esnext",
7
+ "target": "es5",
8
+ "jsx": "react",
9
+ "allowJs": true,
10
+ "moduleResolution": "node",
11
+ "allowSyntheticDefaultImports" : true,
12
+ "esModuleInterop" : true
13
+ }
14
14
  }
package/tsconfig.json CHANGED
@@ -1,3 +1,3 @@
1
- {
2
- "extends": "./tsconfig.base.json"
1
+ {
2
+ "extends": "./tsconfig.base.json"
3
3
  }
package/vite-env.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- interface ImportMetaEnv {
2
- readonly MODE: 'development' | 'production'
3
- }
4
-
5
- interface ImportMeta {
6
- readonly env: ImportMetaEnv;
1
+ interface ImportMetaEnv {
2
+ readonly MODE: 'development' | 'production'
3
+ }
4
+
5
+ interface ImportMeta {
6
+ readonly env: ImportMetaEnv;
7
7
  }
package/vite.config.js CHANGED
@@ -1,23 +1,23 @@
1
- import { defineConfig } from 'vite'
2
- import dts from 'vite-plugin-dts'
3
-
4
- export default defineConfig(({ command, mode }) => {
5
- return {
6
- plugins: [
7
- dts({
8
- insertTypesEntry: true
9
- })
10
- ],
11
- compilerOptions: {
12
- composite: true
13
- },
14
- build: {
15
- lib: {
16
- entry: "src/index.ts",
17
- name: 'orbcharts-core',
18
- formats: ["es", "umd"],
19
- fileName: format => `orbcharts-core.${format}.js`
20
- },
21
- }
22
- }
1
+ import { defineConfig } from 'vite'
2
+ import dts from 'vite-plugin-dts'
3
+
4
+ export default defineConfig(({ command, mode }) => {
5
+ return {
6
+ plugins: [
7
+ dts({
8
+ insertTypesEntry: true
9
+ })
10
+ ],
11
+ compilerOptions: {
12
+ composite: true
13
+ },
14
+ build: {
15
+ lib: {
16
+ entry: "src/index.ts",
17
+ name: 'orbcharts-core',
18
+ formats: ["es", "umd"],
19
+ fileName: format => `orbcharts-core.${format}.js`
20
+ },
21
+ }
22
+ }
23
23
  })