@orbcharts/core 3.0.2 → 3.0.3

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 (78) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +2345 -2229
  3. package/dist/orbcharts-core.umd.js +5 -4
  4. package/dist/src/{utils → multiValue}/multiValueObservables.d.ts +20 -10
  5. package/dist/src/utils/errorMessage.d.ts +5 -0
  6. package/dist/src/utils/index.d.ts +0 -1
  7. package/dist/src/utils/observables.d.ts +3 -2
  8. package/dist/src/utils/orbchartsUtils.d.ts +1 -0
  9. package/lib/core-types.ts +7 -7
  10. package/package.json +46 -46
  11. package/src/AbstractChart.ts +57 -57
  12. package/src/GridChart.ts +24 -24
  13. package/src/MultiGridChart.ts +24 -24
  14. package/src/MultiValueChart.ts +24 -24
  15. package/src/RelationshipChart.ts +24 -24
  16. package/src/SeriesChart.ts +24 -24
  17. package/src/TreeChart.ts +24 -24
  18. package/src/base/createBaseChart.ts +526 -506
  19. package/src/base/createBasePlugin.ts +154 -154
  20. package/src/base/validators/chartOptionsValidator.ts +23 -23
  21. package/src/base/validators/chartParamsValidator.ts +133 -133
  22. package/src/base/validators/elementValidator.ts +13 -13
  23. package/src/base/validators/pluginsValidator.ts +14 -14
  24. package/src/defaults.ts +283 -282
  25. package/src/defineGridPlugin.ts +3 -3
  26. package/src/defineMultiGridPlugin.ts +3 -3
  27. package/src/defineMultiValuePlugin.ts +3 -3
  28. package/src/defineNoneDataPlugin.ts +4 -4
  29. package/src/defineRelationshipPlugin.ts +3 -3
  30. package/src/defineSeriesPlugin.ts +3 -3
  31. package/src/defineTreePlugin.ts +3 -3
  32. package/src/grid/computedDataFn.ts +129 -129
  33. package/src/grid/contextObserverCallback.ts +201 -198
  34. package/src/grid/dataFormatterValidator.ts +125 -120
  35. package/src/grid/dataValidator.ts +12 -12
  36. package/src/{utils → grid}/gridObservables.ts +718 -705
  37. package/src/index.ts +20 -20
  38. package/src/multiGrid/computedDataFn.ts +123 -123
  39. package/src/multiGrid/contextObserverCallback.ts +75 -72
  40. package/src/multiGrid/dataFormatterValidator.ts +120 -115
  41. package/src/multiGrid/dataValidator.ts +12 -12
  42. package/src/{utils → multiGrid}/multiGridObservables.ts +401 -401
  43. package/src/multiValue/computedDataFn.ts +113 -113
  44. package/src/multiValue/contextObserverCallback.ts +328 -276
  45. package/src/multiValue/dataFormatterValidator.ts +94 -89
  46. package/src/multiValue/dataValidator.ts +12 -12
  47. package/src/{utils → multiValue}/multiValueObservables.ts +1219 -1044
  48. package/src/relationship/computedDataFn.ts +159 -159
  49. package/src/relationship/contextObserverCallback.ts +80 -80
  50. package/src/relationship/dataFormatterValidator.ts +13 -13
  51. package/src/relationship/dataValidator.ts +13 -13
  52. package/src/{utils → relationship}/relationshipObservables.ts +84 -84
  53. package/src/series/computedDataFn.ts +88 -88
  54. package/src/series/contextObserverCallback.ts +107 -107
  55. package/src/series/dataFormatterValidator.ts +46 -41
  56. package/src/series/dataValidator.ts +12 -12
  57. package/src/{utils → series}/seriesObservables.ts +175 -175
  58. package/src/tree/computedDataFn.ts +129 -129
  59. package/src/tree/contextObserverCallback.ts +58 -58
  60. package/src/tree/dataFormatterValidator.ts +13 -13
  61. package/src/tree/dataValidator.ts +13 -13
  62. package/src/{utils → tree}/treeObservables.ts +105 -105
  63. package/src/utils/commonUtils.ts +55 -55
  64. package/src/utils/d3Scale.ts +198 -198
  65. package/src/utils/errorMessage.ts +43 -42
  66. package/src/utils/index.ts +4 -10
  67. package/src/utils/observables.ts +293 -281
  68. package/src/utils/orbchartsUtils.ts +396 -377
  69. package/src/utils/validator.ts +126 -126
  70. package/tsconfig.base.json +13 -13
  71. package/tsconfig.json +2 -2
  72. package/vite-env.d.ts +6 -6
  73. package/vite.config.js +22 -22
  74. /package/dist/src/{utils → grid}/gridObservables.d.ts +0 -0
  75. /package/dist/src/{utils → multiGrid}/multiGridObservables.d.ts +0 -0
  76. /package/dist/src/{utils → relationship}/relationshipObservables.d.ts +0 -0
  77. /package/dist/src/{utils → series}/seriesObservables.d.ts +0 -0
  78. /package/dist/src/{utils → tree}/treeObservables.d.ts +0 -0
