@orbcharts/core 3.0.0-alpha.36 → 3.0.0-alpha.38

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 (53) hide show
  1. package/dist/orbcharts-core.es.js +1753 -1664
  2. package/dist/orbcharts-core.umd.js +2 -2
  3. package/dist/src/grid/gridObservables.d.ts +1 -1
  4. package/dist/src/series/seriesObservables.d.ts +1 -8
  5. package/dist/src/tree/treeObservables.d.ts +13 -0
  6. package/dist/src/types/ChartParams.d.ts +1 -1
  7. package/dist/src/types/ComputedData.d.ts +13 -0
  8. package/dist/src/types/ComputedDataGrid.d.ts +2 -5
  9. package/dist/src/types/ComputedDataMultiValue.d.ts +2 -2
  10. package/dist/src/types/ComputedDataRelationship.d.ts +2 -2
  11. package/dist/src/types/ComputedDataTree.d.ts +2 -2
  12. package/dist/src/types/ContextObserverGrid.d.ts +1 -1
  13. package/dist/src/types/ContextObserverTree.d.ts +6 -0
  14. package/dist/src/types/DataFormatterMultiGrid.d.ts +1 -3
  15. package/dist/src/types/DataFormatterMultiValue.d.ts +0 -1
  16. package/dist/src/types/DataFormatterSeries.d.ts +0 -2
  17. package/dist/src/types/DataFormatterTree.d.ts +1 -0
  18. package/dist/src/types/DataMultiValue.d.ts +1 -0
  19. package/dist/src/types/DataRelationship.d.ts +1 -0
  20. package/dist/src/types/DataTree.d.ts +2 -0
  21. package/dist/src/types/Event.d.ts +30 -38
  22. package/dist/src/utils/observables.d.ts +7 -4
  23. package/package.json +1 -1
  24. package/src/defaults.ts +5 -3
  25. package/src/grid/createGridContextObserver.ts +3 -3
  26. package/src/grid/gridObservables.ts +1 -1
  27. package/src/multiGrid/multiGridObservables.ts +3 -3
  28. package/src/multiValue/computeMultiValueData.ts +7 -2
  29. package/src/relationship/computeRelationshipData.ts +3 -0
  30. package/src/series/createSeriesContextObserver.ts +1 -1
  31. package/src/series/seriesObservables.ts +8 -7
  32. package/src/tree/computeTreeData.ts +31 -9
  33. package/src/tree/createTreeContextObserver.ts +44 -0
  34. package/src/tree/treeObservables.ts +95 -0
  35. package/src/types/ChartParams.ts +1 -1
  36. package/src/types/ComputedData.ts +18 -1
  37. package/src/types/ComputedDataGrid.ts +5 -5
  38. package/src/types/ComputedDataMultiValue.ts +2 -3
  39. package/src/types/ComputedDataRelationship.ts +2 -2
  40. package/src/types/ComputedDataTree.ts +2 -2
  41. package/src/types/ContextObserverGrid.ts +1 -1
  42. package/src/types/ContextObserverMultiGrid.ts +1 -1
  43. package/src/types/ContextObserverTree.ts +6 -1
  44. package/src/types/DataFormatterMultiGrid.ts +2 -2
  45. package/src/types/DataFormatterMultiValue.ts +1 -1
  46. package/src/types/DataFormatterSeries.ts +2 -2
  47. package/src/types/DataFormatterTree.ts +1 -0
  48. package/src/types/DataMultiValue.ts +1 -0
  49. package/src/types/DataRelationship.ts +1 -0
  50. package/src/types/DataTree.ts +2 -0
  51. package/src/types/Event.ts +85 -46
  52. package/src/utils/d3Utils.ts +0 -1
  53. package/src/utils/observables.ts +60 -77
