@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,116 +1,116 @@
1
- import type { DataFormatterValidator, DataFormatterTypeMap, ValidatorResult } from '../../lib/core-types'
2
- import { validateColumns } from '../utils/validator'
3
-
4
- export const dataFormatterValidator: DataFormatterValidator<'multiGrid'> = (dataFormatter: DataFormatterTypeMap<'multiGrid'>) => {
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) {
96
- return gridListResult
97
- }
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
1
+ import type { DataFormatterValidator, DataFormatterTypeMap, ValidatorResult } from '../../lib/core-types'
2
+ import { validateColumns } from '../utils/validator'
3
+
4
+ export const dataFormatterValidator: DataFormatterValidator<'multiGrid'> = (dataFormatter: DataFormatterTypeMap<'multiGrid'>) => {
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) {
96
+ return gridListResult
97
+ }
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
116
116
  }
@@ -1,13 +1,13 @@
1
- import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
- import { validateColumns } from '../utils/validator'
3
-
4
- export const dataValidator: DataValidator<'multiGrid'> = (data: DataTypeMap<'multiGrid'>) => {
5
- const result = validateColumns({ data }, {
6
- data: {
7
- toBe: 'DataGrid[]',
8
- // 畢免資料量過大檢查不完,不深度檢查
9
- test: (value) => Array.isArray(value)
10
- }
11
- })
12
- return result
1
+ import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
+ import { validateColumns } from '../utils/validator'
3
+
4
+ export const dataValidator: DataValidator<'multiGrid'> = (data: DataTypeMap<'multiGrid'>) => {
5
+ const result = validateColumns({ data }, {
6
+ data: {
7
+ toBe: 'DataGrid[]',
8
+ // 畢免資料量過大檢查不完,不深度檢查
9
+ test: (value) => Array.isArray(value)
10
+ }
11
+ })
12
+ return result
13
13
  }
@@ -1,110 +1,113 @@
1
- import type { DataMultiValueDatum, ComputedDataFn, ComputedDatumMultiValue } from '../../lib/core-types'
2
- import { createDefaultCategoryLabel, createDefaultDatumId, seriesColorPredicate } from '../utils/orbchartsUtils'
3
- import { isPlainObject } from '../utils'
4
-
5
- export const computedDataFn: ComputedDataFn<'multiValue'> = (context) => {
6
- const { data, dataFormatter, chartParams } = context
7
- if (!data.length) {
8
- return []
9
- }
10
-
11
- const defaultCategoryLabel = createDefaultCategoryLabel()
12
-
13
- let computedDataMultiValue: ComputedDatumMultiValue[][] = []
14
-
15
- try {
16
- const dataMultiValue: DataMultiValueDatum[] = data.map((d, i) => {
17
- if (Array.isArray(d)) {
18
- return {
19
- id: '',
20
- label: '',
21
- description: '',
22
- // tooltipContent: '',
23
- data: {},
24
- categoryLabel: defaultCategoryLabel,
25
- value: d
26
- }
27
- } else if (isPlainObject(d)) {
28
- return {
29
- id: d.id ?? '',
30
- label: d.label ?? '',
31
- description: d.description ?? '',
32
- // tooltipContent: _d.tooltipContent ?? '',
33
- data: d.data ?? {},
34
- categoryLabel: d.categoryLabel ?? defaultCategoryLabel,
35
- value: d.value
36
- }
37
- } else {
38
- return {
39
- id: '',
40
- label: '',
41
- description: '',
42
- // tooltipContent: '',
43
- data: {},
44
- categoryLabel: defaultCategoryLabel,
45
- value: []
46
- }
47
- }
48
- })
49
-
50
- const categoryLabels = (() => {
51
- // 先使用 dataFormatter.categoryLabels
52
- const CategoryLabelsSet = new Set(dataFormatter.categoryLabels)
53
- // 再加入 datum 中的 categoryLabel
54
- for (let datum of dataMultiValue) {
55
- const categoryLabel = datum.categoryLabel ?? defaultCategoryLabel
56
- CategoryLabelsSet.add(categoryLabel) // 不重覆
57
- }
58
- return Array.from(CategoryLabelsSet)
59
- })()
60
-
61
- // <categoryLabel, categoryIndex>
62
- const CategoryIndexMap = new Map<string, number>(
63
- categoryLabels.map((label, index) => [label, index])
64
- )
65
-
66
-
67
- let index = 0
68
-
69
- dataMultiValue.forEach((d, i) => {
70
- const currentIndex = index
71
- index++
72
-
73
- const defaultId = createDefaultDatumId(dataFormatter.type, i)
74
-
75
- const categoryIndex = CategoryIndexMap.get(d.categoryLabel) ?? 0
76
-
77
- const color = seriesColorPredicate(categoryIndex, chartParams)
78
-
79
- const computedDatum: ComputedDatumMultiValue = {
80
- id: d.id ? d.id : defaultId,
81
- index: currentIndex,
82
- label: d.label ? d.label : defaultId,
83
- description: d.description ?? '',
84
- // tooltipContent: _d.tooltipContent ? _d.tooltipContent : dataFormatter.tooltipContentFormat(_d, i, _i, context),
85
- data: d.data,
86
- datumIndex: i,
87
- value: d.value,
88
- categoryIndex,
89
- categoryLabel: d.categoryLabel,
90
- // valueLabel: formatValueToLabel(_d.value, dataFormatter.multiValue[_i].valueFormat),
91
- // axis: _i == 0 ? xScale(_d.value) : yScale(_d.value),
92
- visible: true, // 先給預設值
93
- color
94
- }
95
-
96
- computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
97
-
98
- // 依 categoryIndex 分組
99
- if (!computedDataMultiValue[categoryIndex]) {
100
- computedDataMultiValue[categoryIndex] = []
101
- }
102
- computedDataMultiValue[categoryIndex].push(computedDatum)
103
- })
104
- } catch (e) {
105
- // console.error(e)
106
- throw Error(e)
107
- }
108
-
109
- return computedDataMultiValue
110
- }
1
+ import type { DataMultiValueDatum, ComputedDataFn, ComputedDatumMultiValue } from '../../lib/core-types'
2
+ import { createDefaultCategoryLabel, createDefaultDatumId, seriesColorPredicate } from '../utils/orbchartsUtils'
3
+ import { isPlainObject } from '../utils'
4
+
5
+ export const computedDataFn: ComputedDataFn<'multiValue'> = (context) => {
6
+ const { data, dataFormatter, chartParams } = context
7
+ if (!data.length) {
8
+ return []
9
+ }
10
+
11
+ const defaultCategoryLabel = createDefaultCategoryLabel()
12
+
13
+ let computedDataMultiValue: ComputedDatumMultiValue[][] = []
14
+
15
+ try {
16
+ const dataMultiValue: DataMultiValueDatum[] = data.map((d, i) => {
17
+ if (Array.isArray(d)) {
18
+ return {
19
+ id: '',
20
+ label: '',
21
+ description: '',
22
+ // tooltipContent: '',
23
+ data: {},
24
+ categoryLabel: defaultCategoryLabel,
25
+ value: d
26
+ }
27
+ } else if (isPlainObject(d)) {
28
+ return {
29
+ id: d.id ?? '',
30
+ label: d.label ?? '',
31
+ description: d.description ?? '',
32
+ // tooltipContent: _d.tooltipContent ?? '',
33
+ data: d.data ?? {},
34
+ categoryLabel: d.categoryLabel ?? defaultCategoryLabel,
35
+ value: d.value
36
+ }
37
+ } else {
38
+ return {
39
+ id: '',
40
+ label: '',
41
+ description: '',
42
+ // tooltipContent: '',
43
+ data: {},
44
+ categoryLabel: defaultCategoryLabel,
45
+ value: []
46
+ }
47
+ }
48
+ })
49
+
50
+ const categoryLabels = (() => {
51
+ // 先使用 dataFormatter.categoryLabels
52
+ const CategoryLabelsSet = new Set(dataFormatter.categoryLabels)
53
+ // 再加入 datum 中的 categoryLabel
54
+ for (let datum of dataMultiValue) {
55
+ const categoryLabel = datum.categoryLabel ?? defaultCategoryLabel
56
+ CategoryLabelsSet.add(categoryLabel) // 不重覆
57
+ }
58
+ return Array.from(CategoryLabelsSet)
59
+ })()
60
+
61
+ // <categoryLabel, categoryIndex>
62
+ const CategoryIndexMap = new Map<string, number>(
63
+ categoryLabels.map((label, index) => [label, index])
64
+ )
65
+
66
+
67
+ let index = 0
68
+
69
+ dataMultiValue.forEach((d, i) => {
70
+ const currentIndex = index
71
+ index++
72
+
73
+ const defaultId = createDefaultDatumId(dataFormatter.type, i)
74
+
75
+ const categoryIndex = CategoryIndexMap.get(d.categoryLabel) ?? 0
76
+
77
+ const color = seriesColorPredicate(categoryIndex, chartParams)
78
+
79
+ const computedDatum: ComputedDatumMultiValue = {
80
+ id: d.id ? d.id : defaultId,
81
+ index: currentIndex,
82
+ label: d.label ? d.label : defaultId,
83
+ description: d.description ?? '',
84
+ // tooltipContent: _d.tooltipContent ? _d.tooltipContent : dataFormatter.tooltipContentFormat(_d, i, _i, context),
85
+ data: d.data,
86
+ datumIndex: i,
87
+ value: d.value,
88
+ categoryIndex,
89
+ categoryLabel: d.categoryLabel,
90
+ xValueIndex: dataFormatter.xAxis.valueIndex,
91
+ yValueIndex: dataFormatter.yAxis.valueIndex,
92
+ // valueLabel: formatValueToLabel(_d.value, dataFormatter.multiValue[_i].valueFormat),
93
+ // axis: _i == 0 ? xScale(_d.value) : yScale(_d.value),
94
+ visible: true, // 先給預設值
95
+ color,
96
+ _visibleValue: d.value // 預設和value相同
97
+ }
98
+
99
+ computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
100
+
101
+ // 依 categoryIndex 分組
102
+ if (!computedDataMultiValue[categoryIndex]) {
103
+ computedDataMultiValue[categoryIndex] = []
104
+ }
105
+ computedDataMultiValue[categoryIndex].push(computedDatum)
106
+ })
107
+ } catch (e) {
108
+ // console.error(e)
109
+ throw Error(e)
110
+ }
111
+
112
+ return computedDataMultiValue
113
+ }