@orbcharts/plugins-basic 3.0.7 → 3.0.9

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 (121) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-plugins-basic.es.js +6837 -6656
  3. package/dist/orbcharts-plugins-basic.umd.js +45 -45
  4. package/dist/src/base/BaseStackedBars.d.ts +2 -0
  5. package/dist/src/series/defaults.d.ts +2 -1
  6. package/dist/src/series/index.d.ts +1 -0
  7. package/dist/src/series/plugins/Indicator.d.ts +3 -0
  8. package/lib/core-types.ts +7 -7
  9. package/lib/core.ts +6 -6
  10. package/lib/gridObservables.ts +6 -6
  11. package/lib/plugins-basic-types.ts +6 -6
  12. package/package.json +48 -48
  13. package/src/base/BaseBars.ts +765 -765
  14. package/src/base/BaseBarsTriangle.ts +676 -676
  15. package/src/base/BaseDots.ts +464 -464
  16. package/src/base/BaseGroupAxis.ts +691 -691
  17. package/src/base/BaseLegend.ts +684 -684
  18. package/src/base/BaseLineAreas.ts +629 -629
  19. package/src/base/BaseLines.ts +706 -706
  20. package/src/base/BaseOrdinalBubbles.ts +729 -729
  21. package/src/base/BaseRacingBars.ts +582 -582
  22. package/src/base/BaseRacingLabels.ts +404 -404
  23. package/src/base/BaseRacingValueLabels.ts +403 -403
  24. package/src/base/BaseStackedBars.ts +793 -782
  25. package/src/base/BaseTooltip.ts +408 -408
  26. package/src/base/BaseValueAxis.ts +600 -600
  27. package/src/base/BaseXAxis.ts +427 -427
  28. package/src/base/BaseXZoom.ts +241 -241
  29. package/src/base/BaseYAxis.ts +389 -389
  30. package/src/base/types.ts +2 -2
  31. package/src/const.ts +30 -30
  32. package/src/grid/defaults.ts +213 -213
  33. package/src/grid/gridObservables.ts +635 -635
  34. package/src/grid/index.ts +16 -16
  35. package/src/grid/plugins/Bars.ts +69 -69
  36. package/src/grid/plugins/BarsPN.ts +66 -66
  37. package/src/grid/plugins/BarsTriangle.ts +73 -73
  38. package/src/grid/plugins/Dots.ts +68 -68
  39. package/src/grid/plugins/GridLegend.ts +107 -107
  40. package/src/grid/plugins/GridTooltip.ts +66 -66
  41. package/src/grid/plugins/GroupAux.ts +1095 -1095
  42. package/src/grid/plugins/GroupAxis.ts +73 -73
  43. package/src/grid/plugins/GroupZoom.ts +218 -218
  44. package/src/grid/plugins/LineAreas.ts +65 -65
  45. package/src/grid/plugins/Lines.ts +59 -59
  46. package/src/grid/plugins/StackedBars.ts +66 -64
  47. package/src/grid/plugins/StackedValueAxis.ts +97 -96
  48. package/src/grid/plugins/ValueAxis.ts +94 -94
  49. package/src/index.ts +6 -6
  50. package/src/multiGrid/defaults.ts +244 -244
  51. package/src/multiGrid/index.ts +14 -14
  52. package/src/multiGrid/multiGridObservables.ts +50 -50
  53. package/src/multiGrid/plugins/MultiBars.ts +108 -108
  54. package/src/multiGrid/plugins/MultiBarsTriangle.ts +114 -114
  55. package/src/multiGrid/plugins/MultiDots.ts +102 -102
  56. package/src/multiGrid/plugins/MultiGridLegend.ts +169 -169
  57. package/src/multiGrid/plugins/MultiGridTooltip.ts +66 -66
  58. package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
  59. package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
  60. package/src/multiGrid/plugins/MultiLines.ts +101 -101
  61. package/src/multiGrid/plugins/MultiStackedBars.ts +109 -106
  62. package/src/multiGrid/plugins/MultiStackedValueAxis.ts +135 -134
  63. package/src/multiGrid/plugins/MultiValueAxis.ts +134 -134
  64. package/src/multiGrid/plugins/OverlappingStackedValueAxes.ts +300 -300
  65. package/src/multiGrid/plugins/OverlappingValueAxes.ts +300 -300
  66. package/src/multiValue/defaults.ts +523 -523
  67. package/src/multiValue/index.ts +16 -16
  68. package/src/multiValue/multiValueObservables.ts +781 -781
  69. package/src/multiValue/plugins/MultiValueLegend.ts +107 -107
  70. package/src/multiValue/plugins/MultiValueTooltip.ts +66 -66
  71. package/src/multiValue/plugins/OrdinalAux.ts +660 -660
  72. package/src/multiValue/plugins/OrdinalAxis.ts +524 -524
  73. package/src/multiValue/plugins/OrdinalBubbles.ts +226 -226
  74. package/src/multiValue/plugins/OrdinalZoom.ts +57 -57
  75. package/src/multiValue/plugins/RacingBars.ts +375 -375
  76. package/src/multiValue/plugins/RacingCounterTexts.ts +300 -300
  77. package/src/multiValue/plugins/RacingValueAxis.ts +114 -114
  78. package/src/multiValue/plugins/Scatter.ts +486 -486
  79. package/src/multiValue/plugins/ScatterBubbles.ts +635 -635
  80. package/src/multiValue/plugins/XAxis.ts +107 -107
  81. package/src/multiValue/plugins/XYAux.ts +683 -683
  82. package/src/multiValue/plugins/XYAxes.ts +194 -194
  83. package/src/multiValue/plugins/XYAxes_legacy.ts +683 -683
  84. package/src/multiValue/plugins/XZoom.ts +40 -40
  85. package/src/noneData/defaults.ts +102 -102
  86. package/src/noneData/index.ts +3 -3
  87. package/src/noneData/plugins/Container.ts +27 -27
  88. package/src/noneData/plugins/Tooltip.ts +373 -373
  89. package/src/relationship/defaults.ts +221 -221
  90. package/src/relationship/index.ts +5 -5
  91. package/src/relationship/plugins/ForceDirected.ts +1056 -1056
  92. package/src/relationship/plugins/ForceDirectedBubbles.ts +1294 -1294
  93. package/src/relationship/plugins/RelationshipLegend.ts +100 -100
  94. package/src/relationship/plugins/RelationshipTooltip.ts +66 -66
  95. package/src/relationship/relationshipObservables.ts +49 -49
  96. package/src/series/defaults.ts +236 -224
  97. package/src/series/index.ts +10 -9
  98. package/src/series/plugins/Bubbles.ts +784 -784
  99. package/src/series/plugins/Indicator.ts +292 -0
  100. package/src/series/plugins/Pie.ts +622 -622
  101. package/src/series/plugins/PieEventTexts.ts +283 -283
  102. package/src/series/plugins/PieLabels.ts +639 -639
  103. package/src/series/plugins/Rose.ts +515 -515
  104. package/src/series/plugins/RoseLabels.ts +599 -599
  105. package/src/series/plugins/SeriesLegend.ts +107 -107
  106. package/src/series/plugins/SeriesTooltip.ts +66 -66
  107. package/src/series/seriesObservables.ts +168 -168
  108. package/src/series/seriesUtils.ts +51 -51
  109. package/src/tree/defaults.ts +102 -102
  110. package/src/tree/index.ts +4 -4
  111. package/src/tree/plugins/TreeLegend.ts +100 -100
  112. package/src/tree/plugins/TreeMap.ts +341 -341
  113. package/src/tree/plugins/TreeTooltip.ts +66 -66
  114. package/src/utils/commonUtils.ts +31 -31
  115. package/src/utils/d3Graphics.ts +176 -176
  116. package/src/utils/d3Utils.ts +92 -92
  117. package/src/utils/observables.ts +14 -14
  118. package/src/utils/orbchartsUtils.ts +129 -129
  119. package/tsconfig.base.json +13 -13
  120. package/tsconfig.json +2 -2
  121. package/vite.config.js +22 -22
