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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. package/LICENSE +200 -200
  2. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseBarStack.d.ts +6 -4
  3. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseBars.d.ts +6 -4
  4. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseBarsTriangle.d.ts +7 -4
  5. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseDots.d.ts +5 -3
  6. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseGroupAxis.d.ts +3 -3
  7. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLineAreas.d.ts +6 -3
  8. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLines.d.ts +6 -3
  9. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseValueAxis.d.ts +3 -3
  10. package/dist/{src → orbcharts-plugins-basic/src}/grid/gridObservables.d.ts +4 -4
  11. package/dist/orbcharts-plugins-basic/src/index.d.ts +5 -0
  12. package/dist/orbcharts-plugins-basic/src/multiGrid/multiGridObservables.d.ts +8 -0
  13. package/dist/orbcharts-plugins-basic/src/series/plugins/PieEventTexts.d.ts +3 -0
  14. package/dist/orbcharts-plugins-basic/src/series/seriesObservables.d.ts +21 -0
  15. package/dist/{src → orbcharts-plugins-basic/src}/series/seriesUtils.d.ts +3 -3
  16. package/dist/orbcharts-plugins-basic.es.js +7696 -7529
  17. package/dist/orbcharts-plugins-basic.umd.js +8 -8
  18. package/dist/src/index.d.ts +1 -5
  19. package/package.json +42 -42
  20. package/src/base/BaseBarStack.ts +778 -881
  21. package/src/base/BaseBars.ts +764 -750
  22. package/src/base/BaseBarsTriangle.ts +672 -659
  23. package/src/base/BaseDots.ts +502 -639
  24. package/src/base/BaseGroupAxis.ts +496 -496
  25. package/src/base/BaseLegend.ts +641 -641
  26. package/src/base/BaseLineAreas.ts +625 -621
  27. package/src/base/BaseLines.ts +699 -692
  28. package/src/base/BaseValueAxis.ts +478 -479
  29. package/src/base/types.ts +2 -2
  30. package/src/grid/defaults.ts +121 -121
  31. package/src/grid/gridObservables.ts +247 -263
  32. package/src/grid/index.ts +15 -15
  33. package/src/grid/plugins/BarStack.ts +50 -37
  34. package/src/grid/plugins/Bars.ts +51 -37
  35. package/src/grid/plugins/BarsDiverging.ts +41 -39
  36. package/src/grid/plugins/BarsTriangle.ts +50 -34
  37. package/src/grid/plugins/Dots.ts +37 -35
  38. package/src/grid/plugins/GridLegend.ts +59 -59
  39. package/src/grid/plugins/GroupAux.ts +645 -646
  40. package/src/grid/plugins/GroupAxis.ts +42 -30
  41. package/src/grid/plugins/LineAreas.ts +39 -36
  42. package/src/grid/plugins/Lines.ts +38 -35
  43. package/src/grid/plugins/ScalingArea.ts +173 -174
  44. package/src/grid/plugins/ValueAxis.ts +43 -31
  45. package/src/grid/plugins/ValueStackAxis.ts +79 -70
  46. package/src/grid/types.ts +120 -120
  47. package/src/index.ts +9 -9
  48. package/src/multiGrid/defaults.ts +147 -147
  49. package/src/multiGrid/index.ts +11 -11
  50. package/src/multiGrid/multiGridObservables.ts +42 -289
  51. package/src/multiGrid/plugins/MultiBarStack.ts +74 -60
  52. package/src/multiGrid/plugins/MultiBars.ts +73 -59
  53. package/src/multiGrid/plugins/MultiBarsTriangle.ts +73 -58
  54. package/src/multiGrid/plugins/MultiDots.ts +60 -58
  55. package/src/multiGrid/plugins/MultiGridLegend.ts +89 -89
  56. package/src/multiGrid/plugins/MultiGroupAxis.ts +65 -53
  57. package/src/multiGrid/plugins/MultiLineAreas.ts +62 -59
  58. package/src/multiGrid/plugins/MultiLines.ts +61 -58
  59. package/src/multiGrid/plugins/MultiValueAxis.ts +65 -53
  60. package/src/multiGrid/plugins/OverlappingValueAxes.ts +169 -164
  61. package/src/multiGrid/types.ts +67 -67
  62. package/src/noneData/defaults.ts +64 -61
  63. package/src/noneData/index.ts +3 -3
  64. package/src/noneData/plugins/Container.ts +10 -10
  65. package/src/noneData/plugins/Tooltip.ts +310 -310
  66. package/src/noneData/types.ts +26 -26
  67. package/src/series/defaults.ts +109 -99
  68. package/src/series/index.ts +6 -6
  69. package/src/series/plugins/Bubbles.ts +571 -551
  70. package/src/series/plugins/Pie.ts +548 -600
  71. package/src/series/plugins/PieEventTexts.ts +258 -194
  72. package/src/series/plugins/PieLabels.ts +335 -288
  73. package/src/series/plugins/SeriesLegend.ts +59 -59
  74. package/src/series/seriesObservables.ts +145 -0
  75. package/src/series/seriesUtils.ts +50 -50
  76. package/src/series/types.ts +67 -67
  77. package/src/tree/defaults.ts +22 -22
  78. package/src/tree/index.ts +3 -3
  79. package/src/tree/plugins/TreeLegend.ts +59 -59
  80. package/src/tree/plugins/TreeMap.ts +305 -305
  81. package/src/tree/types.ts +23 -23
  82. package/src/utils/commonUtils.ts +21 -21
  83. package/src/utils/d3Graphics.ts +124 -124
  84. package/src/utils/d3Utils.ts +73 -73
  85. package/src/utils/observables.ts +14 -14
  86. package/src/utils/orbchartsUtils.ts +100 -100
  87. package/tsconfig.dev.json +16 -16
  88. package/tsconfig.json +16 -13
  89. package/tsconfig.prod.json +13 -13
  90. package/vite.config.js +49 -49
  91. package/dist/src/multiGrid/multiGridObservables.d.ts +0 -12
  92. package/dist/src/series/plugins/PieEventTexts.d.ts +0 -1
  93. /package/dist/{src → orbcharts-plugins-basic/src}/base/BaseGroupArea.d.ts +0 -0
  94. /package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLegend.d.ts +0 -0
  95. /package/dist/{src → orbcharts-plugins-basic/src}/base/types.d.ts +0 -0
  96. /package/dist/{src → orbcharts-plugins-basic/src}/grid/defaults.d.ts +0 -0
  97. /package/dist/{src → orbcharts-plugins-basic/src}/grid/index.d.ts +0 -0
  98. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/BarStack.d.ts +0 -0
  99. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Bars.d.ts +0 -0
  100. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/BarsDiverging.d.ts +0 -0
  101. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/BarsTriangle.d.ts +0 -0
  102. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Dots.d.ts +0 -0
  103. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GridLegend.d.ts +0 -0
  104. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GroupAux.d.ts +0 -0
  105. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GroupAxis.d.ts +0 -0
  106. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/LineAreas.d.ts +0 -0
  107. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Lines.d.ts +0 -0
  108. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Ranking.d.ts +0 -0
  109. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/RankingAxis.d.ts +0 -0
  110. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/ScalingArea.d.ts +0 -0
  111. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/ValueAxis.d.ts +0 -0
  112. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/ValueStackAxis.d.ts +0 -0
  113. /package/dist/{src → orbcharts-plugins-basic/src}/grid/types.d.ts +0 -0
  114. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/defaults.d.ts +0 -0
  115. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/index.d.ts +0 -0
  116. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiBarStack.d.ts +0 -0
  117. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiBars.d.ts +0 -0
  118. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiBarsTriangle.d.ts +0 -0
  119. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiDots.d.ts +0 -0
  120. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiGridLegend.d.ts +0 -0
  121. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiGroupAxis.d.ts +0 -0
  122. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiLineAreas.d.ts +0 -0
  123. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiLines.d.ts +0 -0
  124. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiValueAxis.d.ts +0 -0
  125. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/OverlappingValueAxes.d.ts +0 -0
  126. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/types.d.ts +0 -0
  127. /package/dist/{src → orbcharts-plugins-basic/src}/multiValue/index.d.ts +0 -0
  128. /package/dist/{src → orbcharts-plugins-basic/src}/multiValue/plugins/Scatter.d.ts +0 -0
  129. /package/dist/{src → orbcharts-plugins-basic/src}/multiValue/plugins/ScatterAxes.d.ts +0 -0
  130. /package/dist/{src → orbcharts-plugins-basic/src}/noneData/defaults.d.ts +0 -0
  131. /package/dist/{src → orbcharts-plugins-basic/src}/noneData/index.d.ts +0 -0
  132. /package/dist/{src → orbcharts-plugins-basic/src}/noneData/plugins/Container.d.ts +0 -0
  133. /package/dist/{src → orbcharts-plugins-basic/src}/noneData/plugins/Tooltip.d.ts +0 -0
  134. /package/dist/{src → orbcharts-plugins-basic/src}/noneData/types.d.ts +0 -0
  135. /package/dist/{src → orbcharts-plugins-basic/src}/relationship/index.d.ts +0 -0
  136. /package/dist/{src → orbcharts-plugins-basic/src}/relationship/plugins/Relationship.d.ts +0 -0
  137. /package/dist/{src → orbcharts-plugins-basic/src}/series/defaults.d.ts +0 -0
  138. /package/dist/{src → orbcharts-plugins-basic/src}/series/index.d.ts +0 -0
  139. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Bubbles.d.ts +0 -0
  140. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Pie.d.ts +0 -0
  141. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/PieLabels.d.ts +0 -0
  142. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/SeriesLegend.d.ts +0 -0
  143. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Waffle.d.ts +0 -0
  144. /package/dist/{src → orbcharts-plugins-basic/src}/series/types.d.ts +0 -0
  145. /package/dist/{src → orbcharts-plugins-basic/src}/tree/defaults.d.ts +0 -0
  146. /package/dist/{src → orbcharts-plugins-basic/src}/tree/index.d.ts +0 -0
  147. /package/dist/{src → orbcharts-plugins-basic/src}/tree/plugins/TreeLegend.d.ts +0 -0
  148. /package/dist/{src → orbcharts-plugins-basic/src}/tree/plugins/TreeMap.d.ts +0 -0
  149. /package/dist/{src → orbcharts-plugins-basic/src}/tree/types.d.ts +0 -0
  150. /package/dist/{src → orbcharts-plugins-basic/src}/utils/commonUtils.d.ts +0 -0
  151. /package/dist/{src → orbcharts-plugins-basic/src}/utils/d3Graphics.d.ts +0 -0
  152. /package/dist/{src → orbcharts-plugins-basic/src}/utils/d3Utils.d.ts +0 -0
  153. /package/dist/{src → orbcharts-plugins-basic/src}/utils/observables.d.ts +0 -0
  154. /package/dist/{src → orbcharts-plugins-basic/src}/utils/orbchartsUtils.d.ts +0 -0
  155. /package/dist/{vite.config.d.ts → orbcharts-plugins-basic/vite.config.d.ts} +0 -0
