@orbcharts/plugins-basic 3.0.0-alpha.43 → 3.0.0-alpha.44

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-plugins-basic.es.js +5611 -5571
  3. package/dist/orbcharts-plugins-basic.umd.js +7 -7
  4. package/dist/src/base/BaseLegend.d.ts +1 -0
  5. package/package.json +42 -42
  6. package/src/base/BaseBarStack.ts +881 -881
  7. package/src/base/BaseBars.ts +750 -750
  8. package/src/base/BaseBarsTriangle.ts +659 -659
  9. package/src/base/BaseDots.ts +639 -639
  10. package/src/base/BaseGroupAxis.ts +496 -496
  11. package/src/base/BaseLegend.ts +641 -636
  12. package/src/base/BaseLineAreas.ts +621 -621
  13. package/src/base/BaseLines.ts +692 -692
  14. package/src/base/BaseValueAxis.ts +479 -479
  15. package/src/base/types.ts +2 -2
  16. package/src/grid/defaults.ts +121 -121
  17. package/src/grid/gridObservables.ts +263 -263
  18. package/src/grid/index.ts +15 -15
  19. package/src/grid/plugins/BarStack.ts +37 -37
  20. package/src/grid/plugins/Bars.ts +37 -37
  21. package/src/grid/plugins/BarsDiverging.ts +39 -39
  22. package/src/grid/plugins/BarsTriangle.ts +34 -34
  23. package/src/grid/plugins/Dots.ts +35 -35
  24. package/src/grid/plugins/GridLegend.ts +59 -58
  25. package/src/grid/plugins/GroupAux.ts +646 -643
  26. package/src/grid/plugins/GroupAxis.ts +30 -30
  27. package/src/grid/plugins/LineAreas.ts +36 -36
  28. package/src/grid/plugins/Lines.ts +35 -35
  29. package/src/grid/plugins/ScalingArea.ts +174 -174
  30. package/src/grid/plugins/ValueAxis.ts +31 -31
  31. package/src/grid/plugins/ValueStackAxis.ts +70 -70
  32. package/src/grid/types.ts +120 -120
  33. package/src/index.ts +9 -9
  34. package/src/multiGrid/defaults.ts +147 -147
  35. package/src/multiGrid/index.ts +11 -11
  36. package/src/multiGrid/multiGridObservables.ts +289 -289
  37. package/src/multiGrid/plugins/MultiBarStack.ts +60 -60
  38. package/src/multiGrid/plugins/MultiBars.ts +59 -59
  39. package/src/multiGrid/plugins/MultiBarsTriangle.ts +58 -58
  40. package/src/multiGrid/plugins/MultiDots.ts +58 -58
  41. package/src/multiGrid/plugins/MultiGridLegend.ts +89 -88
  42. package/src/multiGrid/plugins/MultiGroupAxis.ts +53 -53
  43. package/src/multiGrid/plugins/MultiLineAreas.ts +59 -59
  44. package/src/multiGrid/plugins/MultiLines.ts +58 -58
  45. package/src/multiGrid/plugins/MultiValueAxis.ts +53 -53
  46. package/src/multiGrid/plugins/OverlappingValueAxes.ts +164 -164
  47. package/src/multiGrid/types.ts +67 -67
  48. package/src/noneData/defaults.ts +61 -61
  49. package/src/noneData/index.ts +3 -3
  50. package/src/noneData/plugins/Container.ts +10 -10
  51. package/src/noneData/plugins/Tooltip.ts +310 -304
  52. package/src/noneData/types.ts +26 -26
  53. package/src/series/defaults.ts +99 -99
  54. package/src/series/index.ts +6 -6
  55. package/src/series/plugins/Bubbles.ts +551 -551
  56. package/src/series/plugins/Pie.ts +600 -600
  57. package/src/series/plugins/PieEventTexts.ts +194 -194
  58. package/src/series/plugins/PieLabels.ts +288 -288
  59. package/src/series/plugins/SeriesLegend.ts +59 -58
  60. package/src/series/seriesUtils.ts +50 -50
  61. package/src/series/types.ts +67 -67
  62. package/src/tree/defaults.ts +22 -22
  63. package/src/tree/index.ts +3 -3
  64. package/src/tree/plugins/TreeLegend.ts +59 -58
  65. package/src/tree/plugins/TreeMap.ts +305 -302
  66. package/src/tree/types.ts +23 -23
  67. package/src/utils/commonUtils.ts +21 -21
  68. package/src/utils/d3Graphics.ts +124 -124
  69. package/src/utils/d3Utils.ts +73 -73
  70. package/src/utils/observables.ts +14 -14
  71. package/src/utils/orbchartsUtils.ts +100 -100
  72. package/tsconfig.dev.json +16 -16
  73. package/tsconfig.json +13 -13
  74. package/tsconfig.prod.json +13 -13
  75. package/vite.config.js +49 -49
