@orbcharts/core 3.0.0-alpha.48 → 3.0.0-alpha.49

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 (83) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +3 -2
  3. package/dist/orbcharts-core.umd.js +1 -1
  4. package/dist/src/types/Chart.d.ts +10 -12
  5. package/package.json +41 -41
  6. package/src/AbstractChart.ts +48 -48
  7. package/src/GridChart.ts +20 -20
  8. package/src/MultiGridChart.ts +20 -20
  9. package/src/MultiValueChart.ts +20 -20
  10. package/src/RelationshipChart.ts +20 -20
  11. package/src/SeriesChart.ts +20 -20
  12. package/src/TreeChart.ts +20 -20
  13. package/src/base/createBaseChart.ts +369 -368
  14. package/src/base/createBasePlugin.ts +95 -95
  15. package/src/defaults.ts +220 -220
  16. package/src/defineGridPlugin.ts +3 -3
  17. package/src/defineMultiGridPlugin.ts +3 -3
  18. package/src/defineMultiValuePlugin.ts +3 -3
  19. package/src/defineNoneDataPlugin.ts +4 -4
  20. package/src/defineRelationshipPlugin.ts +3 -3
  21. package/src/defineSeriesPlugin.ts +3 -3
  22. package/src/defineTreePlugin.ts +3 -3
  23. package/src/grid/computeGridData.ts +134 -134
  24. package/src/grid/createGridContextObserver.ts +155 -155
  25. package/src/grid/gridObservables.ts +600 -600
  26. package/src/index.ts +21 -21
  27. package/src/multiGrid/computeMultiGridData.ts +130 -130
  28. package/src/multiGrid/createMultiGridContextObserver.ts +40 -40
  29. package/src/multiGrid/multiGridObservables.ts +364 -364
  30. package/src/multiValue/computeMultiValueData.ts +143 -143
  31. package/src/multiValue/createMultiValueContextObserver.ts +12 -12
  32. package/src/relationship/computeRelationshipData.ts +118 -118
  33. package/src/relationship/createRelationshipContextObserver.ts +12 -12
  34. package/src/series/computeSeriesData.ts +90 -90
  35. package/src/series/createSeriesContextObserver.ts +93 -93
  36. package/src/series/seriesObservables.ts +175 -175
  37. package/src/tree/computeTreeData.ts +131 -131
  38. package/src/tree/createTreeContextObserver.ts +61 -61
  39. package/src/tree/treeObservables.ts +94 -94
  40. package/src/types/Chart.ts +50 -48
  41. package/src/types/ChartParams.ts +51 -51
  42. package/src/types/ComputedData.ts +83 -83
  43. package/src/types/ComputedDataGrid.ts +13 -13
  44. package/src/types/ComputedDataMultiGrid.ts +2 -2
  45. package/src/types/ComputedDataMultiValue.ts +9 -9
  46. package/src/types/ComputedDataRelationship.ts +19 -19
  47. package/src/types/ComputedDataSeries.ts +7 -7
  48. package/src/types/ComputedDataTree.ts +19 -19
  49. package/src/types/ContextObserver.ts +38 -38
  50. package/src/types/ContextObserverGrid.ts +42 -42
  51. package/src/types/ContextObserverMultiGrid.ts +15 -15
  52. package/src/types/ContextObserverMultiValue.ts +4 -4
  53. package/src/types/ContextObserverRelationship.ts +4 -4
  54. package/src/types/ContextObserverSeries.ts +29 -29
  55. package/src/types/ContextObserverTree.ts +11 -11
  56. package/src/types/ContextSubject.ts +18 -18
  57. package/src/types/Data.ts +45 -45
  58. package/src/types/DataFormatter.ts +74 -74
  59. package/src/types/DataFormatterGrid.ts +67 -67
  60. package/src/types/DataFormatterMultiGrid.ts +44 -44
  61. package/src/types/DataFormatterMultiValue.ts +23 -23
  62. package/src/types/DataFormatterRelationship.ts +25 -25
  63. package/src/types/DataFormatterSeries.ts +20 -20
  64. package/src/types/DataFormatterTree.ts +12 -12
  65. package/src/types/DataGrid.ts +11 -11
  66. package/src/types/DataMultiGrid.ts +6 -6
  67. package/src/types/DataMultiValue.ts +12 -12
  68. package/src/types/DataRelationship.ts +27 -27
  69. package/src/types/DataSeries.ts +11 -11
  70. package/src/types/DataTree.ts +20 -20
  71. package/src/types/Event.ts +153 -153
  72. package/src/types/Layout.ts +11 -11
  73. package/src/types/Padding.ts +5 -5
  74. package/src/types/Plugin.ts +60 -60
  75. package/src/types/TransformData.ts +7 -7
  76. package/src/types/index.ts +37 -37
  77. package/src/utils/commonUtils.ts +50 -50
  78. package/src/utils/d3Utils.ts +89 -89
  79. package/src/utils/index.ts +4 -4
  80. package/src/utils/observables.ts +201 -201
  81. package/src/utils/orbchartsUtils.ts +349 -349
  82. package/tsconfig.json +13 -13
  83. package/vite.config.js +44 -44