@@ -1,127 +1,127 @@
1
- import type {
2
- ColorType,
3
- ValidatorResult,
4
- ToBeTypes,
5
- ToBeOption,
6
- ValidatorRuleToBeTypes,
7
- ValidatorRuleToBe,
8
- ValidatorRuleToBeOption,
9
- ValidatorRule
10
- } from '../../lib/core-types'
11
- import { isFunction, isPlainObject } from './commonUtils'
12
- import { createValidatorErrorMessage } from './errorMessage'
13
-
14
-
15
-
16
- // let test: ValidatorRule = {
17
- // name: {
18
- // toBeTypes: ['string']
19
- // },
20
- // labels: {
21
- // toBe: 'string | "auto"',
22
- // test: (value: any) => {
23
- // return value === 'auto' || typeof value === 'string'
24
- // }
25
- // }
26
- // }
27
-
28
- function getInvalidColumn<T> (data: T, rules: Partial<ValidatorRule<T>>) {
29
- // "toBeTypes" 的測試
30
- const testType: {[key in ToBeTypes]: (value: any) => boolean} = {
31
- string: (value: any) => typeof value === 'string',
32
- number: (value: any) => typeof value === 'number',
33
- boolean: (value: any) => typeof value === 'boolean',
34
- object: (value: any) => isPlainObject(value), // 嚴格判斷是否為純物件
35
- 'object[]': (value: any) => Array.isArray(value) && value.every((v: any) => isPlainObject(v)),
36
- 'string[]': (value: any) => Array.isArray(value) && value.every((v: any) => typeof v === 'string'),
37
- 'number[]': (value: any) => Array.isArray(value) && value.every((v: any) => typeof v === 'number'),
38
- Function: (value: any) => isFunction(value),
39
- null: (value: any) => value === null,
40
- undefined: (value: any) => value === undefined
41
- }
42
- // "toBeOption" 的測試
43
- const testOption: {[key in ToBeOption]: (value: any) => boolean} = {
44
- ColorType: (value: ColorType) => {
45
- return value === 'none'
46
- || value === 'label'
47
- || value === 'primary'
48
- || value === 'secondary'
49
- || value === 'labelContrast'
50
- || value === 'background'
51
- },
52
- }
53
-
54
- const failColumn = Object.keys(data).find((columnName: string) => {
55
- // 有定義規則
56
- if (rules[columnName as keyof T]) {
57
- const rule: ValidatorRuleToBeTypes | ValidatorRuleToBe | ValidatorRuleToBeOption = rules[columnName as keyof T]
58
- const value = data[columnName as keyof T]
59
- // 測試 "toBeTypes"
60
- if ((rule as ValidatorRuleToBeTypes).toBeTypes) {
61
- const toBeTypes = (rule as ValidatorRuleToBeTypes).toBeTypes
62
- const isCorrect = toBeTypes.some((toBeType) => testType[toBeType](value))
63
- if (isCorrect === false) {
64
- return true
65
- }
66
- }
67
- // 測試 "toBe"
68
- else if ((rule as ValidatorRuleToBe).toBe) {
69
- const { toBe, test } = rule as ValidatorRuleToBe
70
- const isCorrect = test(value)
71
- if (isCorrect === false) {
72
- return true
73
- }
74
- }
75
- // 測試 "toBeOption"
76
- else if ((rule as ValidatorRuleToBeOption).toBeOption) {
77
- const toBeOption = (rule as ValidatorRuleToBeOption).toBeOption
78
- const isCorrect = testOption[toBeOption](value)
79
- if (isCorrect === false) {
80
- return true
81
- }
82
- }
83
- }
84
- return false
85
- })
86
-
87
- return failColumn
88
- }
89
-
90
- export function validateColumns<T> (data: T, rules: Partial<ValidatorRule<T>>): ValidatorResult {
91
- // if (data === undefined || data === null) {
92
- // // orbcharts所有的options都是允許空值的
93
- // return {
94
- // status: 'success',
95
- // columnName: '',
96
- // expectToBe: '',
97
- // }
98
- // }
99
- const invalidColumn = getInvalidColumn(data, rules)
100
- if (invalidColumn) {
101
- const rule = rules[invalidColumn as keyof T]
102
- const expectToBe = (rule as ValidatorRuleToBeTypes).toBeTypes
103
- ? (rule as ValidatorRuleToBeTypes).toBeTypes.join(' | ')
104
- : (rule as ValidatorRuleToBe).toBe
105
- ? (rule as ValidatorRuleToBe).toBe
106
- : (rule as ValidatorRuleToBeOption).toBeOption
107
- ? (rule as ValidatorRuleToBeOption).toBeOption
108
- : ''
109
-
110
- return {
111
- status: 'error',
112
- // message: createValidatorErrorMessage({
113
- // columnName: failColumn,
114
- // expect,
115
- // from
116
- // })
117
- columnName: invalidColumn as string,
118
- expectToBe: expectToBe,
119
- }
120
- } else {
121
- return {
122
- status: 'success',
123
- columnName: '',
124
- expectToBe: '',
125
- }
126
- }
1
+ import type {
2
+ ColorType,
3
+ ValidatorResult,
4
+ ToBeTypes,
5
+ ToBeOption,
6
+ ValidatorRuleToBeTypes,
7
+ ValidatorRuleToBe,
8
+ ValidatorRuleToBeOption,
9
+ ValidatorRule
10
+ } from '../../lib/core-types'
11
+ import { isFunction, isPlainObject } from './commonUtils'
12
+ import { createValidatorErrorMessage } from './errorMessage'
13
+
14
+
15
+
16
+ // let test: ValidatorRule = {
17
+ // name: {
18
+ // toBeTypes: ['string']
19
+ // },
20
+ // labels: {
21
+ // toBe: 'string | "auto"',
22
+ // test: (value: any) => {
23
+ // return value === 'auto' || typeof value === 'string'
24
+ // }
25
+ // }
26
+ // }
27
+
28
+ function getInvalidColumn<T> (data: T, rules: Partial<ValidatorRule<T>>) {
29
+ // "toBeTypes" 的測試
30
+ const testType: {[key in ToBeTypes]: (value: any) => boolean} = {
31
+ string: (value: any) => typeof value === 'string',
32
+ number: (value: any) => typeof value === 'number',
33
+ boolean: (value: any) => typeof value === 'boolean',
34
+ object: (value: any) => isPlainObject(value), // 嚴格判斷是否為純物件
35
+ 'object[]': (value: any) => Array.isArray(value) && value.every((v: any) => isPlainObject(v)),
36
+ 'string[]': (value: any) => Array.isArray(value) && value.every((v: any) => typeof v === 'string'),
37
+ 'number[]': (value: any) => Array.isArray(value) && value.every((v: any) => typeof v === 'number'),
38
+ Function: (value: any) => isFunction(value),
39
+ null: (value: any) => value === null,
40
+ undefined: (value: any) => value === undefined
41
+ }
42
+ // "toBeOption" 的測試
43
+ const testOption: {[key in ToBeOption]: (value: any) => boolean} = {
44
+ ColorType: (value: ColorType) => {
45
+ return value === 'none'
46
+ || value === 'label'
47
+ || value === 'primary'
48
+ || value === 'secondary'
49
+ || value === 'labelContrast'
50
+ || value === 'background'
51
+ },
52
+ }
53
+
54
+ const failColumn = Object.keys(data).find((columnName: string) => {
55
+ // 有定義規則
56
+ if (rules[columnName as keyof T]) {
57
+ const rule: ValidatorRuleToBeTypes | ValidatorRuleToBe | ValidatorRuleToBeOption = rules[columnName as keyof T]
58
+ const value = data[columnName as keyof T]
59
+ // 測試 "toBeTypes"
60
+ if ((rule as ValidatorRuleToBeTypes).toBeTypes) {
61
+ const toBeTypes = (rule as ValidatorRuleToBeTypes).toBeTypes
62
+ const isCorrect = toBeTypes.some((toBeType) => testType[toBeType](value))
63
+ if (isCorrect === false) {
64
+ return true
65
+ }
66
+ }
67
+ // 測試 "toBe"
68
+ else if ((rule as ValidatorRuleToBe).toBe) {
69
+ const { toBe, test } = rule as ValidatorRuleToBe
70
+ const isCorrect = test(value)
71
+ if (isCorrect === false) {
72
+ return true
73
+ }
74
+ }
75
+ // 測試 "toBeOption"
76
+ else if ((rule as ValidatorRuleToBeOption).toBeOption) {
77
+ const toBeOption = (rule as ValidatorRuleToBeOption).toBeOption
78
+ const isCorrect = testOption[toBeOption](value)
79
+ if (isCorrect === false) {
80
+ return true
81
+ }
82
+ }
83
+ }
84
+ return false
85
+ })
86
+
87
+ return failColumn
88
+ }
89
+
90
+ export function validateColumns<T> (data: T, rules: Partial<ValidatorRule<T>>): ValidatorResult {
91
+ // if (data === undefined || data === null) {
92
+ // // orbcharts所有的options都是允許空值的
93
+ // return {
94
+ // status: 'success',
95
+ // columnName: '',
96
+ // expectToBe: '',
97
+ // }
98
+ // }
99
+ const invalidColumn = getInvalidColumn(data, rules)
100
+ if (invalidColumn) {
101
+ const rule = rules[invalidColumn as keyof T]
102
+ const expectToBe = (rule as ValidatorRuleToBeTypes).toBeTypes
103
+ ? (rule as ValidatorRuleToBeTypes).toBeTypes.join(' | ')
104
+ : (rule as ValidatorRuleToBe).toBe
105
+ ? (rule as ValidatorRuleToBe).toBe
106
+ : (rule as ValidatorRuleToBeOption).toBeOption
107
+ ? (rule as ValidatorRuleToBeOption).toBeOption
108
+ : ''
109
+
110
+ return {
111
+ status: 'error',
112
+ // message: createValidatorErrorMessage({
113
+ // columnName: failColumn,
114
+ // expect,
115
+ // from
116
+ // })
117
+ columnName: invalidColumn as string,
118
+ expectToBe: expectToBe,
119
+ }
120
+ } else {
121
+ return {
122
+ status: 'success',
123
+ columnName: '',
124
+ expectToBe: '',
125
+ }
126
+ }
127
127
  }
@@ -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
  })
File without changes
File without changes