@@ -1,288 +1,288 @@
1
- import * as d3 from 'd3'
2
- import {
3
- combineLatest,
4
- switchMap,
5
- first,
6
- map,
7
- takeUntil,
8
- Subject,
9
- BehaviorSubject } from 'rxjs'
10
- import {
11
- defineSeriesPlugin } from '@orbcharts/core'
12
- import type {
13
- ChartParams } from '@orbcharts/core'
14
- import type { PieLabelsParams } from '../types'
15
- import type { PieDatum } from '../seriesUtils'
16
- import { DEFAULT_PIE_LABELS_PARAMS } from '../defaults'
17
- import { makePieData } from '../seriesUtils'
18
- import { makeD3Arc } from '../../utils/d3Utils'
19
- import { getDatumColor, getClassName } from '../../utils/orbchartsUtils'
20
-
21
- interface RenderDatum {
22
- pieDatum: PieDatum
23
- arcIndex: number
24
- arcLabel: string
25
- x: number
26
- y: number
27
- mouseoverX: number
28
- mouseoverY: number
29
- }
30
-
31
- const pluginName = 'PieLabels'
32
- const textClassName = getClassName(pluginName, 'text')
33
-
34
- function makeRenderData (pieData: PieDatum[], arc: d3.Arc<any, d3.DefaultArcObject>, mouseoverArc: d3.Arc<any, d3.DefaultArcObject>, centroid: number): RenderDatum[] {
35
- return pieData
36
- .map((d, i) => {
37
- const [_x, _y] = arc!.centroid(d as any)
38
- const [_mouseoverX, _mouseoverY] = mouseoverArc!.centroid(d as any)
39
- return {
40
- pieDatum: d,
41
- arcIndex: i,
42
- arcLabel: d.data.label,
43
- x: _x * centroid!,
44
- y: _y * centroid!,
45
- mouseoverX: _mouseoverX * centroid!,
46
- mouseoverY: _mouseoverY * centroid!
47
- }
48
- })
49
- .filter(d => d.pieDatum.data.visible)
50
- }
51
-
52
- // 繪製圓餅圖
53
- function renderLabel (selection: d3.Selection<SVGGElement, undefined, any, any>, data: RenderDatum[], pluginParams: PieLabelsParams, fullChartParams: ChartParams) {
54
- // console.log(data)
55
- // let update = this.gSelection.selectAll('g').data(pieData)
56
- let update: d3.Selection<SVGPathElement, RenderDatum, any, any> = selection
57
- .selectAll<SVGPathElement, RenderDatum>('text')
58
- .data(data, d => d.pieDatum.id)
59
- let enter = update.enter()
60
- .append<SVGPathElement>('text')
61
- .classed(textClassName, true)
62
- let exit = update.exit()
63
-
64
- enter
65
- .append('text')
66
-
67
- const labelSelection = update.merge(enter)
68
- labelSelection
69
- .attr('font-weight', 'bold')
70
- .attr('text-anchor', 'middle')
71
- .style('dominant-baseline', 'middle')
72
- // .style('pointer-events', 'none')
73
- .style('cursor', d => fullChartParams.highlightTarget && fullChartParams.highlightTarget != 'none'
74
- ? 'pointer'
75
- : 'none')
76
- // .text((d, i) => d.arcLabel)
77
- .text(d => pluginParams.labelFn(d.pieDatum.data))
78
- .attr('font-size', fullChartParams.styles.textSize)
79
- .attr('fill', (d, i) => getDatumColor({ datum: d.pieDatum.data, colorType: pluginParams.labelColorType, fullChartParams }))
80
- .transition()
81
- .attr('transform', (d) => {
82
- // console.log('transform', d)
83
- return 'translate(' + d.x + ',' + d.y + ')'
84
- })
85
- // .on('end', () => initHighlight({ labelSelection, data, fullChartParams }))
86
- exit.remove()
87
-
88
- // 如無新增資料則不用等動畫
89
- // if (enter.size() == 0) {
90
- // this.initHighlight()
91
- // }
92
-
93
- return labelSelection
94
- }
95
-
96
- // function initHighlight ({ labelSelection, data, fullChartParams }: {
97
- // labelSelection: (d3.Selection<SVGPathElement, RenderDatum, any, any>)
98
- // data: RenderDatum[]
99
- // fullChartParams: ChartParams
100
- // }) {
101
- // removeHighlight({ labelSelection })
102
- // // if (fullParams.highlightSeriesId || fullParams.highlightDatumId) {
103
- // highlight({
104
- // labelSelection,
105
- // data,
106
- // id: fullChartParams.highlightDefault,
107
- // label: fullChartParams.highlightDefault,
108
- // fullChartParams
109
- // })
110
- // // }
111
- // }
112
-
113
- function highlight ({ labelSelection, ids, fullChartParams }: {
114
- labelSelection: (d3.Selection<SVGPathElement, RenderDatum, any, any>)
115
- ids: string[]
116
- fullChartParams: ChartParams
117
- }) {
118
- labelSelection.interrupt('highlight')
119
-
120
- if (!ids.length) {
121
- labelSelection
122
- .transition()
123
- .duration(200)
124
- .attr('transform', (d) => {
125
- return 'translate(' + d.x + ',' + d.y + ')'
126
- })
127
- .style('opacity', 1)
128
- return
129
- }
130
-
131
- labelSelection.each((d, i, n) => {
132
- const segment = d3.select<SVGPathElement, RenderDatum>(n[i])
133
-
134
- if (ids.includes(d.pieDatum.id)) {
135
- segment
136
- .style('opacity', 1)
137
- .transition()
138
- .duration(200)
139
- .attr('transform', (d) => {
140
- return 'translate(' + d.mouseoverX + ',' + d.mouseoverY + ')'
141
- })
142
- } else {
143
- segment
144
- .style('opacity', fullChartParams.styles.unhighlightedOpacity)
145
- .transition()
146
- .duration(200)
147
- .attr('transform', (d) => {
148
- return 'translate(' + d.x + ',' + d.y + ')'
149
- })
150
- }
151
- })
152
- }
153
-
154
-
155
- // function removeHighlight ({ labelSelection }: {
156
- // labelSelection: (d3.Selection<SVGPathElement, RenderDatum, any, any> | undefined)
157
- // }) {
158
- // if (!labelSelection) {
159
- // return
160
- // }
161
-
162
- // // 取消放大
163
- // labelSelection
164
- // .transition()
165
- // .duration(200)
166
- // .attr('transform', (d) => {
167
- // return 'translate(' + d.x + ',' + d.y + ')'
168
- // })
169
- // .style('opacity', 1)
170
-
171
- // }
172
-
173
-
174
- export const PieLabels = defineSeriesPlugin(pluginName, DEFAULT_PIE_LABELS_PARAMS)(({ selection, observer, subject }) => {
175
-
176
- const destroy$ = new Subject()
177
-
178
- const graphicSelection: d3.Selection<SVGGElement, any, any, any> = selection.append('g')
179
- let labelSelection$: Subject<d3.Selection<SVGPathElement, RenderDatum, any, any>> = new Subject()
180
- let renderData: RenderDatum[] = []
181
- // let highlightTarget: HighlightTarget | undefined
182
- // let fullChartParams: ChartParams | undefined
183
-
184
- observer.layout$
185
- .pipe(
186
- first()
187
- )
188
- .subscribe(size => {
189
- selection
190
- .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
191
- observer.layout$
192
- .pipe(
193
- takeUntil(destroy$)
194
- )
195
- .subscribe(size => {
196
- selection
197
- .transition()
198
- .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
199
- })
200
- })
201
-
202
-
203
-
204
- // combineLatest({
205
- // event: store.event$,
206
- // fullChartParams: fullChartParams$
207
- // }).pipe(
208
- // // 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
209
- // switchMap(async (d) => d),
210
- // ).subscribe(d => {
211
- // if (d.event.eventName === 'mouseover' && d.event.datum) {
212
- // highlight({
213
- // labelSelection,
214
- // data: renderData,
215
- // id: d.fullChartParams.highlightTarget === 'datum' ? d.event.datum!.id : undefined,
216
- // label: d.fullChartParams.highlightTarget === 'series' ? d.event.datum!.label : undefined,
217
- // fullChartParams: d.fullChartParams
218
- // })
219
- // } else if (d.event.eventName === 'mouseout') {
220
- // removeHighlight({ labelSelection })
221
- // }
222
- // })
223
-
224
- combineLatest({
225
- layout: observer.layout$,
226
- computedData: observer.computedData$,
227
- fullParams: observer.fullParams$,
228
- fullChartParams: observer.fullChartParams$
229
- }).pipe(
230
- takeUntil(destroy$),
231
- // 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
232
- switchMap(async (d) => d),
233
- ).subscribe(data => {
234
-
235
- const shorterSideWith = data.layout.width < data.layout.height ? data.layout.width : data.layout.height
236
-
237
- // 弧產生器 (d3.arc())
238
- const arc = makeD3Arc({
239
- axisWidth: shorterSideWith,
240
- innerRadius: 0,
241
- outerRadius: data.fullParams.outerRadius,
242
- padAngle: 0,
243
- cornerRadius: 0
244
- })
245
-
246
- const arcMouseover = makeD3Arc({
247
- axisWidth: shorterSideWith,
248
- innerRadius: 0,
249
- outerRadius: data.fullParams.outerMouseoverRadius, // 外半徑變化
250
- padAngle: 0,
251
- cornerRadius: 0
252
- })
253
-
254
- const pieData = makePieData({
255
- computedDataSeries: data.computedData,
256
- startAngle: data.fullParams.startAngle,
257
- endAngle: data.fullParams.endAngle
258
- })
259
-
260
- renderData = makeRenderData(pieData, arc, arcMouseover, data.fullParams.labelCentroid)
261
-
262
- const labelSelection = renderLabel(graphicSelection, renderData, data.fullParams, data.fullChartParams)
263
-
264
- labelSelection$.next(labelSelection)
265
-
266
- })
267
-
268
- combineLatest({
269
- labelSelection: labelSelection$,
270
- highlight: observer.seriesHighlight$.pipe(
271
- map(data => data.map(d => d.id))
272
- ),
273
- fullChartParams: observer.fullChartParams$,
274
- }).pipe(
275
- takeUntil(destroy$),
276
- switchMap(async d => d)
277
- ).subscribe(data => {
278
- highlight({
279
- labelSelection: data.labelSelection,
280
- ids: data.highlight,
281
- fullChartParams: data.fullChartParams,
282
- })
283
- })
284
-
285
- return () => {
286
- destroy$.next(undefined)
287
- }
288
- })
1
+ import * as d3 from 'd3'
2
+ import {
3
+ combineLatest,
4
+ switchMap,
5
+ first,
6
+ map,
7
+ takeUntil,
8
+ Subject,
9
+ BehaviorSubject } from 'rxjs'
10
+ import {
11
+ defineSeriesPlugin } from '@orbcharts/core'
12
+ import type {
13
+ ChartParams } from '@orbcharts/core'
14
+ import type { PieLabelsParams } from '../types'
15
+ import type { PieDatum } from '../seriesUtils'
16
+ import { DEFAULT_PIE_LABELS_PARAMS } from '../defaults'
17
+ import { makePieData } from '../seriesUtils'
18
+ import { makeD3Arc } from '../../utils/d3Utils'
19
+ import { getDatumColor, getClassName } from '../../utils/orbchartsUtils'
20
+
21
+ interface RenderDatum {
22
+ pieDatum: PieDatum
23
+ arcIndex: number
24
+ arcLabel: string
25
+ x: number
26
+ y: number
27
+ mouseoverX: number
28
+ mouseoverY: number
29
+ }
30
+
31
+ const pluginName = 'PieLabels'
32
+ const textClassName = getClassName(pluginName, 'text')
33
+
34
+ function makeRenderData (pieData: PieDatum[], arc: d3.Arc<any, d3.DefaultArcObject>, mouseoverArc: d3.Arc<any, d3.DefaultArcObject>, centroid: number): RenderDatum[] {
35
+ return pieData
36
+ .map((d, i) => {
37
+ const [_x, _y] = arc!.centroid(d as any)
38
+ const [_mouseoverX, _mouseoverY] = mouseoverArc!.centroid(d as any)
39
+ return {
40
+ pieDatum: d,
41
+ arcIndex: i,
42
+ arcLabel: d.data.label,
43
+ x: _x * centroid!,
44
+ y: _y * centroid!,
45
+ mouseoverX: _mouseoverX * centroid!,
46
+ mouseoverY: _mouseoverY * centroid!
47
+ }
48
+ })
49
+ .filter(d => d.pieDatum.data.visible)
50
+ }
51
+
52
+ // 繪製圓餅圖
53
+ function renderLabel (selection: d3.Selection<SVGGElement, undefined, any, any>, data: RenderDatum[], pluginParams: PieLabelsParams, fullChartParams: ChartParams) {
54
+ // console.log(data)
55
+ // let update = this.gSelection.selectAll('g').data(pieData)
56
+ let update: d3.Selection<SVGPathElement, RenderDatum, any, any> = selection
57
+ .selectAll<SVGPathElement, RenderDatum>('text')
58
+ .data(data, d => d.pieDatum.id)
59
+ let enter = update.enter()
60
+ .append<SVGPathElement>('text')
61
+ .classed(textClassName, true)
62
+ let exit = update.exit()
63
+
64
+ enter
65
+ .append('text')
66
+
67
+ const labelSelection = update.merge(enter)
68
+ labelSelection
69
+ .attr('font-weight', 'bold')
70
+ .attr('text-anchor', 'middle')
71
+ .style('dominant-baseline', 'middle')
72
+ // .style('pointer-events', 'none')
73
+ .style('cursor', d => fullChartParams.highlightTarget && fullChartParams.highlightTarget != 'none'
74
+ ? 'pointer'
75
+ : 'none')
76
+ // .text((d, i) => d.arcLabel)
77
+ .text(d => pluginParams.labelFn(d.pieDatum.data))
78
+ .attr('font-size', fullChartParams.styles.textSize)
79
+ .attr('fill', (d, i) => getDatumColor({ datum: d.pieDatum.data, colorType: pluginParams.labelColorType, fullChartParams }))
80
+ .transition()
81
+ .attr('transform', (d) => {
82
+ // console.log('transform', d)
83
+ return 'translate(' + d.x + ',' + d.y + ')'
84
+ })
85
+ // .on('end', () => initHighlight({ labelSelection, data, fullChartParams }))
86
+ exit.remove()
87
+
88
+ // 如無新增資料則不用等動畫
89
+ // if (enter.size() == 0) {
90
+ // this.initHighlight()
91
+ // }
92
+
93
+ return labelSelection
94
+ }
95
+
96
+ // function initHighlight ({ labelSelection, data, fullChartParams }: {
97
+ // labelSelection: (d3.Selection<SVGPathElement, RenderDatum, any, any>)
98
+ // data: RenderDatum[]
99
+ // fullChartParams: ChartParams
100
+ // }) {
101
+ // removeHighlight({ labelSelection })
102
+ // // if (fullParams.highlightSeriesId || fullParams.highlightDatumId) {
103
+ // highlight({
104
+ // labelSelection,
105
+ // data,
106
+ // id: fullChartParams.highlightDefault,
107
+ // label: fullChartParams.highlightDefault,
108
+ // fullChartParams
109
+ // })
110
+ // // }
111
+ // }
112
+
113
+ function highlight ({ labelSelection, ids, fullChartParams }: {
114
+ labelSelection: (d3.Selection<SVGPathElement, RenderDatum, any, any>)
115
+ ids: string[]
116
+ fullChartParams: ChartParams
117
+ }) {
118
+ labelSelection.interrupt('highlight')
119
+
120
+ if (!ids.length) {
121
+ labelSelection
122
+ .transition()
123
+ .duration(200)
124
+ .attr('transform', (d) => {
125
+ return 'translate(' + d.x + ',' + d.y + ')'
126
+ })
127
+ .style('opacity', 1)
128
+ return
129
+ }
130
+
131
+ labelSelection.each((d, i, n) => {
132
+ const segment = d3.select<SVGPathElement, RenderDatum>(n[i])
133
+
134
+ if (ids.includes(d.pieDatum.id)) {
135
+ segment
136
+ .style('opacity', 1)
137
+ .transition()
138
+ .duration(200)
139
+ .attr('transform', (d) => {
140
+ return 'translate(' + d.mouseoverX + ',' + d.mouseoverY + ')'
141
+ })
142
+ } else {
143
+ segment
144
+ .style('opacity', fullChartParams.styles.unhighlightedOpacity)
145
+ .transition()
146
+ .duration(200)
147
+ .attr('transform', (d) => {
148
+ return 'translate(' + d.x + ',' + d.y + ')'
149
+ })
150
+ }
151
+ })
152
+ }
153
+
154
+
155
+ // function removeHighlight ({ labelSelection }: {
156
+ // labelSelection: (d3.Selection<SVGPathElement, RenderDatum, any, any> | undefined)
157
+ // }) {
158
+ // if (!labelSelection) {
159
+ // return
160
+ // }
161
+
162
+ // // 取消放大
163
+ // labelSelection
164
+ // .transition()
165
+ // .duration(200)
166
+ // .attr('transform', (d) => {
167
+ // return 'translate(' + d.x + ',' + d.y + ')'
168
+ // })
169
+ // .style('opacity', 1)
170
+
171
+ // }
172
+
173
+
174
+ export const PieLabels = defineSeriesPlugin(pluginName, DEFAULT_PIE_LABELS_PARAMS)(({ selection, observer, subject }) => {
175
+
176
+ const destroy$ = new Subject()
177
+
178
+ const graphicSelection: d3.Selection<SVGGElement, any, any, any> = selection.append('g')
179
+ let labelSelection$: Subject<d3.Selection<SVGPathElement, RenderDatum, any, any>> = new Subject()
180
+ let renderData: RenderDatum[] = []
181
+ // let highlightTarget: HighlightTarget | undefined
182
+ // let fullChartParams: ChartParams | undefined
183
+
184
+ observer.layout$
185
+ .pipe(
186
+ first()
187
+ )
188
+ .subscribe(size => {
189
+ selection
190
+ .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
191
+ observer.layout$
192
+ .pipe(
193
+ takeUntil(destroy$)
194
+ )
195
+ .subscribe(size => {
196
+ selection
197
+ .transition()
198
+ .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
199
+ })
200
+ })
201
+
202
+
203
+
204
+ // combineLatest({
205
+ // event: store.event$,
206
+ // fullChartParams: fullChartParams$
207
+ // }).pipe(
208
+ // // 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
209
+ // switchMap(async (d) => d),
210
+ // ).subscribe(d => {
211
+ // if (d.event.eventName === 'mouseover' && d.event.datum) {
212
+ // highlight({
213
+ // labelSelection,
214
+ // data: renderData,
215
+ // id: d.fullChartParams.highlightTarget === 'datum' ? d.event.datum!.id : undefined,
216
+ // label: d.fullChartParams.highlightTarget === 'series' ? d.event.datum!.label : undefined,
217
+ // fullChartParams: d.fullChartParams
218
+ // })
219
+ // } else if (d.event.eventName === 'mouseout') {
220
+ // removeHighlight({ labelSelection })
221
+ // }
222
+ // })
223
+
224
+ combineLatest({
225
+ layout: observer.layout$,
226
+ computedData: observer.computedData$,
227
+ fullParams: observer.fullParams$,
228
+ fullChartParams: observer.fullChartParams$
229
+ }).pipe(
230
+ takeUntil(destroy$),
231
+ // 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
232
+ switchMap(async (d) => d),
233
+ ).subscribe(data => {
234
+
235
+ const shorterSideWith = data.layout.width < data.layout.height ? data.layout.width : data.layout.height
236
+
237
+ // 弧產生器 (d3.arc())
238
+ const arc = makeD3Arc({
239
+ axisWidth: shorterSideWith,
240
+ innerRadius: 0,
241
+ outerRadius: data.fullParams.outerRadius,
242
+ padAngle: 0,
243
+ cornerRadius: 0
244
+ })
245
+
246
+ const arcMouseover = makeD3Arc({
247
+ axisWidth: shorterSideWith,
248
+ innerRadius: 0,
249
+ outerRadius: data.fullParams.outerMouseoverRadius, // 外半徑變化
250
+ padAngle: 0,
251
+ cornerRadius: 0
252
+ })
253
+
254
+ const pieData = makePieData({
255
+ computedDataSeries: data.computedData,
256
+ startAngle: data.fullParams.startAngle,
257
+ endAngle: data.fullParams.endAngle
258
+ })
259
+
260
+ renderData = makeRenderData(pieData, arc, arcMouseover, data.fullParams.labelCentroid)
261
+
262
+ const labelSelection = renderLabel(graphicSelection, renderData, data.fullParams, data.fullChartParams)
263
+
264
+ labelSelection$.next(labelSelection)
265
+
266
+ })
267
+
268
+ combineLatest({
269
+ labelSelection: labelSelection$,
270
+ highlight: observer.seriesHighlight$.pipe(
271
+ map(data => data.map(d => d.id))
272
+ ),
273
+ fullChartParams: observer.fullChartParams$,
274
+ }).pipe(
275
+ takeUntil(destroy$),
276
+ switchMap(async d => d)
277
+ ).subscribe(data => {
278
+ highlight({
279
+ labelSelection: data.labelSelection,
280
+ ids: data.highlight,
281
+ fullChartParams: data.fullChartParams,
282
+ })
283
+ })
284
+
285
+ return () => {
286
+ destroy$.next(undefined)
287
+ }
288
+ })