@orbcharts/core 3.0.0-alpha.43 → 3.0.0-alpha.45

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