@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,183 +1,181 @@
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
- ChartType,
14
- ChartParams,
15
- ComputedDataTypeMap,
16
- ComputedDatumTypeMap,
17
- DataFormatterTypeMap,
18
- HighlightTarget,
19
- Layout,
20
- TransformData } from '../types'
21
-
22
- // interface DatumUnknown {
23
- // value: number | null
24
- // id: string
25
- // // label: string
26
- // seriesLabel?: string // 要符合每一種computedData所以不一定會有seriesLabel
27
- // groupLabel?: string // 要符合每一種computedData所以不一定會有groupLabel
28
- // }
29
-
30
- // 通用 highlight Observable
31
- export const highlightObservable = ({ datumList$, fullChartParams$, event$ }: {
32
- datumList$: Observable<ComputedDatumTypeMap<'series' | 'grid' | 'multiValue' | 'relationship' | 'tree'>[]>
33
- fullChartParams$: Observable<ChartParams>
34
- event$: Subject<any>
35
- }): Observable<string[]> => {
36
- const destroy$ = new Subject()
37
-
38
- // 預設的highlight
39
- const highlightDefault$ = fullChartParams$.pipe(
40
- takeUntil(destroy$),
41
- map(d => {
42
- return {
43
- id: null,
44
- seriesLabel: null,
45
- groupLabel: null,
46
- categoryLabel: null,
47
- highlightDefault: d.highlightDefault
48
- }
49
- }),
50
- distinctUntilChanged()
51
- )
52
-
53
- // 事件觸發的highlight
54
- const highlightMouseover$ = event$.pipe(
55
- takeUntil(destroy$),
56
- filter(d => d.eventName === 'mouseover' || d.eventName === 'mousemove'),
57
- // distinctUntilChanged((prev, current) => prev.eventName === current.eventName)
58
- map(d => {
59
- return d.datum
60
- ? {
61
- id: (d.datum as any).id,
62
- seriesLabel: (d.datum as any).seriesLabel,
63
- groupLabel: (d.datum as any).groupLabel,
64
- categoryLabel: (d.datum as any).categoryLabel,
65
- highlightDefault: null
66
- }
67
- : {
68
- id: null,
69
- seriesLabel: null,
70
- groupLabel: null,
71
- categoryLabel: null,
72
- highlightDefault: null
73
- }
74
- })
75
- )
76
- const highlightMouseout$ = event$.pipe(
77
- takeUntil(destroy$),
78
- filter(d => d.eventName === 'mouseout'),
79
- // distinctUntilChanged((prev, current) => prev.eventName === current.eventName)
80
- // map(d => {
81
- // return { id: '', label: '' }
82
- // })
83
- switchMap(d => highlightDefault$)
84
- )
85
-
86
- function getDatumIds (datumList: ComputedDatumTypeMap<'series' | 'grid' | 'multiValue' | 'relationship' | 'tree'>[], id: string | null) {
87
- return id == null
88
- ? []
89
- : datumList.find(d => d.id === id) ? [id] : []
90
- }
91
-
92
- function getSeriesIds (datumList: ComputedDatumTypeMap<'series' | 'grid'>[], seriesLabel: string | null) {
93
- return seriesLabel == null
94
- ? []
95
- : datumList.filter(d => d.seriesLabel === seriesLabel).map(d => d.id)
96
- }
97
-
98
- function getGroupIds (datumList: ComputedDatumTypeMap<'grid'>[], groupLabel: string | null) {
99
- return groupLabel == null
100
- ? []
101
- : datumList.filter(d => (d as ComputedDatumTypeMap<"grid">).groupLabel === groupLabel).map(d => d.id)
102
- }
103
-
104
- function getCategoryIds (datumList: ComputedDatumTypeMap<'multiValue' | 'relationship' | 'tree'>[], categoryLabel: string | null) {
105
- return categoryLabel == null
106
- ? []
107
- : datumList.filter(d => (d as ComputedDatumTypeMap<"multiValue" | "relationship" | "tree">).categoryLabel === categoryLabel).map(d => d.id)
108
- }
109
-
110
- return new Observable<string[]>(subscriber => {
111
- combineLatest({
112
- target: merge(highlightMouseover$, highlightMouseout$, highlightDefault$),
113
- datumList: datumList$,
114
- fullChartParams: fullChartParams$,
115
- }).pipe(
116
- takeUntil(destroy$),
117
- switchMap(async d => d)
118
- ).subscribe(data => {
119
- console.log('data.fullChartParams.highlightTarget', data.fullChartParams.highlightTarget)
120
- let ids: string[] = []
121
- if (data.fullChartParams.highlightTarget === 'datum') {
122
- ids = getDatumIds(data.datumList, data.target.id)
123
- } else if (data.fullChartParams.highlightTarget === 'series') {
124
- ids = getSeriesIds(data.datumList as ComputedDatumTypeMap<'series' | 'grid'>[], data.target.seriesLabel)
125
- } else if (data.fullChartParams.highlightTarget === 'group') {
126
- ids = getGroupIds(data.datumList as ComputedDatumTypeMap<'grid'>[], data.target.groupLabel)
127
- } else if (data.fullChartParams.highlightTarget === 'category') {
128
- ids = getCategoryIds(data.datumList as ComputedDatumTypeMap<'multiValue' | 'relationship' | 'tree'>[], data.target.categoryLabel)
129
- }
130
- console.log('ids', ids)
131
- subscriber.next(ids)
132
- })
133
-
134
- return function unsubscribe () {
135
- destroy$.next(undefined)
136
- }
137
- })
138
- }
139
-
140
- export const seriesDataMapObservable = <DatumType extends ComputedDatumTypeMap<'series' | 'grid'>>({ datumList$ }: { datumList$: Observable<DatumType[]> }) => {
141
- return datumList$.pipe(
142
- map(data => {
143
- const SeriesDataMap: Map<string, DatumType[]> = new Map()
144
- data.forEach(d => {
145
- const seriesData = SeriesDataMap.get(d.seriesLabel) ?? []
146
- seriesData.push(d)
147
- SeriesDataMap.set(d.seriesLabel, seriesData)
148
- })
149
- return SeriesDataMap
150
- })
151
- )
152
- }
153
-
154
- export const groupDataMapObservable = <DatumType extends ComputedDatumTypeMap<'grid'>> ({ datumList$ }: { datumList$: Observable<DatumType[]> }) => {
155
- return datumList$.pipe(
156
- map(data => {
157
- const GroupDataMap: Map<string, DatumType[]> = new Map()
158
- data.forEach(d => {
159
- const groupData = GroupDataMap.get(d.groupLabel) ?? []
160
- groupData.push(d)
161
- GroupDataMap.set(d.groupLabel, groupData)
162
- })
163
- return GroupDataMap
164
- })
165
- )
166
- }
167
-
168
- export const categoryDataMapObservable = <DatumType extends ComputedDatumTypeMap<'multiValue' | 'relationship' | 'tree'>> ({ datumList$ }: { datumList$: Observable<DatumType[]> }) => {
169
- return datumList$.pipe(
170
- map(data => {
171
- const GroupDataMap: Map<string, DatumType[]> = new Map()
172
- data
173
- .filter(d => d.categoryLabel != null)
174
- .forEach(d => {
175
- const groupData = GroupDataMap.get(d.categoryLabel) ?? []
176
- groupData.push(d)
177
- GroupDataMap.set(d.categoryLabel, groupData)
178
- })
179
- return GroupDataMap
180
- })
181
- )
182
- }
183
-
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
+ ChartType,
14
+ ChartParams,
15
+ ComputedDataTypeMap,
16
+ ComputedDatumTypeMap,
17
+ DataFormatterTypeMap,
18
+ EventTypeMap,
19
+ HighlightTarget,
20
+ Layout,
21
+ TransformData } from '../types'
22
+
23
+ // interface DatumUnknown {
24
+ // value: number | null
25
+ // id: string
26
+ // // label: string
27
+ // seriesLabel?: string // 要符合每一種computedData所以不一定會有seriesLabel
28
+ // groupLabel?: string // 要符合每一種computedData所以不一定會有groupLabel
29
+ // }
30
+
31
+ // 通用 highlight Observable
32
+ export const highlightObservable = <T extends ChartType, D>({ datumList$, fullChartParams$, event$ }: {
33
+ datumList$: Observable<D[]>
34
+ fullChartParams$: Observable<ChartParams>
35
+ event$: Subject<EventTypeMap<T>>
36
+ }): Observable<D[]> => {
37
+ const destroy$ = new Subject()
38
+
39
+ // 預設的highlight
40
+ const highlightDefault$ = fullChartParams$.pipe(
41
+ takeUntil(destroy$),
42
+ map(d => {
43
+ return {
44
+ id: null,
45
+ seriesLabel: null,
46
+ groupLabel: null,
47
+ categoryLabel: null,
48
+ highlightDefault: d.highlightDefault
49
+ }
50
+ }),
51
+ distinctUntilChanged()
52
+ )
53
+
54
+ // 事件觸發的highlight
55
+ const highlightMouseover$ = event$.pipe(
56
+ takeUntil(destroy$),
57
+ filter(d => d.eventName === 'mouseover' || d.eventName === 'mousemove'),
58
+ // distinctUntilChanged((prev, current) => prev.eventName === current.eventName)
59
+ map(d => {
60
+ return d.datum
61
+ ? {
62
+ id: (d.datum as any).id,
63
+ seriesLabel: (d.datum as any).seriesLabel,
64
+ groupLabel: (d.datum as any).groupLabel,
65
+ categoryLabel: (d.datum as any).categoryLabel,
66
+ highlightDefault: null
67
+ }
68
+ : {
69
+ id: null,
70
+ seriesLabel: null,
71
+ groupLabel: null,
72
+ categoryLabel: null,
73
+ highlightDefault: null
74
+ }
75
+ })
76
+ )
77
+ const highlightMouseout$ = event$.pipe(
78
+ takeUntil(destroy$),
79
+ filter(d => d.eventName === 'mouseout'),
80
+ // distinctUntilChanged((prev, current) => prev.eventName === current.eventName)
81
+ // map(d => {
82
+ // return { id: '', label: '' }
83
+ // })
84
+ switchMap(d => highlightDefault$)
85
+ )
86
+
87
+ function getDatumIds (datumList: ComputedDatumTypeMap<T>[], id: string | null) {
88
+ const datum = datumList.find(d => d.id === id)
89
+ return datum ? [datum] : []
90
+ }
91
+
92
+ function getSeriesIds (datumList: ComputedDatumTypeMap<T>[], seriesLabel: string | null) {
93
+ return seriesLabel == null
94
+ ? []
95
+ : datumList.filter(d => (d as ComputedDatumTypeMap<"series">).seriesLabel === seriesLabel)
96
+ }
97
+
98
+ function getGroupIds (datumList: ComputedDatumTypeMap<T>[], groupLabel: string | null) {
99
+ return groupLabel == null
100
+ ? []
101
+ : datumList.filter(d => (d as ComputedDatumTypeMap<"grid">).groupLabel === groupLabel)
102
+ }
103
+
104
+ function getCategoryIds (datumList: ComputedDatumTypeMap<T>[], categoryLabel: string | null) {
105
+ return categoryLabel == null
106
+ ? []
107
+ : datumList.filter(d => (d as ComputedDatumTypeMap<"multiValue" | "relationship" | "tree">).categoryLabel === categoryLabel)
108
+ }
109
+
110
+ return new Observable<D[]>(subscriber => {
111
+ combineLatest({
112
+ target: merge(highlightMouseover$, highlightMouseout$, highlightDefault$),
113
+ datumList: datumList$,
114
+ fullChartParams: fullChartParams$,
115
+ }).pipe(
116
+ takeUntil(destroy$),
117
+ switchMap(async d => d)
118
+ ).subscribe(data => {
119
+ let datumList: ComputedDatumTypeMap<T>[] = []
120
+ if (data.fullChartParams.highlightTarget === 'datum') {
121
+ datumList = getDatumIds(data.datumList as ComputedDatumTypeMap<T>[], data.target.id)
122
+ } else if (data.fullChartParams.highlightTarget === 'series') {
123
+ datumList = getSeriesIds(data.datumList as ComputedDatumTypeMap<T>[], data.target.seriesLabel)
124
+ } else if (data.fullChartParams.highlightTarget === 'group') {
125
+ datumList = getGroupIds(data.datumList as ComputedDatumTypeMap<T>[], data.target.groupLabel)
126
+ } else if (data.fullChartParams.highlightTarget === 'category') {
127
+ datumList = getCategoryIds(data.datumList as ComputedDatumTypeMap<T>[], data.target.categoryLabel)
128
+ }
129
+ subscriber.next(datumList as D[])
130
+ })
131
+
132
+ return function unsubscribe () {
133
+ destroy$.next(undefined)
134
+ }
135
+ })
136
+ }
137
+
138
+ export const seriesDataMapObservable = <DatumType extends ComputedDatumTypeMap<'series' | 'grid'>>({ datumList$ }: { datumList$: Observable<DatumType[]> }) => {
139
+ return datumList$.pipe(
140
+ map(data => {
141
+ const SeriesDataMap: Map<string, DatumType[]> = new Map()
142
+ data.forEach(d => {
143
+ const seriesData = SeriesDataMap.get(d.seriesLabel) ?? []
144
+ seriesData.push(d)
145
+ SeriesDataMap.set(d.seriesLabel, seriesData)
146
+ })
147
+ return SeriesDataMap
148
+ })
149
+ )
150
+ }
151
+
152
+ export const groupDataMapObservable = <DatumType extends ComputedDatumTypeMap<'grid'>> ({ datumList$ }: { datumList$: Observable<DatumType[]> }) => {
153
+ return datumList$.pipe(
154
+ map(data => {
155
+ const GroupDataMap: Map<string, DatumType[]> = new Map()
156
+ data.forEach(d => {
157
+ const groupData = GroupDataMap.get(d.groupLabel) ?? []
158
+ groupData.push(d)
159
+ GroupDataMap.set(d.groupLabel, groupData)
160
+ })
161
+ return GroupDataMap
162
+ })
163
+ )
164
+ }
165
+
166
+ export const categoryDataMapObservable = <DatumType extends ComputedDatumTypeMap<'multiValue' | 'relationship' | 'tree'>> ({ datumList$ }: { datumList$: Observable<DatumType[]> }) => {
167
+ return datumList$.pipe(
168
+ map(data => {
169
+ const GroupDataMap: Map<string, DatumType[]> = new Map()
170
+ data
171
+ .filter(d => d.categoryLabel != null)
172
+ .forEach(d => {
173
+ const groupData = GroupDataMap.get(d.categoryLabel) ?? []
174
+ groupData.push(d)
175
+ GroupDataMap.set(d.categoryLabel, groupData)
176
+ })
177
+ return GroupDataMap
178
+ })
179
+ )
180
+ }
181
+