@@ -1,90 +1,90 @@
1
- import type { DataSeries, DataSeriesDatum } from '../types/DataSeries'
2
- import type { ComputedDataFn } from '../types/ComputedData'
3
- import type { ComputedDatumSeries } from '../types/ComputedDataSeries'
4
- import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, seriesColorPredicate } from '../utils/orbchartsUtils'
5
-
6
- export const computeSeriesData: ComputedDataFn<'series'> = (context) => {
7
- const { data = [], dataFormatter, chartParams } = context
8
- if (!data.length) {
9
- return []
10
- }
11
-
12
- let computedDataSeries: ComputedDatumSeries[][] = []
13
-
14
- try {
15
-
16
- const createComputedDatumSeries = (seriesData: number | DataSeriesDatum, seriesIndex: number, itemIndex: number, currentIndex: number): ComputedDatumSeries => {
17
- const defaultId = createDefaultDatumId(dataFormatter.type, seriesIndex, itemIndex)
18
- const seriesLabel = dataFormatter.seriesLabels[seriesIndex] || createDefaultSeriesLabel('series', seriesIndex)
19
- const color = seriesColorPredicate(seriesIndex, chartParams)
20
- if (typeof seriesData === 'number') {
21
- return {
22
- id: defaultId,
23
- index: currentIndex,
24
- seq: 0, // 先給預設值
25
- label: defaultId,
26
- description: '',
27
- data: {},
28
- value: seriesData,
29
- seriesIndex: seriesIndex,
30
- seriesLabel,
31
- color,
32
- visible: true // 先給預設值
33
- }
34
- } else {
35
- return {
36
- id: seriesData.id ? seriesData.id : defaultId,
37
- index: currentIndex,
38
- seq: 0, // 先給預設值
39
- label: seriesData.label ? seriesData.label : defaultId,
40
- description: seriesData.description,
41
- data: seriesData.data ?? {},
42
- value: seriesData.value,
43
- seriesIndex: seriesIndex,
44
- seriesLabel,
45
- color,
46
- visible: true // 先給預設值
47
- }
48
- }
49
- }
50
-
51
- computedDataSeries = data
52
- .map((seriesData, seriesIndex) => {
53
- if (Array.isArray(seriesData)) {
54
- return seriesData.map((item, itemIndex) =>
55
- createComputedDatumSeries(item, seriesIndex, itemIndex, computedDataSeries.length + itemIndex)
56
- )
57
- } else {
58
- return createComputedDatumSeries(seriesData, seriesIndex, 0, computedDataSeries.length)
59
- }
60
- })
61
- // 攤為一維陣列
62
- .flat()
63
- // 排序後給 seq
64
- .sort(dataFormatter.sort ?? undefined)
65
- .map((datum, index) => {
66
- datum.seq = index
67
- return datum
68
- })
69
- .map(datum => {
70
- datum.visible = dataFormatter.visibleFilter(datum, context)
71
- return datum
72
- })
73
- // 恢復原排序
74
- .sort((a, b) => a.index - b.index)
75
- // 依seriesIndex分組(二維陣列)
76
- .reduce((acc, datum) => {
77
- if (!acc[datum.seriesIndex]) {
78
- acc[datum.seriesIndex] = []
79
- }
80
- acc[datum.seriesIndex].push(datum)
81
- return acc
82
- }, [])
83
-
84
- } catch (e) {
85
- // console.error(e)
86
- throw Error(e)
87
- }
88
-
89
- return computedDataSeries
90
- }
1
+ import type { DataSeries, DataSeriesDatum } from '../types/DataSeries'
2
+ import type { ComputedDataFn } from '../types/ComputedData'
3
+ import type { ComputedDatumSeries } from '../types/ComputedDataSeries'
4
+ import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, seriesColorPredicate } from '../utils/orbchartsUtils'
5
+
6
+ export const computeSeriesData: ComputedDataFn<'series'> = (context) => {
7
+ const { data = [], dataFormatter, chartParams } = context
8
+ if (!data.length) {
9
+ return []
10
+ }
11
+
12
+ let computedDataSeries: ComputedDatumSeries[][] = []
13
+
14
+ try {
15
+
16
+ const createComputedDatumSeries = (seriesData: number | DataSeriesDatum, seriesIndex: number, itemIndex: number, currentIndex: number): ComputedDatumSeries => {
17
+ const defaultId = createDefaultDatumId(dataFormatter.type, seriesIndex, itemIndex)
18
+ const seriesLabel = dataFormatter.seriesLabels[seriesIndex] || createDefaultSeriesLabel('series', seriesIndex)
19
+ const color = seriesColorPredicate(seriesIndex, chartParams)
20
+ if (typeof seriesData === 'number') {
21
+ return {
22
+ id: defaultId,
23
+ index: currentIndex,
24
+ seq: 0, // 先給預設值
25
+ label: defaultId,
26
+ description: '',
27
+ data: {},
28
+ value: seriesData,
29
+ seriesIndex: seriesIndex,
30
+ seriesLabel,
31
+ color,
32
+ visible: true // 先給預設值
33
+ }
34
+ } else {
35
+ return {
36
+ id: seriesData.id ? seriesData.id : defaultId,
37
+ index: currentIndex,
38
+ seq: 0, // 先給預設值
39
+ label: seriesData.label ? seriesData.label : defaultId,
40
+ description: seriesData.description,
41
+ data: seriesData.data ?? {},
42
+ value: seriesData.value,
43
+ seriesIndex: seriesIndex,
44
+ seriesLabel,
45
+ color,
46
+ visible: true // 先給預設值
47
+ }
48
+ }
49
+ }
50
+
51
+ computedDataSeries = data
52
+ .map((seriesData, seriesIndex) => {
53
+ if (Array.isArray(seriesData)) {
54
+ return seriesData.map((item, itemIndex) =>
55
+ createComputedDatumSeries(item, seriesIndex, itemIndex, computedDataSeries.length + itemIndex)
56
+ )
57
+ } else {
58
+ return createComputedDatumSeries(seriesData, seriesIndex, 0, computedDataSeries.length)
59
+ }
60
+ })
61
+ // 攤為一維陣列
62
+ .flat()
63
+ // 排序後給 seq
64
+ .sort(dataFormatter.sort ?? undefined)
65
+ .map((datum, index) => {
66
+ datum.seq = index
67
+ return datum
68
+ })
69
+ .map(datum => {
70
+ datum.visible = dataFormatter.visibleFilter(datum, context)
71
+ return datum
72
+ })
73
+ // 恢復原排序
74
+ .sort((a, b) => a.index - b.index)
75
+ // 依seriesIndex分組(二維陣列)
76
+ .reduce((acc, datum) => {
77
+ if (!acc[datum.seriesIndex]) {
78
+ acc[datum.seriesIndex] = []
79
+ }
80
+ acc[datum.seriesIndex].push(datum)
81
+ return acc
82
+ }, [])
83
+
84
+ } catch (e) {
85
+ // console.error(e)
86
+ throw Error(e)
87
+ }
88
+
89
+ return computedDataSeries
90
+ }
@@ -1,93 +1,93 @@
1
- import { map, shareReplay } from 'rxjs'
2
- import type { ContextObserverFn } from '../types'
3
- import {
4
- seriesDataMapObservable,
5
- groupDataMapObservable } from '../utils/observables'
6
- import { highlightObservable, textSizePxObservable } from '../utils/observables'
7
-
8
- import { separateSeriesObservable, visibleComputedDataObservable, computedLayoutDataObservable, seriesLabelsObservable, seriesContainerPositionObservable, seriesContainerPositionMapObservable } from './seriesObservables'
9
-
10
- export const createSeriesContextObserver: ContextObserverFn<'series'> = ({ subject, observer }) => {
11
-
12
- const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
13
- shareReplay(1)
14
- )
15
-
16
- const separateSeries$ = separateSeriesObservable({
17
- fullDataFormatter$: observer.fullDataFormatter$
18
- })
19
-
20
- const visibleComputedData$ = visibleComputedDataObservable({
21
- computedData$: observer.computedData$,
22
- })
23
-
24
- const computedLayoutData$ = computedLayoutDataObservable({
25
- computedData$: observer.computedData$,
26
- fullDataFormatter$: observer.fullDataFormatter$
27
- }).pipe(
28
- shareReplay(1)
29
- )
30
-
31
- const visibleComputedLayoutData$ = visibleComputedDataObservable({
32
- computedData$: computedLayoutData$,
33
- })
34
-
35
- const datumList$ = observer.computedData$.pipe(
36
- map(d => d.flat())
37
- ).pipe(
38
- shareReplay(1)
39
- )
40
-
41
- const seriesHighlight$ = highlightObservable({
42
- datumList$,
43
- fullChartParams$: observer.fullChartParams$,
44
- event$: subject.event$
45
- }).pipe(
46
- shareReplay(1)
47
- )
48
-
49
- const seriesLabels$ = seriesLabelsObservable({
50
- computedData$: observer.computedData$,
51
- })
52
-
53
-
54
- const SeriesDataMap$ = seriesDataMapObservable({
55
- datumList$
56
- }).pipe(
57
- shareReplay(1)
58
- )
59
-
60
- const seriesContainerPosition$ = seriesContainerPositionObservable({
61
- computedData$: observer.computedData$,
62
- fullDataFormatter$: observer.fullDataFormatter$,
63
- layout$: observer.layout$,
64
- }).pipe(
65
- shareReplay(1)
66
- )
67
-
68
- const SeriesContainerPositionMap$ = seriesContainerPositionMapObservable({
69
- seriesContainerPosition$: seriesContainerPosition$,
70
- seriesLabels$: seriesLabels$,
71
- separateSeries$: separateSeries$,
72
- }).pipe(
73
- shareReplay(1)
74
- )
75
-
76
- return {
77
- fullParams$: observer.fullParams$,
78
- fullChartParams$: observer.fullChartParams$,
79
- fullDataFormatter$: observer.fullDataFormatter$,
80
- computedData$: observer.computedData$,
81
- layout$: observer.layout$,
82
- textSizePx$,
83
- visibleComputedData$,
84
- visibleComputedLayoutData$,
85
- separateSeries$,
86
- computedLayoutData$,
87
- seriesHighlight$,
88
- seriesLabels$,
89
- SeriesDataMap$,
90
- seriesContainerPosition$,
91
- SeriesContainerPositionMap$,
92
- }
93
- }
1
+ import { map, shareReplay } from 'rxjs'
2
+ import type { ContextObserverFn } from '../types'
3
+ import {
4
+ seriesDataMapObservable,
5
+ groupDataMapObservable } from '../utils/observables'
6
+ import { highlightObservable, textSizePxObservable } from '../utils/observables'
7
+
8
+ import { separateSeriesObservable, visibleComputedDataObservable, computedLayoutDataObservable, seriesLabelsObservable, seriesContainerPositionObservable, seriesContainerPositionMapObservable } from './seriesObservables'
9
+
10
+ export const createSeriesContextObserver: ContextObserverFn<'series'> = ({ subject, observer }) => {
11
+
12
+ const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
13
+ shareReplay(1)
14
+ )
15
+
16
+ const separateSeries$ = separateSeriesObservable({
17
+ fullDataFormatter$: observer.fullDataFormatter$
18
+ })
19
+
20
+ const visibleComputedData$ = visibleComputedDataObservable({
21
+ computedData$: observer.computedData$,
22
+ })
23
+
24
+ const computedLayoutData$ = computedLayoutDataObservable({
25
+ computedData$: observer.computedData$,
26
+ fullDataFormatter$: observer.fullDataFormatter$
27
+ }).pipe(
28
+ shareReplay(1)
29
+ )
30
+
31
+ const visibleComputedLayoutData$ = visibleComputedDataObservable({
32
+ computedData$: computedLayoutData$,
33
+ })
34
+
35
+ const datumList$ = observer.computedData$.pipe(
36
+ map(d => d.flat())
37
+ ).pipe(
38
+ shareReplay(1)
39
+ )
40
+
41
+ const seriesHighlight$ = highlightObservable({
42
+ datumList$,
43
+ fullChartParams$: observer.fullChartParams$,
44
+ event$: subject.event$
45
+ }).pipe(
46
+ shareReplay(1)
47
+ )
48
+
49
+ const seriesLabels$ = seriesLabelsObservable({
50
+ computedData$: observer.computedData$,
51
+ })
52
+
53
+
54
+ const SeriesDataMap$ = seriesDataMapObservable({
55
+ datumList$
56
+ }).pipe(
57
+ shareReplay(1)
58
+ )
59
+
60
+ const seriesContainerPosition$ = seriesContainerPositionObservable({
61
+ computedData$: observer.computedData$,
62
+ fullDataFormatter$: observer.fullDataFormatter$,
63
+ layout$: observer.layout$,
64
+ }).pipe(
65
+ shareReplay(1)
66
+ )
67
+
68
+ const SeriesContainerPositionMap$ = seriesContainerPositionMapObservable({
69
+ seriesContainerPosition$: seriesContainerPosition$,
70
+ seriesLabels$: seriesLabels$,
71
+ separateSeries$: separateSeries$,
72
+ }).pipe(
73
+ shareReplay(1)
74
+ )
75
+
76
+ return {
77
+ fullParams$: observer.fullParams$,
78
+ fullChartParams$: observer.fullChartParams$,
79
+ fullDataFormatter$: observer.fullDataFormatter$,
80
+ computedData$: observer.computedData$,
81
+ layout$: observer.layout$,
82
+ textSizePx$,
83
+ visibleComputedData$,
84
+ visibleComputedLayoutData$,
85
+ separateSeries$,
86
+ computedLayoutData$,
87
+ seriesHighlight$,
88
+ seriesLabels$,
89
+ SeriesDataMap$,
90
+ seriesContainerPosition$,
91
+ SeriesContainerPositionMap$,
92
+ }
93
+ }