@@ -27,8 +27,9 @@ import type {
27
27
  // groupLabel?: string // 要符合每一種computedData所以不一定會有groupLabel
28
28
  // }
29
29
 
30
+ // 通用 highlight Observable
30
31
  export const highlightObservable = ({ datumList$, fullChartParams$, event$ }: {
31
- datumList$: Observable<ComputedDatumTypeMap<'series' | 'grid'>[]>
32
+ datumList$: Observable<ComputedDatumTypeMap<'series' | 'grid' | 'multiValue' | 'relationship' | 'tree'>[]>
32
33
  fullChartParams$: Observable<ChartParams>
33
34
  event$: Subject<any>
34
35
  }): Observable<string[]> => {
@@ -42,6 +43,7 @@ export const highlightObservable = ({ datumList$, fullChartParams$, event$ }: {
42
43
  id: null,
43
44
  seriesLabel: null,
44
45
  groupLabel: null,
46
+ categoryLabel: null,
45
47
  highlightDefault: d.highlightDefault
46
48
  }
47
49
  }),
@@ -59,12 +61,14 @@ export const highlightObservable = ({ datumList$, fullChartParams$, event$ }: {
59
61
  id: (d.datum as any).id,
60
62
  seriesLabel: (d.datum as any).seriesLabel,
61
63
  groupLabel: (d.datum as any).groupLabel,
64
+ categoryLabel: (d.datum as any).categoryLabel,
62
65
  highlightDefault: null
63
66
  }
64
67
  : {
65
68
  id: null,
66
69
  seriesLabel: null,
67
70
  groupLabel: null,
71
+ categoryLabel: null,
68
72
  highlightDefault: null
69
73
  }
70
74
  })
@@ -79,68 +83,28 @@ export const highlightObservable = ({ datumList$, fullChartParams$, event$ }: {
79
83
  switchMap(d => highlightDefault$)
80
84
  )
81
85
 
82
- const getHighlightIds = ({ data, id, seriesLabel, groupLabel, highlightDefault, target }: {
83
- data: ComputedDatumTypeMap<'series' | 'grid'>[]
84
- id: string | null
85
- seriesLabel: string | null
86
- groupLabel: string | null
87
- highlightDefault: string | null
88
- target: HighlightTarget
89
- }) => {
90
- let ids: string[] = []
91
- // if (id) {
92
- // ids.push(id)
93
- // }
94
- // if (label) {
95
- // if (target === 'group') {
96
- // const _ids = data.flat()
97
- // .filter(d => {
98
- // return d.groupLabel === label
99
- // || d.label === label
100
- // })
101
- // .map(d => d.id)
102
- // ids = ids.concat(_ids)
103
- // } else if (target === 'series') {
104
- // const _ids = data.flat()
105
- // .filter(d => {
106
- // return d.seriesLabel === label
107
- // || d.label === label
108
- // })
109
- // .map(d => d.id)
110
- // ids = ids.concat(_ids)
111
- // }
112
- // }
113
- // 依highlightDefault找到id/seriesLabel/groupLabel
114
- if (highlightDefault != null && highlightDefault != '') {
115
- if (target === 'datum') {
116
- id = highlightDefault
117
- } else if (target === 'series') {
118
- const datum = data.flat().find(d => d.id === highlightDefault || d.seriesLabel === highlightDefault)
119
- seriesLabel = (datum && datum.seriesLabel) ? datum.seriesLabel : null
120
- } else if (target === 'group') {
121
- const datum = data.flat().find(d => d.id === highlightDefault || (d as ComputedDatumTypeMap<"grid">).groupLabel === highlightDefault)
122
- groupLabel = (datum && (datum as ComputedDatumTypeMap<"grid">).groupLabel) ? (datum as ComputedDatumTypeMap<"grid">).groupLabel : null
123
- }
124
- }
125
- if (target === 'datum' && id != null && id != '') {
126
- ids.push(id)
127
- } else if (target === 'series' && seriesLabel != null && seriesLabel != '') {
128
- const _ids = data.flat()
129
- .filter(d => {
130
- return d.seriesLabel === seriesLabel
131
- })
132
- .map(d => d.id)
133
- ids = ids.concat(_ids)
134
- } else if (target === 'group' && groupLabel != null && groupLabel != '') {
135
- const _ids = data.flat()
136
- .filter(d => {
137
- return (d as ComputedDatumTypeMap<"grid">).groupLabel === groupLabel
138
- })
139
- .map(d => d.id)
140
- ids = ids.concat(_ids)
141
- }
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
+ }
142
91
 
143
- return ids
92
+ function getSeriesIds (datumList: ComputedDatumTypeMap<'series' | 'grid'>[], seriesLabel: string | null) {
93
+ return seriesLabel == null
94
+ ? datumList.filter(d => d.seriesLabel === seriesLabel).map(d => d.id)
95
+ : []
96
+ }
97
+
98
+ function getGroupIds (datumList: ComputedDatumTypeMap<'grid'>[], groupLabel: string | null) {
99
+ return groupLabel == null
100
+ ? datumList.filter(d => (d as ComputedDatumTypeMap<"grid">).groupLabel === groupLabel).map(d => d.id)
101
+ : []
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)
144
108
  }
