@orbcharts/core 3.0.0-alpha.56 → 3.0.0-alpha.57

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +220 -216
  3. package/dist/orbcharts-core.umd.js +2 -2
  4. package/package.json +41 -41
  5. package/src/AbstractChart.ts +48 -48
  6. package/src/GridChart.ts +20 -20
  7. package/src/MultiGridChart.ts +20 -20
  8. package/src/MultiValueChart.ts +20 -20
  9. package/src/RelationshipChart.ts +20 -20
  10. package/src/SeriesChart.ts +20 -20
  11. package/src/TreeChart.ts +20 -20
  12. package/src/base/createBaseChart.ts +369 -369
  13. package/src/base/createBasePlugin.ts +95 -95
  14. package/src/defaults.ts +226 -226
  15. package/src/defineGridPlugin.ts +3 -3
  16. package/src/defineMultiGridPlugin.ts +3 -3
  17. package/src/defineMultiValuePlugin.ts +3 -3
  18. package/src/defineNoneDataPlugin.ts +4 -4
  19. package/src/defineRelationshipPlugin.ts +3 -3
  20. package/src/defineSeriesPlugin.ts +3 -3
  21. package/src/defineTreePlugin.ts +3 -3
  22. package/src/grid/computeGridData.ts +134 -134
  23. package/src/grid/createGridContextObserver.ts +155 -155
  24. package/src/grid/gridObservables.ts +613 -607
  25. package/src/index.ts +21 -21
  26. package/src/multiGrid/computeMultiGridData.ts +130 -130
  27. package/src/multiGrid/createMultiGridContextObserver.ts +41 -41
  28. package/src/multiGrid/multiGridObservables.ts +365 -365
  29. package/src/multiValue/computeMultiValueData.ts +143 -143
  30. package/src/multiValue/createMultiValueContextObserver.ts +12 -12
  31. package/src/relationship/computeRelationshipData.ts +118 -118
  32. package/src/relationship/createRelationshipContextObserver.ts +12 -12
  33. package/src/series/computeSeriesData.ts +90 -90
  34. package/src/series/createSeriesContextObserver.ts +93 -93
  35. package/src/series/seriesObservables.ts +175 -175
  36. package/src/tree/computeTreeData.ts +132 -132
  37. package/src/tree/createTreeContextObserver.ts +61 -61
  38. package/src/tree/treeObservables.ts +94 -94
  39. package/src/types/Chart.ts +50 -50
  40. package/src/types/ChartParams.ts +51 -51
  41. package/src/types/ComputedData.ts +83 -83
  42. package/src/types/ComputedDataGrid.ts +13 -13
  43. package/src/types/ComputedDataMultiGrid.ts +2 -2
  44. package/src/types/ComputedDataMultiValue.ts +9 -9
  45. package/src/types/ComputedDataRelationship.ts +19 -19
  46. package/src/types/ComputedDataSeries.ts +7 -7
  47. package/src/types/ComputedDataTree.ts +19 -19
  48. package/src/types/ContextObserver.ts +38 -38
  49. package/src/types/ContextObserverGrid.ts +42 -42
  50. package/src/types/ContextObserverMultiGrid.ts +16 -16
  51. package/src/types/ContextObserverMultiValue.ts +4 -4
  52. package/src/types/ContextObserverRelationship.ts +4 -4
  53. package/src/types/ContextObserverSeries.ts +29 -29
  54. package/src/types/ContextObserverTree.ts +11 -11
  55. package/src/types/ContextSubject.ts +18 -18
  56. package/src/types/Data.ts +45 -45
  57. package/src/types/DataFormatter.ts +74 -74
  58. package/src/types/DataFormatterGrid.ts +67 -67
  59. package/src/types/DataFormatterMultiGrid.ts +44 -44
  60. package/src/types/DataFormatterMultiValue.ts +23 -23
  61. package/src/types/DataFormatterRelationship.ts +25 -25
  62. package/src/types/DataFormatterSeries.ts +20 -20
  63. package/src/types/DataFormatterTree.ts +12 -12
  64. package/src/types/DataGrid.ts +11 -11
  65. package/src/types/DataMultiGrid.ts +6 -6
  66. package/src/types/DataMultiValue.ts +12 -12
  67. package/src/types/DataRelationship.ts +27 -27
  68. package/src/types/DataSeries.ts +11 -11
  69. package/src/types/DataTree.ts +20 -20
  70. package/src/types/Event.ts +153 -153
  71. package/src/types/Layout.ts +11 -11
  72. package/src/types/Padding.ts +5 -5
  73. package/src/types/Plugin.ts +60 -60
  74. package/src/types/TransformData.ts +7 -7
  75. package/src/types/index.ts +37 -37
  76. package/src/utils/commonUtils.ts +50 -50
  77. package/src/utils/d3Utils.ts +92 -92
  78. package/src/utils/index.ts +4 -4
  79. package/src/utils/observables.ts +201 -201
  80. package/src/utils/orbchartsUtils.ts +349 -349
  81. package/tsconfig.base.json +13 -13
  82. package/tsconfig.json +2 -2
  83. package/vite.config.js +22 -22
@@ -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
+ }