@@ -1,194 +1,258 @@
1
- import * as d3 from 'd3'
2
- import {
3
- combineLatest,
4
- switchMap,
5
- first,
6
- takeUntil,
7
- map,
8
- distinctUntilChanged,
9
- Subject } from 'rxjs'
10
- import type { Subscription } from 'rxjs'
11
- import {
12
- defineSeriesPlugin} from '@orbcharts/core'
13
- import type {
14
- EventName,
15
- EventSeries } from '@orbcharts/core'
16
- import { DEFAULT_PIE_EVENT_TEXTS_PARAMS } from '../defaults'
17
- import { getD3TransitionEase } from '../../utils/d3Utils'
18
- import { getClassName } from '../../utils/orbchartsUtils'
19
-
20
- type TextDatum = {
21
- text: string
22
- attr: { [key:string]: any }
23
- style: { [key:string]: any }
24
- }
25
-
26
- const pluginName = 'PieEventTexts'
27
- const textClassName = getClassName(pluginName, 'text')
28
-
29
- function renderText (
30
- selection: d3.Selection<SVGGElement, unknown, any, any>,
31
- data: Array<TextDatum>
32
- ): d3.Selection<SVGTextElement, TextDatum, SVGGElement, unknown> {
33
- const textUpdate = selection
34
- .selectAll<SVGTextElement, TextDatum>(`text.${textClassName}`)
35
- .data(data)
36
- const textEnter = textUpdate.enter()
37
- .append('text')
38
- .classed(textClassName, true)
39
- const text = textUpdate.merge(textEnter)
40
- text
41
- .each((d, i, g) => {
42
- const t = d3.select(g[i])
43
- .text(d.text)
44
- Object.keys(d.attr)
45
- .forEach(key => {
46
- t.attr(key, d.attr[key])
47
- })
48
- Object.keys(d.style)
49
- .forEach(key => {
50
- t.style(key, d.style[key])
51
- })
52
- })
53
-
54
- textUpdate.exit().remove()
55
-
56
- return text
57
- }
58
-
59
- function makeTextData ({ eventData, eventName, t, eventFn, textAttrs, textStyles }: {
60
- eventData: EventSeries,
61
- eventName: EventName,
62
- t: number,
63
- eventFn: (d: EventSeries, eventName: EventName, t: number) => string[]
64
- textAttrs: Array<{ [key:string]: string | number }>
65
- textStyles: Array<{ [key:string]: string | number }>
66
- }): TextDatum[] {
67
- const callbackText = eventFn(eventData, eventName, t)
68
- return callbackText.map((d, i) => {
69
- return {
70
- text: d,
71
- attr: textAttrs[i],
72
- style: textStyles[i]
73
- }
74
- })
75
- }
76
-
77
-
78
-
79
- export const PieEventTexts = defineSeriesPlugin(pluginName, DEFAULT_PIE_EVENT_TEXTS_PARAMS)(({ selection, name, observer, subject }) => {
80
-
81
- const destroy$ = new Subject()
82
-
83
- const graphicSelection: d3.Selection<SVGGElement, any, any, any> = selection.append('g')
84
- let centerTextSelection: d3.Selection<SVGTextElement, TextDatum, SVGGElement, unknown> | undefined
85
- let storeEventSubscription: Subscription | undefined
86
-
87
- observer.layout$
88
- .pipe(
89
- first()
90
- )
91
- .subscribe(size => {
92
- selection
93
- .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
94
- observer.layout$
95
- .pipe(
96
- takeUntil(destroy$)
97
- )
98
- .subscribe(size => {
99
- selection
100
- .transition()
101
- .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
102
- })
103
- })
104
-
105
-
106
- const highlightTarget$ = observer.fullChartParams$.pipe(
107
- takeUntil(destroy$),
108
- map(d => d.highlightTarget),
109
- distinctUntilChanged()
110
- )
111
-
112
- combineLatest({
113
- computedData: observer.computedData$,
114
- fullParams: observer.fullParams$,
115
- fullChartParams: observer.fullChartParams$,
116
- highlightTarget: highlightTarget$
117
- }).pipe(
118
- takeUntil(destroy$),
119
- // 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
120
- switchMap(async (d) => d),
121
- ).subscribe(data => {
122
-
123
- graphicSelection
124
- .transition()
125
- .duration(data.fullChartParams.transitionDuration!)
126
- .ease(getD3TransitionEase(data.fullChartParams.transitionEase!))
127
- .tween('move', (event, datum) => {
128
- return (t) => {
129
- const renderData = makeTextData({
130
- eventData: {
131
- type: 'series',
132
- pluginName: name,
133
- eventName: 'transitionMove',
134
- event,
135
- highlightTarget: data.highlightTarget,
136
- data: data.computedData,
137
- series: [],
138
- seriesIndex: -1,
139
- seriesLabel: '',
140
- datum: null
141
- },
142
- eventName: 'transitionMove',
143
- t,
144
- eventFn: data.fullParams.eventFn!,
145
- textAttrs: data.fullParams.textAttrs!,
146
- textStyles: data.fullParams.textStyles!
147
- })
148
- centerTextSelection = renderText(graphicSelection, renderData)
149
- }
150
- })
151
- .on('end', (event, datum) => {
152
- const renderData = makeTextData({
153
- eventData: {
154
- type: 'series',
155
- pluginName: name,
156
- eventName: 'transitionEnd',
157
- event,
158
- highlightTarget: data.highlightTarget,
159
- data: data.computedData,
160
- series: [],
161
- seriesIndex: -1,
162
- seriesLabel: '',
163
- datum: null
164
- },
165
- eventName: 'transitionMove',
166
- t: 1,
167
- eventFn: data.fullParams.eventFn!,
168
- textAttrs: data.fullParams.textAttrs!,
169
- textStyles: data.fullParams.textStyles!
170
- })
171
- centerTextSelection = renderText(graphicSelection, renderData)
172
-
173
- if (storeEventSubscription) {
174
- storeEventSubscription.unsubscribe()
175
- }
176
- storeEventSubscription = subject.event$
177
- .subscribe(eventData => {
178
- const renderData = makeTextData({
179
- eventData,
180
- eventName: eventData.eventName,
181
- t: 1,
182
- eventFn: data.fullParams.eventFn!,
183
- textAttrs: data.fullParams.textAttrs!,
184
- textStyles: data.fullParams.textStyles!
185
- })
186
- centerTextSelection = renderText(graphicSelection, renderData)
187
- })
188
- })
189
- })
190
-
191
- return () => {
192
- destroy$.next(undefined)
193
- }
194
- })
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 { Subscription } from 'rxjs'
12
+ import {
13
+ defineSeriesPlugin} from '@orbcharts/core'
14
+ import type {
15
+ ComputedDatumSeries,
16
+ ChartParams,
17
+ SeriesContainerPosition,
18
+ EventName,
19
+ EventSeries } from '@orbcharts/core'
20
+ import type { PieEventTextsParams } from '../types'
21
+ import { DEFAULT_PIE_EVENT_TEXTS_PARAMS } from '../defaults'
22
+ import { getD3TransitionEase } from '../../utils/d3Utils'
23
+ import { getClassName } from '../../utils/orbchartsUtils'
24
+ import { seriesCenterSelectionObservable } from '../seriesObservables'
25
+
26
+
27
+ type TextDatum = {
28
+ text: string
29
+ attr: { [key:string]: any }
30
+ style: { [key:string]: any }
31
+ }
32
+
33
+ const pluginName = 'PieEventTexts'
34
+ const textClassName = getClassName(pluginName, 'text')
35
+
36
+ function renderText (
37
+ selection: d3.Selection<SVGGElement, unknown, any, any>,
38
+ data: Array<TextDatum>
39
+ ): d3.Selection<SVGTextElement, TextDatum, SVGGElement, unknown> {
40
+ const textUpdate = selection
41
+ .selectAll<SVGTextElement, TextDatum>(`text.${textClassName}`)
42
+ .data(data)
43
+ const textEnter = textUpdate.enter()
44
+ .append('text')
45
+ .classed(textClassName, true)
46
+ const text = textUpdate.merge(textEnter)
47
+ text
48
+ .each((d, i, g) => {
49
+ const t = d3.select(g[i])
50
+ .text(d.text)
51
+ Object.keys(d.attr)
52
+ .forEach(key => {
53
+ t.attr(key, d.attr[key])
54
+ })
55
+ Object.keys(d.style)
56
+ .forEach(key => {
57
+ t.style(key, d.style[key])
58
+ })
59
+ })
60
+
61
+ textUpdate.exit().remove()
62
+
63
+ return text
64
+ }
65
+
66
+ function makeTextData ({ eventData, eventName, t, eventFn, textAttrs, textStyles }: {
67
+ eventData: EventSeries,
68
+ eventName: EventName,
69
+ t: number,
70
+ eventFn: (d: EventSeries, eventName: EventName, t: number) => string[]
71
+ textAttrs: Array<{ [key:string]: string | number }>
72
+ textStyles: Array<{ [key:string]: string | number }>
73
+ }): TextDatum[] {
74
+ const callbackText = eventFn(eventData, eventName, t)
75
+ return callbackText.map((d, i) => {
76
+ return {
77
+ text: d,
78
+ attr: textAttrs[i],
79
+ style: textStyles[i]
80
+ }
81
+ })
82
+ }
83
+
84
+ function createEachPieEventTexts (pluginName: string, context: {
85
+ containerSelection: d3.Selection<SVGGElement, any, any, unknown>
86
+ computedData$: Observable<ComputedDatumSeries[][]>
87
+ containerComputedLayoutData$: Observable<ComputedDatumSeries[]>
88
+ SeriesDataMap$: Observable<Map<string, ComputedDatumSeries[]>>
89
+ fullParams$: Observable<PieEventTextsParams>
90
+ fullChartParams$: Observable<ChartParams>
91
+ seriesHighlight$: Observable<ComputedDatumSeries[]>
92
+ seriesContainerPosition$: Observable<SeriesContainerPosition>
93
+ event$: Subject<EventSeries>
94
+ }) {
95
+ const destroy$ = new Subject()
96
+
97
+ // const graphicSelection: d3.Selection<SVGGElement, any, any, any> = selection.append('g')
98
+ let centerTextSelection: d3.Selection<SVGTextElement, TextDatum, SVGGElement, unknown> | undefined
99
+ let storeEventSubscription: Subscription | undefined
100
+
101
+ // context.layout$
102
+ // .pipe(
103
+ // first()
104
+ // )
105
+ // .subscribe(size => {
106
+ // selection
107
+ // .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
108
+ // context.layout$
109
+ // .pipe(
110
+ // takeUntil(destroy$)
111
+ // )
112
+ // .subscribe(size => {
113
+ // selection
114
+ // .transition()
115
+ // .attr('transform', `translate(${size.width / 2}, ${size.height / 2})`)
116
+ // })
117
+ // })
118
+
119
+ const highlightTarget$ = context.fullChartParams$.pipe(
120
+ takeUntil(destroy$),
121
+ map(d => d.highlightTarget),
122
+ distinctUntilChanged()
123
+ )
124
+
125
+ combineLatest({
126
+ computedData: context.computedData$,
127
+ fullParams: context.fullParams$,
128
+ fullChartParams: context.fullChartParams$,
129
+ highlightTarget: highlightTarget$,
130
+ }).pipe(
131
+ takeUntil(destroy$),
132
+ switchMap(async (d) => d),
133
+ ).subscribe(data => {
134
+
135
+ context.containerSelection
136
+ .transition('move')
137
+ .duration(data.fullChartParams.transitionDuration!)
138
+ // .ease(getD3TransitionEase(data.fullChartParams.transitionEase!))
139
+ .tween('move', (event, datum) => {
140
+ return (t) => {
141
+ const renderData = makeTextData({
142
+ eventData: {
143
+ type: 'series',
144
+ pluginName,
145
+ eventName: 'transitionMove',
146
+ event,
147
+ highlightTarget: data.highlightTarget,
148
+ data: data.computedData,
149
+ series: [],
150
+ seriesIndex: -1,
151
+ seriesLabel: '',
152
+ datum: null
153
+ },
154
+ eventName: 'transitionMove',
155
+ t,
156
+ eventFn: data.fullParams.eventFn!,
157
+ textAttrs: data.fullParams.textAttrs!,
158
+ textStyles: data.fullParams.textStyles!
159
+ })
160
+ centerTextSelection = renderText(context.containerSelection, renderData)
161
+ }
162
+ })
163
+ .on('end', (event, datum) => {
164
+ const renderData = makeTextData({
165
+ eventData: {
166
+ type: 'series',
167
+ pluginName,
168
+ eventName: 'transitionEnd',
169
+ event,
170
+ highlightTarget: data.highlightTarget,
171
+ data: data.computedData,
172
+ series: [],
173
+ seriesIndex: -1,
174
+ seriesLabel: '',
175
+ datum: null
176
+ },
177
+ eventName: 'transitionMove',
178
+ t: 1,
179
+ eventFn: data.fullParams.eventFn!,
180
+ textAttrs: data.fullParams.textAttrs!,
181
+ textStyles: data.fullParams.textStyles!
182
+ })
183
+ centerTextSelection = renderText(context.containerSelection, renderData)
184
+
185
+ if (storeEventSubscription) {
186
+ storeEventSubscription.unsubscribe()
187
+ }
188
+ storeEventSubscription = context.event$
189
+ .subscribe(eventData => {
190
+ const renderData = makeTextData({
191
+ eventData,
192
+ eventName: eventData.eventName,
193
+ t: 1,
194
+ eventFn: data.fullParams.eventFn!,
195
+ textAttrs: data.fullParams.textAttrs!,
196
+ textStyles: data.fullParams.textStyles!
197
+ })
198
+ centerTextSelection = renderText(context.containerSelection, renderData)
199
+ })
200
+ })
201
+ })
202
+
203
+ return () => {
204
+ destroy$.next(undefined)
205
+ }
206
+ }
207
+
208
+ export const PieEventTexts = defineSeriesPlugin(pluginName, DEFAULT_PIE_EVENT_TEXTS_PARAMS)(({ selection, name, observer, subject }) => {
209
+ const destroy$ = new Subject()
210
+
211
+ const { seriesCenterSelection$ } = seriesCenterSelectionObservable({
212
+ selection: selection,
213
+ pluginName,
214
+ seriesSeparate$: observer.seriesSeparate$,
215
+ seriesLabels$: observer.seriesLabels$,
216
+ seriesContainerPosition$: observer.seriesContainerPosition$
217
+ })
218
+
219
+ const unsubscribeFnArr: (() => void)[] = []
220
+
221
+ seriesCenterSelection$.subscribe(seriesCenterSelection => {
222
+ // 每次重新計算時,清除之前的訂閱
223
+ unsubscribeFnArr.forEach(fn => fn())
224
+
225
+ seriesCenterSelection.each((d, containerIndex, g) => {
226
+
227
+ const containerSelection = d3.select(g[containerIndex])
228
+
229
+ const containerComputedLayoutData$ = observer.computedLayoutData$.pipe(
230
+ takeUntil(destroy$),
231
+ map(data => data[containerIndex] ?? data[0])
232
+ )
233
+
234
+ const containerPosition$ = observer.seriesContainerPosition$.pipe(
235
+ takeUntil(destroy$),
236
+ map(data => data[containerIndex] ?? data[0])
237
+ )
238
+
239
+ unsubscribeFnArr[containerIndex] = createEachPieEventTexts(pluginName, {
240
+ containerSelection: containerSelection,
241
+ computedData$: observer.computedData$,
242
+ containerComputedLayoutData$: containerComputedLayoutData$,
243
+ SeriesDataMap$: observer.SeriesDataMap$,
244
+ fullParams$: observer.fullParams$,
245
+ fullChartParams$: observer.fullChartParams$,
246
+ seriesHighlight$: observer.seriesHighlight$,
247
+ seriesContainerPosition$: containerPosition$,
248
+ event$: subject.event$,
249
+ })
250
+
251
+ })
252
+ })
253
+
254
+ return () => {
255
+ destroy$.next(undefined)
256
+ unsubscribeFnArr.forEach(fn => fn())
257
+ }
258
+ })