@@ -1,283 +1,283 @@
1
- import * as d3 from 'd3'
2
- import {
3
- combineLatest,
4
- switchMap,
5
- first,
6
- takeUntil,
7
- map,
8
- distinctUntilChanged,
9
- Observable,
10
- Subject } from 'rxjs'
11
- import type { DefinePluginConfig } from '../../../lib/core-types'
12
- import type { Subscription } from 'rxjs'
13
- import {
14
- defineSeriesPlugin} from '../../../lib/core'
15
- import type {
16
- ComputedDatumSeries,
17
- ChartParams,
18
- ContainerPosition,
19
- EventName,
20
- EventSeries } from '../../../lib/core-types'
21
- import type { PieEventTextsParams } from '../../../lib/plugins-basic-types'
22
- import { DEFAULT_PIE_EVENT_TEXTS_PARAMS } from '../defaults'
23
- import { getD3TransitionEase } from '../../utils/d3Utils'
24
- import { getClassName } from '../../utils/orbchartsUtils'
25
- import { seriesCenterSelectionObservable } from '../seriesObservables'
26
- import { LAYER_INDEX_OF_LABEL } from '../../const'
27
-
28
- type TextDatum = {
29
- text: string
30
- attr: { [key:string]: any }
31
- style: { [key:string]: any }
32
- }
33
-
34
- const pluginName = 'PieEventTexts'
35
- const textClassName = getClassName(pluginName, 'text')
36
-
37
- const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_PIE_EVENT_TEXTS_PARAMS> = {
38
- name: pluginName,
39
- defaultParams: DEFAULT_PIE_EVENT_TEXTS_PARAMS,
40
- layerIndex: LAYER_INDEX_OF_LABEL,
41
- validator: (params, { validateColumns }) => {
42
- const result = validateColumns(params, {
43
- renderFn: {
44
- toBeTypes: ['Function'],
45
- },
46
- textAttrs: {
47
- toBeTypes: ['object[]'],
48
- },
49
- textStyles: {
50
- toBeTypes: ['object[]'],
51
- }
52
- })
53
- return result
54
- }
55
- }
56
-
57
- function renderText (
58
- selection: d3.Selection<SVGGElement, unknown, any, any>,
59
- data: Array<TextDatum>
60
- ): d3.Selection<SVGTextElement, TextDatum, SVGGElement, unknown> {
61
- const textUpdate = selection
62
- .selectAll<SVGTextElement, TextDatum>(`text.${textClassName}`)
63
- .data(data)
64
- const textEnter = textUpdate.enter()
65
- .append('text')
66
- .classed(textClassName, true)
67
- const text = textUpdate.merge(textEnter)
68
- text
69
- .each((d, i, g) => {
70
- const t = d3.select(g[i])
71
- .text(d.text)
72
- Object.keys(d.attr)
73
- .forEach(key => {
74
- t.attr(key, d.attr[key])
75
- })
76
- Object.keys(d.style)
77
- .forEach(key => {
78
- t.style(key, d.style[key])
79
- })
80
- })
81
-
82
- textUpdate.exit().remove()
83
-
84
- return text
85
- }
86
-
87
- function createTextData ({ eventData, renderFn, textAttrs, textStyles }: {
88
- eventData: EventSeries,
89
- // t: number,
90
- renderFn: (d: EventSeries) => string[] | string
91
- textAttrs: Array<{ [key:string]: string | number }>
92
- textStyles: Array<{ [key:string]: string | number }>
93
- }): TextDatum[] {
94
- const callbackText = renderFn(eventData)
95
- const textArr = Array.isArray(callbackText) ? callbackText : [callbackText]
96
- return textArr.map((d, i) => {
97
- return {
98
- text: d,
99
- attr: textAttrs[i],
100
- style: textStyles[i]
101
- }
102
- })
103
- }
104
-
105
- function createEachPieEventTexts (pluginName: string, context: {
106
- containerSelection: d3.Selection<SVGGElement, any, any, unknown>
107
- computedData$: Observable<ComputedDatumSeries[][]>
108
- containerComputedSortedData$: Observable<ComputedDatumSeries[]>
109
- SeriesDataMap$: Observable<Map<string, ComputedDatumSeries[]>>
110
- fullParams$: Observable<PieEventTextsParams>
111
- fullChartParams$: Observable<ChartParams>
112
- seriesHighlight$: Observable<ComputedDatumSeries[]>
113
- seriesContainerPosition$: Observable<ContainerPosition>
114
- event$: Subject<EventSeries>
115
- }) {
116
- const destroy$ = new Subject()
117
-
118
- // const graphicSelection: d3.Selection<SVGGElement, any, any, any> = selection.append('g')
119
- let centerTextSelection: d3.Selection<SVGTextElement, TextDatum, SVGGElement, unknown> | undefined
120
- let storeEventSubscription: Subscription | undefined
121
-
122
- // context.layout$
123
- // .pipe(
124
- // first()
125
- // )
126
- // .subscribe(size => {
127
- // selection
128
- // .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
129
- // context.layout$
130
- // .pipe(
131
- // takeUntil(destroy$)
132
- // )
133
- // .subscribe(size => {
134
- // selection
135
- // .transition()
136
- // .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
137
- // })
138
- // })
139
-
140
- const highlightTarget$ = context.fullChartParams$.pipe(
141
- takeUntil(destroy$),
142
- map(d => d.highlightTarget),
143
- distinctUntilChanged()
144
- )
145
-
146
- combineLatest({
147
- computedData: context.computedData$,
148
- fullParams: context.fullParams$,
149
- fullChartParams: context.fullChartParams$,
150
- highlightTarget: highlightTarget$,
151
- }).pipe(
152
- takeUntil(destroy$),
153
- switchMap(async (d) => d),
154
- ).subscribe(data => {
155
-
156
- context.containerSelection
157
- .transition('move')
158
- .duration(data.fullChartParams.transitionDuration!)
159
- // .ease(getD3TransitionEase(data.fullChartParams.transitionEase!))
160
- .tween('move', (event, datum) => {
161
- return (t) => {
162
- const renderData = createTextData({
163
- eventData: {
164
- type: 'series',
165
- pluginName,
166
- eventName: 'transitionMove',
167
- event,
168
- tween: t,
169
- highlightTarget: data.highlightTarget,
170
- data: data.computedData,
171
- series: [],
172
- seriesIndex: -1,
173
- seriesLabel: '',
174
- datum: null
175
- },
176
- // eventName: 'transitionMove',
177
- // t,
178
- renderFn: data.fullParams.renderFn!,
179
- textAttrs: data.fullParams.textAttrs!,
180
- textStyles: data.fullParams.textStyles!
181
- })
182
- centerTextSelection = renderText(context.containerSelection, renderData)
183
- }
184
- })
185
- .on('end', (event, datum) => {
186
- const renderData = createTextData({
187
- eventData: {
188
- type: 'series',
189
- pluginName,
190
- eventName: 'transitionEnd',
191
- event,
192
- tween: 1,
193
- highlightTarget: data.highlightTarget,
194
- data: data.computedData,
195
- series: [],
196
- seriesIndex: -1,
197
- seriesLabel: '',
198
- datum: null
199
- },
200
- // eventName: 'transitionMove',
201
- // t: 1,
202
- renderFn: data.fullParams.renderFn!,
203
- textAttrs: data.fullParams.textAttrs!,
204
- textStyles: data.fullParams.textStyles!
205
- })
206
- centerTextSelection = renderText(context.containerSelection, renderData)
207
-
208
- if (storeEventSubscription) {
209
- storeEventSubscription.unsubscribe()
210
- }
211
- storeEventSubscription = context.event$
212
- .subscribe(eventData => {
213
- const renderData = createTextData({
214
- eventData,
215
- // t: 1,
216
- renderFn: data.fullParams.renderFn!,
217
- textAttrs: data.fullParams.textAttrs!,
218
- textStyles: data.fullParams.textStyles!
219
- })
220
- centerTextSelection = renderText(context.containerSelection, renderData)
221
- })
222
- })
223
- })
224
-
225
- return () => {
226
- destroy$.next(undefined)
227
- }
228
- }
229
-
230
- export const PieEventTexts = defineSeriesPlugin(pluginConfig)(({ selection, name, observer, subject }) => {
231
- const destroy$ = new Subject()
232
-
233
- const { seriesCenterSelection$ } = seriesCenterSelectionObservable({
234
- selection: selection,
235
- pluginName,
236
- visibleComputedSortedData$: observer.visibleComputedSortedData$,
237
- seriesContainerPosition$: observer.seriesContainerPosition$
238
- })
239
-
240
- const unsubscribeFnArr: (() => void)[] = []
241
-
242
- seriesCenterSelection$
243
- .pipe(
244
- takeUntil(destroy$)
245
- )
246
- .subscribe(seriesCenterSelection => {
247
- // 每次重新計算時,清除之前的訂閱
248
- unsubscribeFnArr.forEach(fn => fn())
249
-
250
- seriesCenterSelection.each((d, containerIndex, g) => {
251
-
252
- const containerSelection = d3.select(g[containerIndex])
253
-
254
- const containerComputedSortedData$ = observer.computedSortedData$.pipe(
255
- takeUntil(destroy$),
256
- map(data => data[containerIndex] ?? data[0])
257
- )
258
-
259
- const containerPosition$ = observer.seriesContainerPosition$.pipe(
260
- takeUntil(destroy$),
261
- map(data => data[containerIndex] ?? data[0])
262
- )
263
-
264
- unsubscribeFnArr[containerIndex] = createEachPieEventTexts(pluginName, {
265
- containerSelection: containerSelection,
266
- computedData$: observer.computedData$,
267
- containerComputedSortedData$: containerComputedSortedData$,
268
- SeriesDataMap$: observer.SeriesDataMap$,
269
- fullParams$: observer.fullParams$,
270
- fullChartParams$: observer.fullChartParams$,
271
- seriesHighlight$: observer.seriesHighlight$,
272
- seriesContainerPosition$: containerPosition$,
273
- event$: subject.event$,
274
- })
275
-
276
- })
277
- })
278
-
279
- return () => {
280
- destroy$.next(undefined)
281
- unsubscribeFnArr.forEach(fn => fn())
282
- }
283
- })
1
+ import * as d3 from 'd3'
2
+ import {
3
+ combineLatest,
4
+ switchMap,
5
+ first,
6
+ takeUntil,
7
+ map,
8
+ distinctUntilChanged,
9
+ Observable,
10
+ Subject } from 'rxjs'
11
+ import type { DefinePluginConfig } from '../../../lib/core-types'
12
+ import type { Subscription } from 'rxjs'
13
+ import {
14
+ defineSeriesPlugin} from '../../../lib/core'
15
+ import type {
16
+ ComputedDatumSeries,
17
+ ChartParams,
18
+ ContainerPosition,
19
+ EventName,
20
+ EventSeries } from '../../../lib/core-types'
21
+ import type { PieEventTextsParams } from '../../../lib/plugins-basic-types'
22
+ import { DEFAULT_PIE_EVENT_TEXTS_PARAMS } from '../defaults'
23
+ import { getD3TransitionEase } from '../../utils/d3Utils'
24
+ import { getClassName } from '../../utils/orbchartsUtils'
25
+ import { seriesCenterSelectionObservable } from '../seriesObservables'
26
+ import { LAYER_INDEX_OF_LABEL } from '../../const'
27
+
28
+ type TextDatum = {
29
+ text: string
30
+ attr: { [key:string]: any }
31
+ style: { [key:string]: any }
32
+ }
33
+
34
+ const pluginName = 'PieEventTexts'
35
+ const textClassName = getClassName(pluginName, 'text')
36
+
37
+ const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_PIE_EVENT_TEXTS_PARAMS> = {
38
+ name: pluginName,
39
+ defaultParams: DEFAULT_PIE_EVENT_TEXTS_PARAMS,
40
+ layerIndex: LAYER_INDEX_OF_LABEL,
41
+ validator: (params, { validateColumns }) => {
42
+ const result = validateColumns(params, {
43
+ renderFn: {
44
+ toBeTypes: ['Function'],
45
+ },
46
+ textAttrs: {
47
+ toBeTypes: ['object[]'],
48
+ },
49
+ textStyles: {
50
+ toBeTypes: ['object[]'],
51
+ }
52
+ })
53
+ return result
54
+ }
55
+ }
56
+
57
+ function renderText (
58
+ selection: d3.Selection<SVGGElement, unknown, any, any>,
59
+ data: Array<TextDatum>
60
+ ): d3.Selection<SVGTextElement, TextDatum, SVGGElement, unknown> {
61
+ const textUpdate = selection
62
+ .selectAll<SVGTextElement, TextDatum>(`text.${textClassName}`)
63
+ .data(data)
64
+ const textEnter = textUpdate.enter()
65
+ .append('text')
66
+ .classed(textClassName, true)
67
+ const text = textUpdate.merge(textEnter)
68
+ text
69
+ .each((d, i, g) => {
70
+ const t = d3.select(g[i])
71
+ .text(d.text)
72
+ Object.keys(d.attr)
73
+ .forEach(key => {
74
+ t.attr(key, d.attr[key])
75
+ })
76
+ Object.keys(d.style)
77
+ .forEach(key => {
78
+ t.style(key, d.style[key])
79
+ })
80
+ })
81
+
82
+ textUpdate.exit().remove()
83
+
84
+ return text
85
+ }
86
+
87
+ function createTextData ({ eventData, renderFn, textAttrs, textStyles }: {
88
+ eventData: EventSeries,
89
+ // t: number,
90
+ renderFn: (d: EventSeries) => string[] | string
91
+ textAttrs: Array<{ [key:string]: string | number }>
92
+ textStyles: Array<{ [key:string]: string | number }>
93
+ }): TextDatum[] {
94
+ const callbackText = renderFn(eventData)
95
+ const textArr = Array.isArray(callbackText) ? callbackText : [callbackText]
96
+ return textArr.map((d, i) => {
97
+ return {
98
+ text: d,
99
+ attr: textAttrs[i],
100
+ style: textStyles[i]
101
+ }
102
+ })
103
+ }
104
+
105
+ function createEachPieEventTexts (pluginName: string, context: {
106
+ containerSelection: d3.Selection<SVGGElement, any, any, unknown>
107
+ computedData$: Observable<ComputedDatumSeries[][]>
108
+ containerComputedSortedData$: Observable<ComputedDatumSeries[]>
109
+ SeriesDataMap$: Observable<Map<string, ComputedDatumSeries[]>>
110
+ fullParams$: Observable<PieEventTextsParams>
111
+ fullChartParams$: Observable<ChartParams>
112
+ seriesHighlight$: Observable<ComputedDatumSeries[]>
113
+ seriesContainerPosition$: Observable<ContainerPosition>
114
+ event$: Subject<EventSeries>
115
+ }) {
116
+ const destroy$ = new Subject()
117
+
118
+ // const graphicSelection: d3.Selection<SVGGElement, any, any, any> = selection.append('g')
119
+ let centerTextSelection: d3.Selection<SVGTextElement, TextDatum, SVGGElement, unknown> | undefined
120
+ let storeEventSubscription: Subscription | undefined
121
+
122
+ // context.layout$
123
+ // .pipe(
124
+ // first()
125
+ // )
126
+ // .subscribe(size => {
127
+ // selection
128
+ // .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
129
+ // context.layout$
130
+ // .pipe(
131
+ // takeUntil(destroy$)
132
+ // )
133
+ // .subscribe(size => {
134
+ // selection
135
+ // .transition()
136
+ // .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
137
+ // })
138
+ // })
139
+
140
+ const highlightTarget$ = context.fullChartParams$.pipe(
141
+ takeUntil(destroy$),
142
+ map(d => d.highlightTarget),
143
+ distinctUntilChanged()
144
+ )
145
+
146
+ combineLatest({
147
+ computedData: context.computedData$,
148
+ fullParams: context.fullParams$,
149
+ fullChartParams: context.fullChartParams$,
150
+ highlightTarget: highlightTarget$,
151
+ }).pipe(
152
+ takeUntil(destroy$),
153
+ switchMap(async (d) => d),
154
+ ).subscribe(data => {
155
+
156
+ context.containerSelection
157
+ .transition('move')
158
+ .duration(data.fullChartParams.transitionDuration!)
159
+ // .ease(getD3TransitionEase(data.fullChartParams.transitionEase!))
160
+ .tween('move', (event, datum) => {
161
+ return (t) => {
162
+ const renderData = createTextData({
163
+ eventData: {
164
+ type: 'series',
165
+ pluginName,
166
+ eventName: 'transitionMove',
167
+ event,
168
+ tween: t,
169
+ highlightTarget: data.highlightTarget,
170
+ data: data.computedData,
171
+ series: [],
172
+ seriesIndex: -1,
173
+ seriesLabel: '',
174
+ datum: null
175
+ },
176
+ // eventName: 'transitionMove',
177
+ // t,
178
+ renderFn: data.fullParams.renderFn!,
179
+ textAttrs: data.fullParams.textAttrs!,
180
+ textStyles: data.fullParams.textStyles!
181
+ })
182
+ centerTextSelection = renderText(context.containerSelection, renderData)
183
+ }
184
+ })
185
+ .on('end', (event, datum) => {
186
+ const renderData = createTextData({
187
+ eventData: {
188
+ type: 'series',
189
+ pluginName,
190
+ eventName: 'transitionEnd',
191
+ event,
192
+ tween: 1,
193
+ highlightTarget: data.highlightTarget,
194
+ data: data.computedData,
195
+ series: [],
196
+ seriesIndex: -1,
197
+ seriesLabel: '',
198
+ datum: null
199
+ },
200
+ // eventName: 'transitionMove',
201
+ // t: 1,
202
+ renderFn: data.fullParams.renderFn!,
203
+ textAttrs: data.fullParams.textAttrs!,
204
+ textStyles: data.fullParams.textStyles!
205
+ })
206
+ centerTextSelection = renderText(context.containerSelection, renderData)
207
+
208
+ if (storeEventSubscription) {
209
+ storeEventSubscription.unsubscribe()
210
+ }
211
+ storeEventSubscription = context.event$
212
+ .subscribe(eventData => {
213
+ const renderData = createTextData({
214
+ eventData,
215
+ // t: 1,
216
+ renderFn: data.fullParams.renderFn!,
217
+ textAttrs: data.fullParams.textAttrs!,
218
+ textStyles: data.fullParams.textStyles!
219
+ })
220
+ centerTextSelection = renderText(context.containerSelection, renderData)
221
+ })
222
+ })
223
+ })
224
+
225
+ return () => {
226
+ destroy$.next(undefined)
227
+ }
228
+ }
229
+
230
+ export const PieEventTexts = defineSeriesPlugin(pluginConfig)(({ selection, name, observer, subject }) => {
231
+ const destroy$ = new Subject()
232
+
233
+ const { seriesCenterSelection$ } = seriesCenterSelectionObservable({
234
+ selection: selection,
235
+ pluginName,
236
+ visibleComputedSortedData$: observer.visibleComputedSortedData$,
237
+ seriesContainerPosition$: observer.seriesContainerPosition$
238
+ })
239
+
240
+ const unsubscribeFnArr: (() => void)[] = []
241
+
242
+ seriesCenterSelection$
243
+ .pipe(
244
+ takeUntil(destroy$)
245
+ )
246
+ .subscribe(seriesCenterSelection => {
247
+ // 每次重新計算時,清除之前的訂閱
248
+ unsubscribeFnArr.forEach(fn => fn())
249
+
250
+ seriesCenterSelection.each((d, containerIndex, g) => {
251
+
252
+ const containerSelection = d3.select(g[containerIndex])
253
+
254
+ const containerComputedSortedData$ = observer.computedSortedData$.pipe(
255
+ takeUntil(destroy$),
256
+ map(data => data[containerIndex] ?? data[0])
257
+ )
258
+
259
+ const containerPosition$ = observer.seriesContainerPosition$.pipe(
260
+ takeUntil(destroy$),
261
+ map(data => data[containerIndex] ?? data[0])
262
+ )
263
+
264
+ unsubscribeFnArr[containerIndex] = createEachPieEventTexts(pluginName, {
265
+ containerSelection: containerSelection,
266
+ computedData$: observer.computedData$,
267
+ containerComputedSortedData$: containerComputedSortedData$,
268
+ SeriesDataMap$: observer.SeriesDataMap$,
269
+ fullParams$: observer.fullParams$,
270
+ fullChartParams$: observer.fullChartParams$,
271
+ seriesHighlight$: observer.seriesHighlight$,
272
+ seriesContainerPosition$: containerPosition$,
273
+ event$: subject.event$,
274
+ })
275
+
276
+ })
277
+ })
278
+
279
+ return () => {
280
+ destroy$.next(undefined)
281
+ unsubscribeFnArr.forEach(fn => fn())
282
+ }
283
+ })