@orbcharts/core 3.0.0-alpha.39 → 3.0.0-alpha.40

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +6 -6
  3. package/dist/orbcharts-core.umd.js +1 -1
  4. package/dist/src/types/ContextObserverGrid.d.ts +1 -1
  5. package/dist/src/types/ContextObserverSeries.d.ts +1 -1
  6. package/dist/src/types/ContextObserverTree.d.ts +1 -1
  7. package/dist/src/utils/observables.d.ts +5 -5
  8. package/package.json +41 -41
  9. package/src/AbstractChart.ts +48 -48
  10. package/src/GridChart.ts +20 -20
  11. package/src/MultiGridChart.ts +20 -20
  12. package/src/MultiValueChart.ts +20 -20
  13. package/src/RelationshipChart.ts +20 -20
  14. package/src/SeriesChart.ts +20 -20
  15. package/src/TreeChart.ts +20 -20
  16. package/src/base/createBaseChart.ts +367 -367
  17. package/src/base/createBasePlugin.ts +89 -89
  18. package/src/defaults.ts +247 -247
  19. package/src/defineGridPlugin.ts +3 -3
  20. package/src/defineMultiGridPlugin.ts +3 -3
  21. package/src/defineMultiValuePlugin.ts +3 -3
  22. package/src/defineNoneDataPlugin.ts +4 -4
  23. package/src/defineRelationshipPlugin.ts +3 -3
  24. package/src/defineSeriesPlugin.ts +3 -3
  25. package/src/defineTreePlugin.ts +3 -3
  26. package/src/grid/computeGridData.ts +205 -205
  27. package/src/grid/createGridContextObserver.ts +124 -124
  28. package/src/grid/gridObservables.ts +486 -486
  29. package/src/index.ts +21 -21
  30. package/src/multiGrid/computeMultiGridData.ts +173 -173
  31. package/src/multiGrid/createMultiGridContextObserver.ts +34 -34
  32. package/src/multiGrid/multiGridObservables.ts +285 -285
  33. package/src/multiValue/computeMultiValueData.ts +136 -136
  34. package/src/multiValue/createMultiValueContextObserver.ts +12 -12
  35. package/src/relationship/computeRelationshipData.ts +106 -106
  36. package/src/relationship/createRelationshipContextObserver.ts +12 -12
  37. package/src/series/computeSeriesData.ts +153 -153
  38. package/src/series/createSeriesContextObserver.ts +33 -33
  39. package/src/series/seriesObservables.ts +23 -23
  40. package/src/tree/computeTreeData.ts +128 -128
  41. package/src/tree/createTreeContextObserver.ts +56 -56
  42. package/src/tree/treeObservables.ts +94 -94
  43. package/src/types/Chart.ts +48 -48
  44. package/src/types/ChartParams.ts +51 -51
  45. package/src/types/ComputedData.ts +82 -82
  46. package/src/types/ComputedDataGrid.ts +13 -13
  47. package/src/types/ComputedDataMultiGrid.ts +2 -2
  48. package/src/types/ComputedDataMultiValue.ts +9 -9
  49. package/src/types/ComputedDataRelationship.ts +19 -19
  50. package/src/types/ComputedDataSeries.ts +7 -7
  51. package/src/types/ComputedDataTree.ts +19 -19
  52. package/src/types/ContextObserver.ts +38 -38
  53. package/src/types/ContextObserverGrid.ts +33 -33
  54. package/src/types/ContextObserverMultiGrid.ts +27 -27
  55. package/src/types/ContextObserverMultiValue.ts +4 -4
  56. package/src/types/ContextObserverRelationship.ts +4 -4
  57. package/src/types/ContextObserverSeries.ts +7 -7
  58. package/src/types/ContextObserverTree.ts +10 -10
  59. package/src/types/ContextSubject.ts +18 -18
  60. package/src/types/Data.ts +45 -45
  61. package/src/types/DataFormatter.ts +95 -95
  62. package/src/types/DataFormatterGrid.ts +55 -55
  63. package/src/types/DataFormatterMultiGrid.ts +42 -42
  64. package/src/types/DataFormatterMultiValue.ts +20 -20
  65. package/src/types/DataFormatterRelationship.ts +22 -22
  66. package/src/types/DataFormatterSeries.ts +29 -29
  67. package/src/types/DataFormatterTree.ts +12 -12
  68. package/src/types/DataGrid.ts +11 -11
  69. package/src/types/DataMultiGrid.ts +6 -6
  70. package/src/types/DataMultiValue.ts +12 -12
  71. package/src/types/DataRelationship.ts +27 -27
  72. package/src/types/DataSeries.ts +11 -11
  73. package/src/types/DataTree.ts +20 -20
  74. package/src/types/Event.ts +153 -153
  75. package/src/types/Layout.ts +11 -11
  76. package/src/types/Padding.ts +5 -5
  77. package/src/types/Plugin.ts +60 -60
  78. package/src/types/TransformData.ts +7 -7
  79. package/src/types/index.ts +37 -37
  80. package/src/utils/commonUtils.ts +50 -50
  81. package/src/utils/d3Utils.ts +89 -89
  82. package/src/utils/index.ts +4 -4
  83. package/src/utils/observables.ts +181 -183
  84. package/src/utils/orbchartsUtils.ts +253 -253
  85. package/tsconfig.json +13 -13
  86. package/vite.config.js +44 -44
