@orbcharts/core 3.0.0-beta.4 → 3.0.0-beta.5

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 (67) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +167 -163
  3. package/dist/orbcharts-core.umd.js +3 -3
  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 +235 -235
  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 +176 -176
  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 +110 -110
  37. package/src/multiValue/contextObserverCallback.ts +160 -160
  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 +129 -129
  49. package/src/tree/contextObserverCallback.ts +58 -58
  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/d3Scale.ts +198 -198
  54. package/src/utils/errorMessage.ts +42 -42
  55. package/src/utils/gridObservables.ts +683 -671
  56. package/src/utils/index.ts +9 -9
  57. package/src/utils/multiGridObservables.ts +392 -392
  58. package/src/utils/multiValueObservables.ts +661 -642
  59. package/src/utils/observables.ts +219 -219
  60. package/src/utils/orbchartsUtils.ts +377 -377
  61. package/src/utils/seriesObservables.ts +175 -175
  62. package/src/utils/treeObservables.ts +105 -105
  63. package/src/utils/validator.ts +126 -126
  64. package/tsconfig.base.json +13 -13
  65. package/tsconfig.json +2 -2
  66. package/vite-env.d.ts +6 -6
  67. package/vite.config.js +22 -22
@@ -1,10 +1,10 @@
1
- import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
-
3
- export const dataValidator: DataValidator<'relationship'> = (data: DataTypeMap<'relationship'>) => {
4
-
5
- return {
6
- status: 'success',
7
- columnName: '',
8
- expectToBe: ''
9
- }
1
+ import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
+
3
+ export const dataValidator: DataValidator<'relationship'> = (data: DataTypeMap<'relationship'>) => {
4
+
5
+ return {
6
+ status: 'success',
7
+ columnName: '',
8
+ expectToBe: ''
9
+ }
10
10
  }
@@ -1,88 +1,88 @@
1
- import type { DataSeries, DataSeriesDatum, ComputedDataFn, ComputedDatumSeries } from '../../lib/core-types'
2
- import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, seriesColorPredicate } from '../utils/orbchartsUtils'
3
-
4
- export const computedDataFn: ComputedDataFn<'series'> = (context) => {
5
- const { data = [], dataFormatter, chartParams } = context
6
- if (!data.length) {
7
- return []
8
- }
9
-
10
- let computedDataSeries: ComputedDatumSeries[][] = []
11
-
12
- try {
13
-
14
- const createComputedDatumSeries = (seriesData: number | DataSeriesDatum, seriesIndex: number, itemIndex: number, currentIndex: number): ComputedDatumSeries => {
15
- const defaultId = createDefaultDatumId(dataFormatter.type, seriesIndex, itemIndex)
16
- const seriesLabel = dataFormatter.seriesLabels[seriesIndex] || createDefaultSeriesLabel('series', seriesIndex)
17
- const color = seriesColorPredicate(seriesIndex, chartParams)
18
- if (typeof seriesData === 'number') {
19
- return {
20
- id: defaultId,
21
- index: currentIndex,
22
- seq: 0, // 先給預設值
23
- label: defaultId,
24
- description: '',
25
- data: {},
26
- value: seriesData,
27
- seriesIndex: seriesIndex,
28
- seriesLabel,
29
- color,
30
- visible: true // 先給預設值
31
- }
32
- } else {
33
- return {
34
- id: seriesData.id ? seriesData.id : defaultId,
35
- index: currentIndex,
36
- seq: 0, // 先給預設值
37
- label: seriesData.label ? seriesData.label : defaultId,
38
- description: seriesData.description,
39
- data: seriesData.data ?? {},
40
- value: seriesData.value,
41
- seriesIndex: seriesIndex,
42
- seriesLabel,
43
- color,
44
- visible: true // 先給預設值
45
- }
46
- }
47
- }
48
-
49
- computedDataSeries = data
50
- .map((seriesData, seriesIndex) => {
51
- if (Array.isArray(seriesData)) {
52
- return seriesData.map((item, itemIndex) =>
53
- createComputedDatumSeries(item, seriesIndex, itemIndex, computedDataSeries.length + itemIndex)
54
- )
55
- } else {
56
- return createComputedDatumSeries(seriesData, seriesIndex, 0, computedDataSeries.length)
57
- }
58
- })
59
- // 攤為一維陣列
60
- .flat()
61
- // 排序後給 seq
62
- .sort(dataFormatter.sort ?? undefined)
63
- .map((datum, index) => {
64
- datum.seq = index
65
- return datum
66
- })
67
- .map(datum => {
68
- datum.visible = dataFormatter.visibleFilter(datum, context)
69
- return datum
70
- })
71
- // 恢復原排序
72
- .sort((a, b) => a.index - b.index)
73
- // 依seriesIndex分組(二維陣列)
74
- .reduce((acc, datum) => {
75
- if (!acc[datum.seriesIndex]) {
76
- acc[datum.seriesIndex] = []
77
- }
78
- acc[datum.seriesIndex].push(datum)
79
- return acc
80
- }, [])
81
-
82
- } catch (e) {
83
- // console.error(e)
84
- throw Error(e)
85
- }
86
-
87
- return computedDataSeries
88
- }
1
+ import type { DataSeries, DataSeriesDatum, ComputedDataFn, ComputedDatumSeries } from '../../lib/core-types'
2
+ import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, seriesColorPredicate } from '../utils/orbchartsUtils'
3
+
4
+ export const computedDataFn: ComputedDataFn<'series'> = (context) => {
5
+ const { data = [], dataFormatter, chartParams } = context
6
+ if (!data.length) {
7
+ return []
8
+ }
9
+
10
+ let computedDataSeries: ComputedDatumSeries[][] = []
11
+
12
+ try {
13
+
14
+ const createComputedDatumSeries = (seriesData: number | DataSeriesDatum, seriesIndex: number, itemIndex: number, currentIndex: number): ComputedDatumSeries => {
15
+ const defaultId = createDefaultDatumId(dataFormatter.type, seriesIndex, itemIndex)
16
+ const seriesLabel = dataFormatter.seriesLabels[seriesIndex] || createDefaultSeriesLabel('series', seriesIndex)
17
+ const color = seriesColorPredicate(seriesIndex, chartParams)
18
+ if (typeof seriesData === 'number') {
19
+ return {
20
+ id: defaultId,
21
+ index: currentIndex,
22
+ seq: 0, // 先給預設值
23
+ label: defaultId,
24
+ description: '',
25
+ data: {},
26
+ value: seriesData,
27
+ seriesIndex: seriesIndex,
28
+ seriesLabel,
29
+ color,
30
+ visible: true // 先給預設值
31
+ }
32
+ } else {
33
+ return {
34
+ id: seriesData.id ? seriesData.id : defaultId,
35
+ index: currentIndex,
36
+ seq: 0, // 先給預設值
37
+ label: seriesData.label ? seriesData.label : defaultId,
38
+ description: seriesData.description,
39
+ data: seriesData.data ?? {},
40
+ value: seriesData.value,
41
+ seriesIndex: seriesIndex,
42
+ seriesLabel,
43
+ color,
44
+ visible: true // 先給預設值
45
+ }
46
+ }
47
+ }
48
+
49
+ computedDataSeries = data
50
+ .map((seriesData, seriesIndex) => {
51
+ if (Array.isArray(seriesData)) {
52
+ return seriesData.map((item, itemIndex) =>
53
+ createComputedDatumSeries(item, seriesIndex, itemIndex, computedDataSeries.length + itemIndex)
54
+ )
55
+ } else {
56
+ return createComputedDatumSeries(seriesData, seriesIndex, 0, computedDataSeries.length)
57
+ }
58
+ })
59
+ // 攤為一維陣列
60
+ .flat()
61
+ // 排序後給 seq
62
+ .sort(dataFormatter.sort ?? undefined)
63
+ .map((datum, index) => {
64
+ datum.seq = index
65
+ return datum
66
+ })
67
+ .map(datum => {
68
+ datum.visible = dataFormatter.visibleFilter(datum, context)
69
+ return datum
70
+ })
71
+ // 恢復原排序
72
+ .sort((a, b) => a.index - b.index)
73
+ // 依seriesIndex分組(二維陣列)
74
+ .reduce((acc, datum) => {
75
+ if (!acc[datum.seriesIndex]) {
76
+ acc[datum.seriesIndex] = []
77
+ }
78
+ acc[datum.seriesIndex].push(datum)
79
+ return acc
80
+ }, [])
81
+
82
+ } catch (e) {
83
+ // console.error(e)
84
+ throw Error(e)
85
+ }
86
+
87
+ return computedDataSeries
88
+ }
@@ -1,100 +1,100 @@
1
- import { map, shareReplay } from 'rxjs'
2
- import type { ContextObserverCallback } from '../../lib/core-types'
3
- import {
4
- seriesDataMapObservable,
5
- groupDataMapObservable } from '../utils/observables'
6
- import { highlightObservable, textSizePxObservable } from '../utils/observables'
7
-
8
- import {
9
- separateSeriesObservable,
10
- seriesVisibleComputedDataObservable,
11
- seriesComputedLayoutDataObservable,
12
- seriesLabelsObservable,
13
- seriesContainerPositionObservable,
14
- seriesContainerPositionMapObservable
15
- } from '../utils/seriesObservables'
16
-
17
- export const contextObserverCallback: ContextObserverCallback<'series'> = ({ subject, observer }) => {
18
-
19
- const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
20
- shareReplay(1)
21
- )
22
-
23
- const separateSeries$ = separateSeriesObservable({
24
- fullDataFormatter$: observer.fullDataFormatter$
25
- })
26
-
27
- const visibleComputedData$ = seriesVisibleComputedDataObservable({
28
- computedData$: observer.computedData$,
29
- })
30
-
31
- const computedLayoutData$ = seriesComputedLayoutDataObservable({
32
- computedData$: observer.computedData$,
33
- fullDataFormatter$: observer.fullDataFormatter$
34
- }).pipe(
35
- shareReplay(1)
36
- )
37
-
38
- const visibleComputedLayoutData$ = seriesVisibleComputedDataObservable({
39
- computedData$: computedLayoutData$,
40
- })
41
-
42
- const datumList$ = observer.computedData$.pipe(
43
- map(d => d.flat())
44
- ).pipe(
45
- shareReplay(1)
46
- )
47
-
48
- const seriesHighlight$ = highlightObservable({
49
- datumList$,
50
- fullChartParams$: observer.fullChartParams$,
51
- event$: subject.event$
52
- }).pipe(
53
- shareReplay(1)
54
- )
55
-
56
- const seriesLabels$ = seriesLabelsObservable({
57
- computedData$: observer.computedData$,
58
- })
59
-
60
-
61
- const SeriesDataMap$ = seriesDataMapObservable({
62
- datumList$
63
- }).pipe(
64
- shareReplay(1)
65
- )
66
-
67
- const seriesContainerPosition$ = seriesContainerPositionObservable({
68
- computedData$: observer.computedData$,
69
- fullDataFormatter$: observer.fullDataFormatter$,
70
- layout$: observer.layout$,
71
- }).pipe(
72
- shareReplay(1)
73
- )
74
-
75
- const SeriesContainerPositionMap$ = seriesContainerPositionMapObservable({
76
- seriesContainerPosition$: seriesContainerPosition$,
77
- seriesLabels$: seriesLabels$,
78
- separateSeries$: separateSeries$,
79
- }).pipe(
80
- shareReplay(1)
81
- )
82
-
83
- return {
84
- fullParams$: observer.fullParams$,
85
- fullChartParams$: observer.fullChartParams$,
86
- fullDataFormatter$: observer.fullDataFormatter$,
87
- computedData$: observer.computedData$,
88
- layout$: observer.layout$,
89
- textSizePx$,
90
- visibleComputedData$,
91
- visibleComputedLayoutData$,
92
- separateSeries$,
93
- computedLayoutData$,
94
- seriesHighlight$,
95
- seriesLabels$,
96
- SeriesDataMap$,
97
- seriesContainerPosition$,
98
- SeriesContainerPositionMap$,
99
- }
100
- }
1
+ import { map, shareReplay } from 'rxjs'
2
+ import type { ContextObserverCallback } from '../../lib/core-types'
3
+ import {
4
+ seriesDataMapObservable,
5
+ groupDataMapObservable } from '../utils/observables'
6
+ import { highlightObservable, textSizePxObservable } from '../utils/observables'
7
+
8
+ import {
9
+ separateSeriesObservable,
10
+ seriesVisibleComputedDataObservable,
11
+ seriesComputedLayoutDataObservable,
12
+ seriesLabelsObservable,
13
+ seriesContainerPositionObservable,
14
+ seriesContainerPositionMapObservable
15
+ } from '../utils/seriesObservables'
16
+
17
+ export const contextObserverCallback: ContextObserverCallback<'series'> = ({ subject, observer }) => {
18
+
19
+ const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
20
+ shareReplay(1)
21
+ )
22
+
23
+ const separateSeries$ = separateSeriesObservable({
24
+ fullDataFormatter$: observer.fullDataFormatter$
25
+ })
26
+
27
+ const visibleComputedData$ = seriesVisibleComputedDataObservable({
28
+ computedData$: observer.computedData$,
29
+ })
30
+
31
+ const computedLayoutData$ = seriesComputedLayoutDataObservable({
32
+ computedData$: observer.computedData$,
33
+ fullDataFormatter$: observer.fullDataFormatter$
34
+ }).pipe(
35
+ shareReplay(1)
36
+ )
37
+
38
+ const visibleComputedLayoutData$ = seriesVisibleComputedDataObservable({
39
+ computedData$: computedLayoutData$,
40
+ })
41
+
42
+ const datumList$ = observer.computedData$.pipe(
43
+ map(d => d.flat())
44
+ ).pipe(
45
+ shareReplay(1)
46
+ )
47
+
48
+ const seriesHighlight$ = highlightObservable({
49
+ datumList$,
50
+ fullChartParams$: observer.fullChartParams$,
51
+ event$: subject.event$
52
+ }).pipe(
53
+ shareReplay(1)
54
+ )
55
+
56
+ const seriesLabels$ = seriesLabelsObservable({
57
+ computedData$: observer.computedData$,
58
+ })
59
+
60
+
61
+ const SeriesDataMap$ = seriesDataMapObservable({
62
+ datumList$
63
+ }).pipe(
64
+ shareReplay(1)
65
+ )
66
+
67
+ const seriesContainerPosition$ = seriesContainerPositionObservable({
68
+ computedData$: observer.computedData$,
69
+ fullDataFormatter$: observer.fullDataFormatter$,
70
+ layout$: observer.layout$,
71
+ }).pipe(
72
+ shareReplay(1)
73
+ )
74
+
75
+ const SeriesContainerPositionMap$ = seriesContainerPositionMapObservable({
76
+ seriesContainerPosition$: seriesContainerPosition$,
77
+ seriesLabels$: seriesLabels$,
78
+ separateSeries$: separateSeries$,
79
+ }).pipe(
80
+ shareReplay(1)
81
+ )
82
+
83
+ return {
84
+ fullParams$: observer.fullParams$,
85
+ fullChartParams$: observer.fullChartParams$,
86
+ fullDataFormatter$: observer.fullDataFormatter$,
87
+ computedData$: observer.computedData$,
88
+ layout$: observer.layout$,
89
+ textSizePx$,
90
+ visibleComputedData$,
91
+ visibleComputedLayoutData$,
92
+ separateSeries$,
93
+ computedLayoutData$,
94
+ seriesHighlight$,
95
+ seriesLabels$,
96
+ SeriesDataMap$,
97
+ seriesContainerPosition$,
98
+ SeriesContainerPositionMap$,
99
+ }
100
+ }
@@ -1,42 +1,42 @@
1
- import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
2
- import { validateColumns } from '../utils/validator'
3
-
4
- export const dataFormatterValidator: DataFormatterValidator<'series'> = (dataFormatter: DataFormatterTypeMap<'series'>) => {
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
- }
40
- }
41
- return result
1
+ import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
2
+ import { validateColumns } from '../utils/validator'
3
+
4
+ export const dataFormatterValidator: DataFormatterValidator<'series'> = (dataFormatter: DataFormatterTypeMap<'series'>) => {
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
+ }
40
+ }
41
+ return result
42
42
  }
@@ -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<'series'> = (data: DataTypeMap<'series'>) => {
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
1
+ import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
+ import { validateColumns } from '../utils/validator'
3
+
4
+ export const dataValidator: DataValidator<'series'> = (data: DataTypeMap<'series'>) => {
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
13
13
  }