145
109
 
146
110
  return new Observable<string[]>(subscriber => {
@@ -149,16 +113,19 @@ export const highlightObservable = ({ datumList$, fullChartParams$, event$ }: {
149
113
  datumList: datumList$,
150
114
  fullChartParams: fullChartParams$,
151
115
  }).pipe(
152
- takeUntil(destroy$)
116
+ takeUntil(destroy$),
117
+ switchMap(async d => d)
153
118
  ).subscribe(data => {
154
- const ids = getHighlightIds({
155
- data: data.datumList,
156
- id: data.target.id,
157
- seriesLabel: data.target.seriesLabel,
158
- groupLabel: data.target.groupLabel,
159
- highlightDefault: data.target.highlightDefault,
160
- target: data.fullChartParams.highlightTarget,
161
- })
119
+ let ids: string[] = []
120
+ if (data.fullChartParams.highlightTarget === 'datum') {
121
+ ids = getDatumIds(data.datumList, data.target.id)
122
+ } else if (data.fullChartParams.highlightTarget === 'series') {
123
+ ids = getSeriesIds(data.datumList as ComputedDatumTypeMap<'series' | 'grid'>[], data.target.seriesLabel)
124
+ } else if (data.fullChartParams.highlightTarget === 'group') {
125
+ ids = getGroupIds(data.datumList as ComputedDatumTypeMap<'grid'>[], data.target.groupLabel)
126
+ } else if (data.fullChartParams.highlightTarget === 'category') {
127
+ ids = getCategoryIds(data.datumList as ComputedDatumTypeMap<'multiValue' | 'relationship' | 'tree'>[], data.target.categoryLabel)
128
+ }
162
129
  subscriber.next(ids)
163
130
  })
164
131
 
@@ -168,31 +135,47 @@ export const highlightObservable = ({ datumList$, fullChartParams$, event$ }: {
168
135
  })
169
136
  }
170
137
 
171
- export const seriesDataMapObservable = <DatumType extends ComputedDatumTypeMap<ChartType>>({ datumList$ }: { datumList$: Observable<DatumType[]> }) => {
138
+ export const seriesDataMapObservable = <DatumType extends ComputedDatumTypeMap<'series' | 'grid'>>({ datumList$ }: { datumList$: Observable<DatumType[]> }) => {
172
139
  return datumList$.pipe(
173
140
  map(data => {
174
141
  const SeriesDataMap: Map<string, DatumType[]> = new Map()
175
142
  data.forEach(d => {
176
- const seriesData = SeriesDataMap.get((d as ComputedDatumTypeMap<'series' | 'grid'>).seriesLabel) ?? []
143
+ const seriesData = SeriesDataMap.get(d.seriesLabel) ?? []
177
144
  seriesData.push(d)
178
- SeriesDataMap.set((d as ComputedDatumTypeMap<'series' | 'grid'>).seriesLabel, seriesData)
145
+ SeriesDataMap.set(d.seriesLabel, seriesData)
179
146
  })
180
147
  return SeriesDataMap
181
148
  })
182
149
  )
183
150
  }
184
151
 
185
- export const groupDataMapObservable = <DatumType extends ComputedDatumTypeMap<ChartType>> ({ datumList$ }: { datumList$: Observable<DatumType[]> }) => {
152
+ export const groupDataMapObservable = <DatumType extends ComputedDatumTypeMap<'grid'>> ({ datumList$ }: { datumList$: Observable<DatumType[]> }) => {
186
153
  return datumList$.pipe(
187
154
  map(data => {
188
155
  const GroupDataMap: Map<string, DatumType[]> = new Map()
189
156
  data.forEach(d => {
190
- const groupData = GroupDataMap.get((d as ComputedDatumTypeMap<'grid'>).groupLabel) ?? []
157
+ const groupData = GroupDataMap.get(d.groupLabel) ?? []
191
158
  groupData.push(d)
192
- GroupDataMap.set((d as ComputedDatumTypeMap<'grid'>).groupLabel, groupData)
159
+ GroupDataMap.set(d.groupLabel, groupData)
193
160
  })
194
161
  return GroupDataMap
195
162
  })
196
163
  )
197
164
  }
198
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
+