@@ -1,153 +1,153 @@
1
- import type { DataSeries, DataSeriesDatum } from '../types/DataSeries'
2
- import type { ComputedDataFn } from '../types/ComputedData'
3
- import type { ComputedDataSeries, ComputedDatumSeries } from '../types/ComputedDataSeries'
4
- import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, seriesColorPredicate } from '../utils/orbchartsUtils'
5
-
6
- interface SortValue {
7
- rowIndex: number
8
- columnIndex: number
9
- index: number
10
- datum: number | DataSeriesDatum
11
- }
12
-
13
- type GetSortedIndex = (computedDataSeries: ComputedDatumSeries[], rowIndex: number, columnIndex: number) => number
14
-
15
- function createSortedIndexMap (data: DataSeries, sort: (a: number | DataSeriesDatum, b: number | DataSeriesDatum) => number): Map<string, number> {
16
-
17
- const SortedIndexMap: Map<string, number> = new Map() // Map<[rowIndex, columnIndex], sortedIndex>
18
-
19
- let _data = Object.assign([], data) as DataSeries
20
- // 建立排序所需資料的物件
21
- let sortValueData: SortValue[] = []
22
- _data.forEach((d, i) => {
23
- if (Array.isArray(d)) {
24
- d.forEach((_d, _i) => {
25
- sortValueData.push({
26
- rowIndex: i,
27
- columnIndex: _i,
28
- index: -1,
29
- datum: _d
30
- })
31
- })
32
- } else {
33
- sortValueData.push({
34
- rowIndex: i,
35
- columnIndex: 0,
36
- index: -1,
37
- datum: d
38
- })
39
- }
40
- })
41
- // 排序
42
- sortValueData.sort((a, b) => sort(a.datum, b.datum))
43
- // 取得排序後的index
44
- sortValueData = sortValueData.map((d, i) => {
45
- return {
46
- ...d,
47
- index: i
48
- }
49
- })
50
- // 建立SortedIndexMap
51
- sortValueData.forEach(d => {
52
- SortedIndexMap.set(String([d.rowIndex, d.columnIndex]), d.index)
53
- })
54
-
55
- return SortedIndexMap
56
- }
57
-
58
- export const computeSeriesData: ComputedDataFn<'series'> = (context) => {
59
- const { data = [], dataFormatter, chartParams } = context
60
- if (!data.length) {
61
- return []
62
- }
63
-
64
- const computedDataSeries: ComputedDatumSeries[] = []
65
-
66
- try {
67
- // 取得排序後的索引
68
- const getSortedIndex: GetSortedIndex = ((hasSort: boolean) => {
69
- if (hasSort) {
70
- // 資料索引對應排序後的索引 Map<[rowIndex, columnIndex], sortedIndex>
71
- const SortedIndexMap: Map<string, number> = createSortedIndexMap(data, dataFormatter.sort)
72
- return (computedDataSeries: ComputedDatumSeries[], rowIndex: number, columnIndex: number) => {
73
- return SortedIndexMap.get(String([rowIndex, columnIndex]))
74
- }
75
- } else {
76
- return (computedDataSeries: ComputedDatumSeries[], rowIndex: number, columnIndex: number) => {
77
- return computedDataSeries.length
78
- }
79
- }
80
- })(dataFormatter.sort != null)
81
-
82
- // 資料索引對應排序後的索引 Map<[rowIndex, columnIndex], sortedIndex>
83
- // let SortedIndexMap: Map<string, number> = new Map()
84
- // if (dataFormatter.sort) {
85
- // SortedIndexMap = createSortedIndexMap(data, dataFormatter.sort)
86
- // }
87
-
88
- const createComputedDatumSeries = (detailData: number | DataSeriesDatum, rowIndex: number, columnIndex: number, currentIndex: number, sortedIndex: number): ComputedDatumSeries => {
89
- const defaultId = createDefaultDatumId(dataFormatter.type, rowIndex, columnIndex)
90
- // const seriesLabel = dataFormatter.mapSeries(detailData, rowIndex, columnIndex, context)
91
- const seriesLabel = dataFormatter.seriesLabels[rowIndex] || createDefaultSeriesLabel('series', rowIndex)
92
- // const color = dataFormatter.colorsPredicate(detailData, rowIndex, columnIndex, context)
93
- const color = seriesColorPredicate(rowIndex, chartParams)
94
- const visible = dataFormatter.visibleFilter(detailData, rowIndex, columnIndex, context)
95
- if (typeof detailData === 'number') {
96
- return {
97
- id: defaultId,
98
- index: currentIndex,
99
- sortedIndex,
100
- label: defaultId,
101
- description: '',
102
- // tooltipContent: dataFormatter.tooltipContentFormat(detailData, rowIndex, columnIndex, context),
103
- data: {},
104
- value: detailData,
105
- // valueLabel: formatValueToLabel(detailData, dataFormatter.valueFormat),
106
- seriesIndex: rowIndex,
107
- seriesLabel,
108
- color,
109
- visible
110
- }
111
- } else {
112
- return {
113
- id: detailData.id ? detailData.id : defaultId,
114
- index: currentIndex,
115
- sortedIndex,
116
- label: detailData.label ? detailData.label : defaultId,
117
- description: detailData.description,
118
- // tooltipContent: detailData.tooltipContent ? detailData.tooltipContent : dataFormatter.tooltipContentFormat(detailData, rowIndex, columnIndex, context),
119
- data: detailData.data ?? {},
120
- value: detailData.value,
121
- // valueLabel: formatValueToLabel(detailData.value, dataFormatter.valueFormat),
122
- seriesIndex: rowIndex,
123
- seriesLabel,
124
- color,
125
- visible
126
- }
127
- }
128
- }
129
-
130
- data.forEach((mainData, rowIndex) => {
131
- if (Array.isArray(mainData)) {
132
- mainData.forEach((detailData, columnIndex) => {
133
- const sortedIndex = getSortedIndex(computedDataSeries, rowIndex, columnIndex)
134
- const datum = createComputedDatumSeries(detailData, rowIndex, columnIndex, computedDataSeries.length, sortedIndex)
135
- computedDataSeries.push(datum)
136
- })
137
- } else {
138
- const sortedIndex = getSortedIndex(computedDataSeries, rowIndex, 0)
139
- const datum = createComputedDatumSeries(mainData, rowIndex, 0, computedDataSeries.length, sortedIndex) // 只有一維陣列所以columnIndex為0
140
- computedDataSeries.push(datum)
141
- }
142
- })
143
-
144
- // if (dataFormatter.sort != null) {
145
- // computedDataSeries.sort((a, b) => a.sortedIndex - b.sortedIndex)
146
- // }
147
- } catch (e) {
148
- // console.error(e)
149
- throw Error(e)
150
- }
151
-
152
- return computedDataSeries
153
- }
1
+ import type { DataSeries, DataSeriesDatum } from '../types/DataSeries'
2
+ import type { ComputedDataFn } from '../types/ComputedData'
3
+ import type { ComputedDataSeries, ComputedDatumSeries } from '../types/ComputedDataSeries'
4
+ import { formatValueToLabel, createDefaultDatumId, createDefaultSeriesLabel, seriesColorPredicate } from '../utils/orbchartsUtils'
5
+
6
+ interface SortValue {
7
+ rowIndex: number
8
+ columnIndex: number
9
+ index: number
10
+ datum: number | DataSeriesDatum
11
+ }
12
+
13
+ type GetSortedIndex = (computedDataSeries: ComputedDatumSeries[], rowIndex: number, columnIndex: number) => number
14
+
15
+ function createSortedIndexMap (data: DataSeries, sort: (a: number | DataSeriesDatum, b: number | DataSeriesDatum) => number): Map<string, number> {
16
+
17
+ const SortedIndexMap: Map<string, number> = new Map() // Map<[rowIndex, columnIndex], sortedIndex>
18
+
19
+ let _data = Object.assign([], data) as DataSeries
20
+ // 建立排序所需資料的物件
21
+ let sortValueData: SortValue[] = []
22
+ _data.forEach((d, i) => {
23
+ if (Array.isArray(d)) {
24
+ d.forEach((_d, _i) => {
25
+ sortValueData.push({
26
+ rowIndex: i,
27
+ columnIndex: _i,
28
+ index: -1,
29
+ datum: _d
30
+ })
31
+ })
32
+ } else {
33
+ sortValueData.push({
34
+ rowIndex: i,
35
+ columnIndex: 0,
36
+ index: -1,
37
+ datum: d
38
+ })
39
+ }
40
+ })
41
+ // 排序
42
+ sortValueData.sort((a, b) => sort(a.datum, b.datum))
43
+ // 取得排序後的index
44
+ sortValueData = sortValueData.map((d, i) => {
45
+ return {
46
+ ...d,
47
+ index: i
48
+ }
49
+ })
50
+ // 建立SortedIndexMap
51
+ sortValueData.forEach(d => {
52
+ SortedIndexMap.set(String([d.rowIndex, d.columnIndex]), d.index)
53
+ })
54
+
55
+ return SortedIndexMap
56
+ }
57
+
58
+ export const computeSeriesData: ComputedDataFn<'series'> = (context) => {
59
+ const { data = [], dataFormatter, chartParams } = context
60
+ if (!data.length) {
61
+ return []
62
+ }
63
+
64
+ const computedDataSeries: ComputedDatumSeries[] = []
65
+
66
+ try {
67
+ // 取得排序後的索引
68
+ const getSortedIndex: GetSortedIndex = ((hasSort: boolean) => {
69
+ if (hasSort) {
70
+ // 資料索引對應排序後的索引 Map<[rowIndex, columnIndex], sortedIndex>
71
+ const SortedIndexMap: Map<string, number> = createSortedIndexMap(data, dataFormatter.sort)
72
+ return (computedDataSeries: ComputedDatumSeries[], rowIndex: number, columnIndex: number) => {
73
+ return SortedIndexMap.get(String([rowIndex, columnIndex]))
74
+ }
75
+ } else {
76
+ return (computedDataSeries: ComputedDatumSeries[], rowIndex: number, columnIndex: number) => {
77
+ return computedDataSeries.length
78
+ }
79
+ }
80
+ })(dataFormatter.sort != null)
81
+
82
+ // 資料索引對應排序後的索引 Map<[rowIndex, columnIndex], sortedIndex>
83
+ // let SortedIndexMap: Map<string, number> = new Map()
84
+ // if (dataFormatter.sort) {
85
+ // SortedIndexMap = createSortedIndexMap(data, dataFormatter.sort)
86
+ // }
87
+
88
+ const createComputedDatumSeries = (detailData: number | DataSeriesDatum, rowIndex: number, columnIndex: number, currentIndex: number, sortedIndex: number): ComputedDatumSeries => {
89
+ const defaultId = createDefaultDatumId(dataFormatter.type, rowIndex, columnIndex)
90
+ // const seriesLabel = dataFormatter.mapSeries(detailData, rowIndex, columnIndex, context)
91
+ const seriesLabel = dataFormatter.seriesLabels[rowIndex] || createDefaultSeriesLabel('series', rowIndex)
92
+ // const color = dataFormatter.colorsPredicate(detailData, rowIndex, columnIndex, context)
93
+ const color = seriesColorPredicate(rowIndex, chartParams)
94
+ const visible = dataFormatter.visibleFilter(detailData, rowIndex, columnIndex, context)
95
+ if (typeof detailData === 'number') {
96
+ return {
97
+ id: defaultId,
98
+ index: currentIndex,
99
+ sortedIndex,
100
+ label: defaultId,
101
+ description: '',
102
+ // tooltipContent: dataFormatter.tooltipContentFormat(detailData, rowIndex, columnIndex, context),
103
+ data: {},
104
+ value: detailData,
105
+ // valueLabel: formatValueToLabel(detailData, dataFormatter.valueFormat),
106
+ seriesIndex: rowIndex,
107
+ seriesLabel,
108
+ color,
109
+ visible
110
+ }
111
+ } else {
112
+ return {
113
+ id: detailData.id ? detailData.id : defaultId,
114
+ index: currentIndex,
115
+ sortedIndex,
116
+ label: detailData.label ? detailData.label : defaultId,
117
+ description: detailData.description,
118
+ // tooltipContent: detailData.tooltipContent ? detailData.tooltipContent : dataFormatter.tooltipContentFormat(detailData, rowIndex, columnIndex, context),
119
+ data: detailData.data ?? {},
120
+ value: detailData.value,
121
+ // valueLabel: formatValueToLabel(detailData.value, dataFormatter.valueFormat),
122
+ seriesIndex: rowIndex,
123
+ seriesLabel,
124
+ color,
125
+ visible
126
+ }
127
+ }
128
+ }
129
+
130
+ data.forEach((mainData, rowIndex) => {
131
+ if (Array.isArray(mainData)) {
132
+ mainData.forEach((detailData, columnIndex) => {
133
+ const sortedIndex = getSortedIndex(computedDataSeries, rowIndex, columnIndex)
134
+ const datum = createComputedDatumSeries(detailData, rowIndex, columnIndex, computedDataSeries.length, sortedIndex)
135
+ computedDataSeries.push(datum)
136
+ })
137
+ } else {
138
+ const sortedIndex = getSortedIndex(computedDataSeries, rowIndex, 0)
139
+ const datum = createComputedDatumSeries(mainData, rowIndex, 0, computedDataSeries.length, sortedIndex) // 只有一維陣列所以columnIndex為0
140
+ computedDataSeries.push(datum)
141
+ }
142
+ })
143
+
144
+ // if (dataFormatter.sort != null) {
145
+ // computedDataSeries.sort((a, b) => a.sortedIndex - b.sortedIndex)
146
+ // }
147
+ } catch (e) {
148
+ // console.error(e)
149
+ throw Error(e)
150
+ }
151
+
152
+ return computedDataSeries
153
+ }
@@ -1,33 +1,33 @@
1
- import { shareReplay } from 'rxjs'
2
- import type { ContextObserverFn } from '../types'
3
- import {
4
- seriesDataMapObservable,
5
- groupDataMapObservable } from '../utils/observables'
6
- import { highlightObservable } from '../utils/observables'
7
-
8
- export const createSeriesContextObserver: ContextObserverFn<'series'> = ({ subject, observer }) => {
9
-
10
- const seriesHighlight$ = highlightObservable({
11
- datumList$: observer.computedData$,
12
- fullChartParams$: observer.fullChartParams$,
13
- event$: subject.event$
14
- }).pipe(
15
- shareReplay(1)
16
- )
17
-
18
- const SeriesDataMap$ = seriesDataMapObservable({
19
- datumList$: observer.computedData$
20
- }).pipe(
21
- shareReplay(1)
22
- )
23
-
24
- return {
25
- fullParams$: observer.fullParams$,
26
- fullChartParams$: observer.fullChartParams$,
27
- fullDataFormatter$: observer.fullDataFormatter$,
28
- computedData$: observer.computedData$,
29
- layout$: observer.layout$,
30
- seriesHighlight$,
31
- SeriesDataMap$
32
- }
33
- }
1
+ import { shareReplay } from 'rxjs'
2
+ import type { ContextObserverFn } from '../types'
3
+ import {
4
+ seriesDataMapObservable,
5
+ groupDataMapObservable } from '../utils/observables'
6
+ import { highlightObservable } from '../utils/observables'
7
+
8
+ export const createSeriesContextObserver: ContextObserverFn<'series'> = ({ subject, observer }) => {
9
+
10
+ const seriesHighlight$ = highlightObservable({
11
+ datumList$: observer.computedData$,
12
+ fullChartParams$: observer.fullChartParams$,
13
+ event$: subject.event$
14
+ }).pipe(
15
+ shareReplay(1)
16
+ )
17
+
18
+ const SeriesDataMap$ = seriesDataMapObservable({
19
+ datumList$: observer.computedData$
20
+ }).pipe(
21
+ shareReplay(1)
22
+ )
23
+
24
+ return {
25
+ fullParams$: observer.fullParams$,
26
+ fullChartParams$: observer.fullChartParams$,
27
+ fullDataFormatter$: observer.fullDataFormatter$,
28
+ computedData$: observer.computedData$,
29
+ layout$: observer.layout$,
30
+ seriesHighlight$,
31
+ SeriesDataMap$
32
+ }
33
+ }
@@ -1,24 +1,24 @@
1
- import {
2
- combineLatest,
3
- distinctUntilChanged,
4
- filter,
5
- map,
6
- merge,
7
- takeUntil,
8
- shareReplay,
9
- switchMap,
10
- Subject,
11
- Observable } from 'rxjs'
12
- import type {
13
- ChartParams,
14
- ComputedDatumSeries,
15
- ComputedDataTypeMap } from '../types'
16
- import { highlightObservable } from '../utils/observables'
17
-
18
- // export const seriesHighlightObservable = ({ computedData$, fullChartParams$, event$ }: {
19
- // computedData$: Observable<ComputedDataTypeMap<'series'>>
20
- // fullChartParams$: Observable<ChartParams>
21
- // event$: Subject<any>
22
- // }): Observable<string[]> => {
23
- // return highlightObservable ({ datumList$: computedData$, fullChartParams$, event$ })
1
+ import {
2
+ combineLatest,
3
+ distinctUntilChanged,
4
+ filter,
5
+ map,
6
+ merge,
7
+ takeUntil,
8
+ shareReplay,
9
+ switchMap,
10
+ Subject,
11
+ Observable } from 'rxjs'
12
+ import type {
13
+ ChartParams,
14
+ ComputedDatumSeries,
15
+ ComputedDataTypeMap } from '../types'
16
+ import { highlightObservable } from '../utils/observables'
17
+
18
+ // export const seriesHighlightObservable = ({ computedData$, fullChartParams$, event$ }: {
19
+ // computedData$: Observable<ComputedDataTypeMap<'series'>>
20
+ // fullChartParams$: Observable<ChartParams>
21
+ // event$: Subject<any>
22
+ // }): Observable<string[]> => {
23
+ // return highlightObservable ({ datumList$: computedData$, fullChartParams$, event$ })
24
24
  // }