@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,640 +1,503 @@
1
- import * as d3 from 'd3'
2
- import {
3
- combineLatest,
4
- map,
5
- switchMap,
6
- takeUntil,
7
- distinctUntilChanged,
8
- Observable,
9
- Subject } from 'rxjs'
10
- import type { BasePluginFn } from './types'
11
- import type {
12
- ComputedDatumGrid,
13
- ComputedDataGrid,
14
- EventGrid,
15
- ChartParams,
16
- ContainerPosition,
17
- Layout,
18
- TransformData,
19
- ColorType } from '@orbcharts/core'
20
- import { getDatumColor, getClassName, getUniID } from '../utils/orbchartsUtils'
21
- import { gridSelectionsObservable } from '../grid/gridObservables'
22
-
23
- export interface BaseDotsParams {
24
- radius: number
25
- fillColorType: ColorType
26
- strokeColorType: ColorType
27
- strokeWidth: number
28
- onlyShowHighlighted: boolean
29
- }
30
-
31
- interface BaseDotsContext {
32
- selection: d3.Selection<any, unknown, any, unknown>
33
- computedData$: Observable<ComputedDataGrid>
34
- visibleComputedData$: Observable<ComputedDatumGrid[][]>
35
- existSeriesLabels$: Observable<string[]>
36
- SeriesDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
37
- GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
38
- fullParams$: Observable<BaseDotsParams>
39
- fullChartParams$: Observable<ChartParams>
40
- gridAxesTransform$: Observable<TransformData>
41
- gridGraphicTransform$: Observable<TransformData>
42
- gridGraphicReverseScale$: Observable<[number, number][]>
43
- gridAxesSize$: Observable<{
44
- width: number;
45
- height: number;
46
- }>
47
- gridHighlight$: Observable<ComputedDatumGrid[]>
48
- gridContainer$: Observable<ContainerPosition[]>
49
- event$: Subject<EventGrid>
50
- }
51
-
52
-
53
- type ClipPathDatum = {
54
- id: string;
55
- // x: number;
56
- // y: number;
57
- width: number;
58
- height: number;
59
- }
60
-
61
- // const pluginName = 'Dots'
62
- // const circleGClassName = getClassName(pluginName, 'circleG')
63
- // const circleClassName = getClassName(pluginName, 'circle')
64
-
65
- function renderDots ({ graphicGSelection, circleGClassName, circleClassName, data, fullParams, fullChartParams, graphicReverseScale }: {
66
- graphicGSelection: d3.Selection<SVGGElement, any, any, any>
67
- circleGClassName: string
68
- circleClassName: string
69
- data: ComputedDatumGrid[][]
70
- fullParams: BaseDotsParams
71
- fullChartParams: ChartParams
72
- graphicReverseScale: [number, number][]
73
- }) {
74
- const createEnterDuration = (enter: d3.Selection<d3.EnterElement, ComputedDatumGrid, SVGGElement, any>) => {
75
- const enterSize = enter.size()
76
- const eachDuration = fullChartParams.transitionDuration / enterSize
77
- return eachDuration
78
- }
79
- // enterDuration
80
- let enterDuration = 0
81
-
82
- graphicGSelection
83
- .each((seriesData, seriesIndex, g) => {
84
- d3.select(g[seriesIndex])
85
- .selectAll<SVGGElement, ComputedDatumGrid>('g')
86
- .data(data[seriesIndex], d => d.id)
87
- .join(
88
- enter => {
89
- // enterDuration
90
- enterDuration = createEnterDuration(enter)
91
-
92
- return enter
93
- .append('g')
94
- .classed(circleGClassName, true)
95
- },
96
- update => update,
97
- exit => exit.remove()
98
- )
99
- .attr('transform', d => `translate(${d.axisX}, ${d.axisY})`)
100
- .each((d, i, g) => {
101
- const circle = d3.select(g[i])
102
- .selectAll('circle')
103
- .data([d])
104
- .join(
105
- enter => {
106
- return enter
107
- .append('circle')
108
- .style('cursor', 'pointer')
109
- .style('vector-effect', 'non-scaling-stroke')
110
- .classed(circleClassName, true)
111
- .attr('opacity', 0)
112
- .transition()
113
- .delay((_d, _i) => {
114
- return i * enterDuration
115
- })
116
- .attr('opacity', 1)
117
- },
118
- update => {
119
- return update
120
- .transition()
121
- .duration(50)
122
- // .attr('cx', d => d.axisX)
123
- // .attr('cy', d => d.axisY)
124
- .attr('opacity', 1)
125
- },
126
- exit => exit.remove()
127
- )
128
- .attr('r', fullParams.radius)
129
- .attr('fill', (d, i) => getDatumColor({ datum: d, colorType: fullParams.fillColorType, fullChartParams }))
130
- .attr('stroke', (d, i) => getDatumColor({ datum: d, colorType: fullParams.strokeColorType, fullChartParams }))
131
- .attr('stroke-width', fullParams.strokeWidth)
132
- .attr('transform', `scale(${graphicReverseScale[seriesIndex][0] ?? 1}, ${graphicReverseScale[seriesIndex][1] ?? 1})`)
133
- })
134
- })
135
-
136
- // const dots = graphicGSelection
137
- // .selectAll<SVGGElement, ComputedDatumGrid>('g')
138
- // .data(data, d => d.id)
139
- // .join(
140
- // enter => {
141
- // // enterDuration
142
- // enterDuration = createEnterDuration(enter)
143
-
144
- // return enter
145
- // .append('g')
146
- // .classed(circleGClassName, true)
147
- // },
148
- // update => update,
149
- // exit => exit.remove()
150
- // )
151
- // .attr('transform', d => `translate(${d.axisX}, ${d.axisY})`)
152
- // .each((d, i, g) => {
153
- // const circle = d3.select(g[i])
154
- // .selectAll('circle')
155
- // .data([d])
156
- // .join(
157
- // enter => {
158
- // return enter
159
- // .append('circle')
160
- // .style('cursor', 'pointer')
161
- // .style('vector-effect', 'non-scaling-stroke')
162
- // .classed(circleClassName, true)
163
- // .attr('opacity', 0)
164
- // .transition()
165
- // .delay((_d, _i) => {
166
- // return i * enterDuration
167
- // })
168
- // .attr('opacity', 1)
169
- // },
170
- // update => {
171
- // return update
172
- // .transition()
173
- // .duration(50)
174
- // // .attr('cx', d => d.axisX)
175
- // // .attr('cy', d => d.axisY)
176
- // .attr('opacity', 1)
177
- // },
178
- // exit => exit.remove()
179
- // )
180
- // .attr('r', fullParams.radius)
181
- // .attr('fill', (d, i) => getDatumColor({ datum: d, colorType: fullParams.fillColorType, fullChartParams }))
182
- // .attr('stroke', (d, i) => getDatumColor({ datum: d, colorType: fullParams.strokeColorType, fullChartParams }))
183
- // .attr('stroke-width', fullParams.strokeWidth)
184
- // .attr('transform', `scale(${graphicReverseScale[0]}, ${graphicReverseScale[1]})`)
185
- // })
186
-
187
- const graphicCircleSelection: d3.Selection<SVGRectElement, ComputedDatumGrid, SVGGElement, unknown> = graphicGSelection.selectAll(`circle.${circleClassName}`)
188
-
189
- return graphicCircleSelection
190
- }
191
-
192
-
193
- function highlightDots ({ selection, ids, onlyShowHighlighted, fullChartParams }: {
194
- selection: d3.Selection<SVGGElement, ComputedDatumGrid, any, any>
195
- ids: string[]
196
- onlyShowHighlighted: boolean
197
- fullChartParams: ChartParams
198
- }) {
199
- selection.interrupt('highlight')
200
- if (!ids.length) {
201
- // remove highlight
202
- selection
203
- .transition('highlight')
204
- .duration(200)
205
- .style('opacity', onlyShowHighlighted === true ? 0 : 1)
206
- return
207
- }
208
-
209
- selection
210
- .each((d, i, n) => {
211
- if (ids.includes(d.id)) {
212
- d3.select(n[i])
213
- .style('opacity', 1)
214
- .transition('highlight')
215
- .duration(200)
216
- } else {
217
- d3.select(n[i])
218
- .style('opacity', onlyShowHighlighted === true ? 0 : fullChartParams.styles.unhighlightedOpacity)
219
- .transition('highlight')
220
- .duration(200)
221
- }
222
- })
223
- }
224
-
225
- function renderClipPath ({ defsSelection, clipPathData }: {
226
- defsSelection: d3.Selection<SVGDefsElement, any, any, any>
227
- clipPathData: ClipPathDatum[]
228
- }) {
229
- const clipPath = defsSelection
230
- .selectAll<SVGClipPathElement, Layout>('clipPath')
231
- .data(clipPathData)
232
- .join(
233
- enter => {
234
- return enter
235
- .append('clipPath')
236
- },
237
- update => update,
238
- exit => exit.remove()
239
- )
240
- .attr('id', d => d.id)
241
- .each((d, i, g) => {
242
- const rect = d3.select(g[i])
243
- .selectAll<SVGRectElement, typeof d>('rect')
244
- .data([d])
245
- .join('rect')
246
- .attr('x', 0)
247
- .attr('y', 0)
248
- .attr('width', _d => _d.width)
249
- .attr('height', _d => _d.height)
250
- })
251
-
252
- }
253
-
254
-
255
-
256
- export const createBaseDots: BasePluginFn<BaseDotsContext> = (pluginName: string, {
257
- selection,
258
- computedData$,
259
- visibleComputedData$,
260
- existSeriesLabels$,
261
- SeriesDataMap$,
262
- GroupDataMap$,
263
- fullParams$,
264
- fullChartParams$,
265
- gridAxesTransform$,
266
- gridGraphicTransform$,
267
- gridGraphicReverseScale$,
268
- gridAxesSize$,
269
- gridHighlight$,
270
- gridContainer$,
271
- event$
272
- }) => {
273
-
274
- const destroy$ = new Subject()
275
-
276
- const clipPathID = getUniID(pluginName, 'clipPath-box')
277
- const circleGClassName = getClassName(pluginName, 'circleG')
278
- const circleClassName = getClassName(pluginName, 'circle')
279
-
280
- // const axisSelection: d3.Selection<SVGGElement, any, any, any> = selection
281
- // .append('g')
282
- // .attr('clip-path', `url(#${clipPathID})`)
283
- // const defsSelection: d3.Selection<SVGDefsElement, any, any, any> = axisSelection.append('defs')
284
- // const dataAreaSelection: d3.Selection<SVGGElement, any, any, any> = axisSelection.append('g')
285
- const graphicSelection$: Subject<d3.Selection<SVGGElement, ComputedDatumGrid, any, any>> = new Subject()
286
-
287
- // gridAxesTransform$
288
- // .pipe(
289
- // takeUntil(destroy$),
290
- // map(d => d.value),
291
- // distinctUntilChanged()
292
- // ).subscribe(d => {
293
- // axisSelection
294
- // .style('transform', d)
295
- // })
296
-
297
- // gridGraphicTransform$
298
- // .pipe(
299
- // takeUntil(destroy$),
300
- // switchMap(async d => d.value),
301
- // distinctUntilChanged()
302
- // ).subscribe(d => {
303
- // dataAreaSelection
304
- // .transition()
305
- // .duration(50)
306
- // .style('transform', d)
307
- // })
308
-
309
- // const seriesSelection$ = computedData$.pipe(
310
- // takeUntil(destroy$),
311
- // distinctUntilChanged((a, b) => {
312
- // // 只有當series的數量改變時,才重新計算
313
- // return a.length === b.length
314
- // }),
315
- // map((computedData, i) => {
316
- // return selection
317
- // .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${seriesClassName}`)
318
- // .data(computedData, d => d[0] ? d[0].seriesIndex : i)
319
- // .join(
320
- // enter => {
321
- // return enter
322
- // .append('g')
323
- // .classed(seriesClassName, true)
324
- // .each((d, i, g) => {
325
- // const axesSelection = d3.select(g[i])
326
- // .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${axesClassName}`)
327
- // .data([i])
328
- // .join(
329
- // enter => {
330
- // return enter
331
- // .append('g')
332
- // .classed(axesClassName, true)
333
- // .attr('clip-path', `url(#${clipPathID})`)
334
- // .each((d, i, g) => {
335
- // const defsSelection = d3.select(g[i])
336
- // .selectAll<SVGDefsElement, any>('defs')
337
- // .data([i])
338
- // .join('defs')
339
-
340
- // const graphicGSelection = d3.select(g[i])
341
- // .selectAll<SVGGElement, any>('g')
342
- // .data([i])
343
- // .join('g')
344
- // .classed(graphicClassName, true)
345
- // })
346
- // },
347
- // update => update,
348
- // exit => exit.remove()
349
- // )
350
- // })
351
- // },
352
- // update => update,
353
- // exit => exit.remove()
354
- // )
355
- // })
356
- // )
357
-
358
- // combineLatest({
359
- // seriesSelection: seriesSelection$,
360
- // gridContainer: gridContainer$
361
- // }).pipe(
362
- // takeUntil(destroy$),
363
- // switchMap(async d => d)
364
- // ).subscribe(data => {
365
- // data.seriesSelection
366
- // .transition()
367
- // .attr('transform', (d, i) => {
368
- // const translate = data.gridContainer[i].translate
369
- // const scale = data.gridContainer[i].scale
370
- // return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
371
- // })
372
- // })
373
-
374
-
375
- // const axesSelection$ = combineLatest({
376
- // seriesSelection: seriesSelection$,
377
- // gridAxesTransform: gridAxesTransform$
378
- // }).pipe(
379
- // takeUntil(destroy$),
380
- // switchMap(async d => d),
381
- // map(data => {
382
- // return data.seriesSelection
383
- // .select<SVGGElement>(`g.${axesClassName}`)
384
- // .style('transform', data.gridAxesTransform.value)
385
- // })
386
- // )
387
- // const defsSelection$ = axesSelection$.pipe(
388
- // takeUntil(destroy$),
389
- // map(axesSelection => {
390
- // return axesSelection.select<SVGDefsElement>('defs')
391
- // })
392
- // )
393
- // const graphicGSelection$ = combineLatest({
394
- // axesSelection: axesSelection$,
395
- // gridGraphicTransform: gridGraphicTransform$
396
- // }).pipe(
397
- // takeUntil(destroy$),
398
- // switchMap(async d => d),
399
- // map(data => {
400
- // const graphicGSelection = data.axesSelection
401
- // .select<SVGGElement>(`g.${graphicClassName}`)
402
- // graphicGSelection
403
- // .transition()
404
- // .duration(50)
405
- // .style('transform', data.gridGraphicTransform.value)
406
- // return graphicGSelection
407
- // })
408
- // )
409
-
410
- const {
411
- seriesSelection$,
412
- axesSelection$,
413
- defsSelection$,
414
- graphicGSelection$
415
- } = gridSelectionsObservable({
416
- selection,
417
- pluginName,
418
- clipPathID,
419
- existSeriesLabels$,
420
- gridContainer$,
421
- gridAxesTransform$,
422
- gridGraphicTransform$
423
- })
424
-
425
- const graphicReverseScale$: Observable<[number, number][]> = combineLatest({
426
- // gridGraphicTransform: gridGraphicTransform$,
427
- // gridContainer: gridContainer$,
428
- // gridAxesTransform: gridAxesTransform$
429
- computedData: computedData$,
430
- gridGraphicReverseScale: gridGraphicReverseScale$
431
- }).pipe(
432
- takeUntil(destroy$),
433
- switchMap(async data => data),
434
- map(data => {
435
- return data.computedData.map((series, seriesIndex) => {
436
- return data.gridGraphicReverseScale[seriesIndex]
437
- })
438
- })
439
- )
440
-
441
- const clipPathSubscription = combineLatest({
442
- defsSelection: defsSelection$,
443
- gridAxesSize: gridAxesSize$,
444
- }).pipe(
445
- takeUntil(destroy$),
446
- switchMap(async (d) => d),
447
- ).subscribe(data => {
448
- // 外層的遮罩
449
- const clipPathData = [{
450
- id: clipPathID,
451
- width: data.gridAxesSize.width,
452
- height: data.gridAxesSize.height
453
- }]
454
- renderClipPath({
455
- defsSelection: data.defsSelection,
456
- clipPathData,
457
- })
458
- })
459
-
460
- // const visibleComputedData$ = computedData$.pipe(
461
- // map(computedData => {
462
- // return computedData
463
- // .map(d => {
464
- // return d.filter(_d => _d.visible == true)
465
- // })
466
- // })
467
- // )
468
-
469
- // const SeriesDataMap$ = visibleComputedData$.pipe(
470
- // map(d => makeGridSeriesDataMap(d))
471
- // )
472
-
473
- // const GroupDataMap$ = visibleComputedData$.pipe(
474
- // map(d => makeGridGroupDataMap(d))
475
- // )
476
-
477
- // const DataMap$ = computedData$.pipe(
478
- // map(d => {
479
- // const DataMap: Map<string, ComputedDatumGrid> = new Map()
480
- // d.flat().forEach(_d => DataMap.set(_d.id, _d))
481
- // return DataMap
482
- // })
483
- // )
484
-
485
- const highlightTarget$ = fullChartParams$.pipe(
486
- takeUntil(destroy$),
487
- map(d => d.highlightTarget),
488
- distinctUntilChanged()
489
- )
490
-
491
- combineLatest({
492
- graphicGSelection: graphicGSelection$,
493
- computedData: computedData$,
494
- visibleComputedData: visibleComputedData$,
495
- SeriesDataMap: SeriesDataMap$,
496
- GroupDataMap: GroupDataMap$,
497
- graphicReverseScale: graphicReverseScale$,
498
- fullChartParams: fullChartParams$,
499
- fullParams: fullParams$,
500
- highlightTarget: highlightTarget$
501
- }).pipe(
502
- takeUntil(destroy$),
503
- switchMap(async (d) => d),
504
- ).subscribe(data => {
505
-
506
- const graphicSelection = renderDots({
507
- graphicGSelection: data.graphicGSelection,
508
- circleGClassName,
509
- circleClassName,
510
- data: data.visibleComputedData,
511
- fullParams: data.fullParams,
512
- fullChartParams: data.fullChartParams,
513
- graphicReverseScale: data.graphicReverseScale
514
- })
515
-
516
- graphicSelection
517
- .on('mouseover', (event, datum) => {
518
- event.stopPropagation()
519
-
520
- event$.next({
521
- type: 'grid',
522
- eventName: 'mouseover',
523
- pluginName,
524
- highlightTarget: data.highlightTarget,
525
- datum,
526
- gridIndex: datum.gridIndex,
527
- series: data.SeriesDataMap.get(datum.seriesLabel)!,
528
- seriesIndex: datum.seriesIndex,
529
- seriesLabel: datum.seriesLabel,
530
- groups: data.GroupDataMap.get(datum.groupLabel)!,
531
- groupIndex: datum.groupIndex,
532
- groupLabel: datum.groupLabel,
533
- event,
534
- data: data.computedData
535
- })
536
- })
537
- .on('mousemove', (event, datum) => {
538
- event.stopPropagation()
539
-
540
- event$.next({
541
- type: 'grid',
542
- eventName: 'mousemove',
543
- pluginName,
544
- highlightTarget: data.highlightTarget,
545
- data: data.computedData,
546
- datum,
547
- gridIndex: datum.gridIndex,
548
- series: data.SeriesDataMap.get(datum.seriesLabel)!,
549
- seriesIndex: datum.seriesIndex,
550
- seriesLabel: datum.seriesLabel,
551
- groups: data.GroupDataMap.get(datum.groupLabel)!,
552
- groupIndex: datum.groupIndex,
553
- groupLabel: datum.groupLabel,
554
- event
555
- })
556
- })
557
- .on('mouseout', (event, datum) => {
558
- event.stopPropagation()
559
-
560
- event$.next({
561
- type: 'grid',
562
- eventName: 'mouseout',
563
- pluginName,
564
- highlightTarget: data.highlightTarget,
565
- datum,
566
- gridIndex: datum.gridIndex,
567
- series: data.SeriesDataMap.get(datum.seriesLabel)!,
568
- seriesIndex: datum.seriesIndex,
569
- seriesLabel: datum.seriesLabel,
570
- groups: data.GroupDataMap.get(datum.groupLabel)!,
571
- groupIndex: datum.groupIndex,
572
- groupLabel: datum.groupLabel,
573
- event,
574
- data: data.computedData
575
- })
576
- })
577
- .on('click', (event, datum) => {
578
- event.stopPropagation()
579
-
580
- event$.next({
581
- type: 'grid',
582
- eventName: 'click',
583
- pluginName,
584
- highlightTarget: data.highlightTarget,
585
- datum,
586
- gridIndex: datum.gridIndex,
587
- series: data.SeriesDataMap.get(datum.seriesLabel)!,
588
- seriesIndex: datum.seriesIndex,
589
- seriesLabel: datum.seriesLabel,
590
- groups: data.GroupDataMap.get(datum.groupLabel)!,
591
- groupIndex: datum.groupIndex,
592
- groupLabel: datum.groupLabel,
593
- event,
594
- data: data.computedData
595
- })
596
- })
597
-
598
- graphicSelection$.next(graphicSelection)
599
-
600
- })
601
-
602
- // const datumList$ = computedData$.pipe(
603
- // takeUntil(destroy$),
604
- // map(d => d.flat())
605
- // )
606
- // const highlight$ = highlightObservable({ datumList$, fullChartParams$, event$: store.event$ })
607
- // const highlightSubscription = gridHighlight$.subscribe()
608
- const onlyShowHighlighted$ = fullParams$.pipe(
609
- takeUntil(destroy$),
610
- map(d => d.onlyShowHighlighted),
611
- distinctUntilChanged()
612
- )
613
-
614
- fullChartParams$.pipe(
615
- takeUntil(destroy$),
616
- switchMap(d => combineLatest({
617
- graphicSelection: graphicSelection$,
618
- highlight: gridHighlight$.pipe(
619
- map(data => data.map(d => d.id))
620
- ),
621
- onlyShowHighlighted: onlyShowHighlighted$,
622
- fullChartParams: fullChartParams$
623
- }).pipe(
624
- takeUntil(destroy$),
625
- switchMap(async d => d)
626
- ))
627
- ).subscribe(data => {
628
- highlightDots({
629
- selection: data.graphicSelection,
630
- ids: data.highlight,
631
- onlyShowHighlighted: data.onlyShowHighlighted,
632
- fullChartParams: data.fullChartParams
633
- })
634
- })
635
-
636
- return () => {
637
- destroy$.next(undefined)
638
- // highlightSubscription.unsubscribe()
639
- }
1
+ import * as d3 from 'd3'
2
+ import {
3
+ combineLatest,
4
+ map,
5
+ switchMap,
6
+ takeUntil,
7
+ distinctUntilChanged,
8
+ Observable,
9
+ Subject } from 'rxjs'
10
+ import type { BasePluginFn } from './types'
11
+ import type {
12
+ ComputedDatumGrid,
13
+ ComputedDataGrid,
14
+ ComputedLayoutDataGrid,
15
+ EventGrid,
16
+ ChartParams,
17
+ GridContainerPosition,
18
+ Layout,
19
+ TransformData,
20
+ ColorType } from '@orbcharts/core'
21
+ import { getDatumColor, getClassName, getUniID } from '../utils/orbchartsUtils'
22
+ import { gridSelectionsObservable } from '../grid/gridObservables'
23
+
24
+ export interface BaseDotsParams {
25
+ radius: number
26
+ fillColorType: ColorType
27
+ strokeColorType: ColorType
28
+ strokeWidth: number
29
+ onlyShowHighlighted: boolean
30
+ }
31
+
32
+ interface BaseDotsContext {
33
+ selection: d3.Selection<any, unknown, any, unknown>
34
+ computedData$: Observable<ComputedDataGrid>
35
+ computedLayoutData$: Observable<ComputedLayoutDataGrid>
36
+ visibleComputedData$: Observable<ComputedDatumGrid[][]>
37
+ visibleComputedLayoutData$: Observable<ComputedLayoutDataGrid>
38
+ seriesLabels$: Observable<string[]>
39
+ SeriesDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
40
+ GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
41
+ fullParams$: Observable<BaseDotsParams>
42
+ fullChartParams$: Observable<ChartParams>
43
+ gridAxesTransform$: Observable<TransformData>
44
+ gridGraphicTransform$: Observable<TransformData>
45
+ gridGraphicReverseScale$: Observable<[number, number][]>
46
+ gridAxesSize$: Observable<{
47
+ width: number;
48
+ height: number;
49
+ }>
50
+ gridHighlight$: Observable<ComputedDatumGrid[]>
51
+ gridContainerPosition$: Observable<GridContainerPosition[]>
52
+ event$: Subject<EventGrid>
53
+ }
54
+
55
+
56
+ type ClipPathDatum = {
57
+ id: string;
58
+ // x: number;
59
+ // y: number;
60
+ width: number;
61
+ height: number;
62
+ }
63
+
64
+ // const pluginName = 'Dots'
65
+ // const circleGClassName = getClassName(pluginName, 'circleG')
66
+ // const circleClassName = getClassName(pluginName, 'circle')
67
+
68
+ function renderDots ({ graphicGSelection, circleGClassName, circleClassName, visibleComputedLayoutData, fullParams, fullChartParams, graphicReverseScale }: {
69
+ graphicGSelection: d3.Selection<SVGGElement, any, any, any>
70
+ circleGClassName: string
71
+ circleClassName: string
72
+ visibleComputedLayoutData: ComputedLayoutDataGrid
73
+ fullParams: BaseDotsParams
74
+ fullChartParams: ChartParams
75
+ graphicReverseScale: [number, number][]
76
+ }) {
77
+ const createEnterDuration = (enter: d3.Selection<d3.EnterElement, ComputedDatumGrid, SVGGElement, any>) => {
78
+ const enterSize = enter.size()
79
+ const eachDuration = fullChartParams.transitionDuration / enterSize
80
+ return eachDuration
81
+ }
82
+ // enterDuration
83
+ let enterDuration = 0
84
+
85
+ graphicGSelection
86
+ .each((seriesData, seriesIndex, g) => {
87
+ d3.select(g[seriesIndex])
88
+ .selectAll<SVGGElement, ComputedDatumGrid>('g')
89
+ .data(visibleComputedLayoutData[seriesIndex], d => d.id)
90
+ .join(
91
+ enter => {
92
+ // enterDuration
93
+ enterDuration = createEnterDuration(enter)
94
+
95
+ return enter
96
+ .append('g')
97
+ .classed(circleGClassName, true)
98
+ },
99
+ update => update,
100
+ exit => exit.remove()
101
+ )
102
+ .attr('transform', d => `translate(${d.axisX}, ${d.axisY})`)
103
+ .each((d, i, g) => {
104
+ const circle = d3.select(g[i])
105
+ .selectAll('circle')
106
+ .data([d])
107
+ .join(
108
+ enter => {
109
+ return enter
110
+ .append('circle')
111
+ .style('cursor', 'pointer')
112
+ .style('vector-effect', 'non-scaling-stroke')
113
+ .classed(circleClassName, true)
114
+ .attr('opacity', 0)
115
+ .transition()
116
+ .delay((_d, _i) => {
117
+ return i * enterDuration
118
+ })
119
+ .attr('opacity', 1)
120
+ },
121
+ update => {
122
+ return update
123
+ .transition()
124
+ .duration(50)
125
+ // .attr('cx', d => d.axisX)
126
+ // .attr('cy', d => d.axisY)
127
+ .attr('opacity', 1)
128
+ },
129
+ exit => exit.remove()
130
+ )
131
+ .attr('r', fullParams.radius)
132
+ .attr('fill', (d, i) => getDatumColor({ datum: d, colorType: fullParams.fillColorType, fullChartParams }))
133
+ .attr('stroke', (d, i) => getDatumColor({ datum: d, colorType: fullParams.strokeColorType, fullChartParams }))
134
+ .attr('stroke-width', fullParams.strokeWidth)
135
+ .attr('transform', `scale(${graphicReverseScale[seriesIndex][0] ?? 1}, ${graphicReverseScale[seriesIndex][1] ?? 1})`)
136
+ })
137
+ })
138
+
139
+ // const dots = graphicGSelection
140
+ // .selectAll<SVGGElement, ComputedDatumGrid>('g')
141
+ // .data(data, d => d.id)
142
+ // .join(
143
+ // enter => {
144
+ // // enterDuration
145
+ // enterDuration = createEnterDuration(enter)
146
+
147
+ // return enter
148
+ // .append('g')
149
+ // .classed(circleGClassName, true)
150
+ // },
151
+ // update => update,
152
+ // exit => exit.remove()
153
+ // )
154
+ // .attr('transform', d => `translate(${d.axisX}, ${d.axisY})`)
155
+ // .each((d, i, g) => {
156
+ // const circle = d3.select(g[i])
157
+ // .selectAll('circle')
158
+ // .data([d])
159
+ // .join(
160
+ // enter => {
161
+ // return enter
162
+ // .append('circle')
163
+ // .style('cursor', 'pointer')
164
+ // .style('vector-effect', 'non-scaling-stroke')
165
+ // .classed(circleClassName, true)
166
+ // .attr('opacity', 0)
167
+ // .transition()
168
+ // .delay((_d, _i) => {
169
+ // return i * enterDuration
170
+ // })
171
+ // .attr('opacity', 1)
172
+ // },
173
+ // update => {
174
+ // return update
175
+ // .transition()
176
+ // .duration(50)
177
+ // // .attr('cx', d => d.axisX)
178
+ // // .attr('cy', d => d.axisY)
179
+ // .attr('opacity', 1)
180
+ // },
181
+ // exit => exit.remove()
182
+ // )
183
+ // .attr('r', fullParams.radius)
184
+ // .attr('fill', (d, i) => getDatumColor({ datum: d, colorType: fullParams.fillColorType, fullChartParams }))
185
+ // .attr('stroke', (d, i) => getDatumColor({ datum: d, colorType: fullParams.strokeColorType, fullChartParams }))
186
+ // .attr('stroke-width', fullParams.strokeWidth)
187
+ // .attr('transform', `scale(${graphicReverseScale[0]}, ${graphicReverseScale[1]})`)
188
+ // })
189
+
190
+ const graphicCircleSelection: d3.Selection<SVGRectElement, ComputedDatumGrid, SVGGElement, unknown> = graphicGSelection.selectAll(`circle.${circleClassName}`)
191
+
192
+ return graphicCircleSelection
193
+ }
194
+
195
+
196
+ function highlightDots ({ selection, ids, onlyShowHighlighted, fullChartParams }: {
197
+ selection: d3.Selection<SVGGElement, ComputedDatumGrid, any, any>
198
+ ids: string[]
199
+ onlyShowHighlighted: boolean
200
+ fullChartParams: ChartParams
201
+ }) {
202
+ selection.interrupt('highlight')
203
+ if (!ids.length) {
204
+ // remove highlight
205
+ selection
206
+ .transition('highlight')
207
+ .duration(200)
208
+ .style('opacity', onlyShowHighlighted === true ? 0 : 1)
209
+ return
210
+ }
211
+
212
+ selection
213
+ .each((d, i, n) => {
214
+ if (ids.includes(d.id)) {
215
+ d3.select(n[i])
216
+ .style('opacity', 1)
217
+ .transition('highlight')
218
+ .duration(200)
219
+ } else {
220
+ d3.select(n[i])
221
+ .style('opacity', onlyShowHighlighted === true ? 0 : fullChartParams.styles.unhighlightedOpacity)
222
+ .transition('highlight')
223
+ .duration(200)
224
+ }
225
+ })
226
+ }
227
+
228
+ function renderClipPath ({ defsSelection, clipPathData }: {
229
+ defsSelection: d3.Selection<SVGDefsElement, any, any, any>
230
+ clipPathData: ClipPathDatum[]
231
+ }) {
232
+ const clipPath = defsSelection
233
+ .selectAll<SVGClipPathElement, Layout>('clipPath')
234
+ .data(clipPathData)
235
+ .join(
236
+ enter => {
237
+ return enter
238
+ .append('clipPath')
239
+ },
240
+ update => update,
241
+ exit => exit.remove()
242
+ )
243
+ .attr('id', d => d.id)
244
+ .each((d, i, g) => {
245
+ const rect = d3.select(g[i])
246
+ .selectAll<SVGRectElement, typeof d>('rect')
247
+ .data([d])
248
+ .join('rect')
249
+ .attr('x', 0)
250
+ .attr('y', 0)
251
+ .attr('width', _d => _d.width)
252
+ .attr('height', _d => _d.height)
253
+ })
254
+
255
+ }
256
+
257
+
258
+
259
+ export const createBaseDots: BasePluginFn<BaseDotsContext> = (pluginName: string, {
260
+ selection,
261
+ computedData$,
262
+ computedLayoutData$,
263
+ visibleComputedData$,
264
+ visibleComputedLayoutData$,
265
+ seriesLabels$,
266
+ SeriesDataMap$,
267
+ GroupDataMap$,
268
+ fullParams$,
269
+ fullChartParams$,
270
+ gridAxesTransform$,
271
+ gridGraphicTransform$,
272
+ gridGraphicReverseScale$,
273
+ gridAxesSize$,
274
+ gridHighlight$,
275
+ gridContainerPosition$,
276
+ event$
277
+ }) => {
278
+
279
+ const destroy$ = new Subject()
280
+
281
+ const clipPathID = getUniID(pluginName, 'clipPath-box')
282
+ const circleGClassName = getClassName(pluginName, 'circleG')
283
+ const circleClassName = getClassName(pluginName, 'circle')
284
+
285
+ // const axisSelection: d3.Selection<SVGGElement, any, any, any> = selection
286
+ // .append('g')
287
+ // .attr('clip-path', `url(#${clipPathID})`)
288
+ // const defsSelection: d3.Selection<SVGDefsElement, any, any, any> = axisSelection.append('defs')
289
+ // const dataAreaSelection: d3.Selection<SVGGElement, any, any, any> = axisSelection.append('g')
290
+ // const graphicSelection$: Subject<d3.Selection<SVGGElement, ComputedDatumGrid, any, any>> = new Subject()
291
+
292
+ const {
293
+ seriesSelection$,
294
+ axesSelection$,
295
+ defsSelection$,
296
+ graphicGSelection$
297
+ } = gridSelectionsObservable({
298
+ selection,
299
+ pluginName,
300
+ clipPathID,
301
+ seriesLabels$,
302
+ gridContainerPosition$,
303
+ gridAxesTransform$,
304
+ gridGraphicTransform$
305
+ })
306
+
307
+ const graphicReverseScale$: Observable<[number, number][]> = combineLatest({
308
+ // gridGraphicTransform: gridGraphicTransform$,
309
+ // gridContainerPosition: gridContainerPosition$,
310
+ // gridAxesTransform: gridAxesTransform$
311
+ computedData: computedData$,
312
+ gridGraphicReverseScale: gridGraphicReverseScale$
313
+ }).pipe(
314
+ takeUntil(destroy$),
315
+ switchMap(async data => data),
316
+ map(data => {
317
+ return data.computedData.map((series, seriesIndex) => {
318
+ return data.gridGraphicReverseScale[seriesIndex]
319
+ })
320
+ })
321
+ )
322
+
323
+ const clipPathSubscription = combineLatest({
324
+ defsSelection: defsSelection$,
325
+ gridAxesSize: gridAxesSize$,
326
+ }).pipe(
327
+ takeUntil(destroy$),
328
+ switchMap(async (d) => d),
329
+ ).subscribe(data => {
330
+ // 外層的遮罩
331
+ const clipPathData = [{
332
+ id: clipPathID,
333
+ width: data.gridAxesSize.width,
334
+ height: data.gridAxesSize.height
335
+ }]
336
+ renderClipPath({
337
+ defsSelection: data.defsSelection,
338
+ clipPathData,
339
+ })
340
+ })
341
+
342
+ const highlightTarget$ = fullChartParams$.pipe(
343
+ takeUntil(destroy$),
344
+ map(d => d.highlightTarget),
345
+ distinctUntilChanged()
346
+ )
347
+
348
+ const graphicSelection$ = combineLatest({
349
+ graphicGSelection: graphicGSelection$,
350
+ visibleComputedLayoutData: visibleComputedLayoutData$,
351
+ graphicReverseScale: graphicReverseScale$,
352
+ fullChartParams: fullChartParams$,
353
+ fullParams: fullParams$,
354
+ }).pipe(
355
+ takeUntil(destroy$),
356
+ switchMap(async (d) => d),
357
+ map(data => {
358
+ return renderDots({
359
+ graphicGSelection: data.graphicGSelection,
360
+ circleGClassName,
361
+ circleClassName,
362
+ visibleComputedLayoutData: data.visibleComputedLayoutData,
363
+ fullParams: data.fullParams,
364
+ fullChartParams: data.fullChartParams,
365
+ graphicReverseScale: data.graphicReverseScale
366
+ })
367
+ })
368
+ )
369
+
370
+ combineLatest({
371
+ graphicSelection: graphicSelection$,
372
+ computedData: computedData$,
373
+ SeriesDataMap: SeriesDataMap$,
374
+ GroupDataMap: GroupDataMap$,
375
+ highlightTarget: highlightTarget$
376
+ }).pipe(
377
+ takeUntil(destroy$),
378
+ switchMap(async (d) => d),
379
+ ).subscribe(data => {
380
+
381
+ data.graphicSelection
382
+ .on('mouseover', (event, datum) => {
383
+ event.stopPropagation()
384
+
385
+ event$.next({
386
+ type: 'grid',
387
+ eventName: 'mouseover',
388
+ pluginName,
389
+ highlightTarget: data.highlightTarget,
390
+ datum,
391
+ gridIndex: datum.gridIndex,
392
+ series: data.SeriesDataMap.get(datum.seriesLabel)!,
393
+ seriesIndex: datum.seriesIndex,
394
+ seriesLabel: datum.seriesLabel,
395
+ groups: data.GroupDataMap.get(datum.groupLabel)!,
396
+ groupIndex: datum.groupIndex,
397
+ groupLabel: datum.groupLabel,
398
+ event,
399
+ data: data.computedData
400
+ })
401
+ })
402
+ .on('mousemove', (event, datum) => {
403
+ event.stopPropagation()
404
+
405
+ event$.next({
406
+ type: 'grid',
407
+ eventName: 'mousemove',
408
+ pluginName,
409
+ highlightTarget: data.highlightTarget,
410
+ data: data.computedData,
411
+ datum,
412
+ gridIndex: datum.gridIndex,
413
+ series: data.SeriesDataMap.get(datum.seriesLabel)!,
414
+ seriesIndex: datum.seriesIndex,
415
+ seriesLabel: datum.seriesLabel,
416
+ groups: data.GroupDataMap.get(datum.groupLabel)!,
417
+ groupIndex: datum.groupIndex,
418
+ groupLabel: datum.groupLabel,
419
+ event
420
+ })
421
+ })
422
+ .on('mouseout', (event, datum) => {
423
+ event.stopPropagation()
424
+
425
+ event$.next({
426
+ type: 'grid',
427
+ eventName: 'mouseout',
428
+ pluginName,
429
+ highlightTarget: data.highlightTarget,
430
+ datum,
431
+ gridIndex: datum.gridIndex,
432
+ series: data.SeriesDataMap.get(datum.seriesLabel)!,
433
+ seriesIndex: datum.seriesIndex,
434
+ seriesLabel: datum.seriesLabel,
435
+ groups: data.GroupDataMap.get(datum.groupLabel)!,
436
+ groupIndex: datum.groupIndex,
437
+ groupLabel: datum.groupLabel,
438
+ event,
439
+ data: data.computedData
440
+ })
441
+ })
442
+ .on('click', (event, datum) => {
443
+ event.stopPropagation()
444
+
445
+ event$.next({
446
+ type: 'grid',
447
+ eventName: 'click',
448
+ pluginName,
449
+ highlightTarget: data.highlightTarget,
450
+ datum,
451
+ gridIndex: datum.gridIndex,
452
+ series: data.SeriesDataMap.get(datum.seriesLabel)!,
453
+ seriesIndex: datum.seriesIndex,
454
+ seriesLabel: datum.seriesLabel,
455
+ groups: data.GroupDataMap.get(datum.groupLabel)!,
456
+ groupIndex: datum.groupIndex,
457
+ groupLabel: datum.groupLabel,
458
+ event,
459
+ data: data.computedData
460
+ })
461
+ })
462
+
463
+ })
464
+
465
+ // const datumList$ = computedData$.pipe(
466
+ // takeUntil(destroy$),
467
+ // map(d => d.flat())
468
+ // )
469
+ // const highlight$ = highlightObservable({ datumList$, fullChartParams$, event$: store.event$ })
470
+ // const highlightSubscription = gridHighlight$.subscribe()
471
+ const onlyShowHighlighted$ = fullParams$.pipe(
472
+ takeUntil(destroy$),
473
+ map(d => d.onlyShowHighlighted),
474
+ distinctUntilChanged()
475
+ )
476
+
477
+ fullChartParams$.pipe(
478
+ takeUntil(destroy$),
479
+ switchMap(d => combineLatest({
480
+ graphicSelection: graphicSelection$,
481
+ highlight: gridHighlight$.pipe(
482
+ map(data => data.map(d => d.id))
483
+ ),
484
+ onlyShowHighlighted: onlyShowHighlighted$,
485
+ fullChartParams: fullChartParams$
486
+ }).pipe(
487
+ takeUntil(destroy$),
488
+ switchMap(async d => d)
489
+ ))
490
+ ).subscribe(data => {
491
+ highlightDots({
492
+ selection: data.graphicSelection,
493
+ ids: data.highlight,
494
+ onlyShowHighlighted: data.onlyShowHighlighted,
495
+ fullChartParams: data.fullChartParams
496
+ })
497
+ })
498
+
499
+ return () => {
500
+ destroy$.next(undefined)
501
+ // highlightSubscription.unsubscribe()
502
+ }
640
503
  }