@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,635 +1,635 @@
1
- import * as d3 from 'd3'
2
- import {
3
- combineLatest,
4
- map,
5
- filter,
6
- switchMap,
7
- takeUntil,
8
- distinctUntilChanged,
9
- Observable,
10
- Subject,
11
- share,
12
- shareReplay
13
- } from 'rxjs'
14
- import type {
15
- ComputedDatumMultiValue,
16
- ComputedDataMultiValue,
17
- ComputedXYDatumMultiValue,
18
- ComputedXYDataMultiValue,
19
- DefinePluginConfig,
20
- EventMultiValue,
21
- ChartParams,
22
- ContainerPositionScaled,
23
- Layout,
24
- TransformData,
25
- ColorType
26
- } from '../../../lib/core-types'
27
- import {
28
- defineMultiValuePlugin,
29
- getMinMax
30
- } from '../../../lib/core'
31
- import type { ScatterBubblesParams } from '../../../lib/plugins-basic-types'
32
- import { DEFAULT_SCATTER_BUBBLES_PARAMS } from '../defaults'
33
- import { LAYER_INDEX_OF_GRAPHIC_COVER } from '../../const'
34
- import { getDatumColor, getClassName, getUniID } from '../../utils/orbchartsUtils'
35
- import { multiValueSelectionsObservable } from '../multiValueObservables'
36
-
37
- type ClipPathDatum = {
38
- id: string;
39
- // x: number;
40
- // y: number;
41
- width: number;
42
- height: number;
43
- }
44
-
45
- interface BubbleDatum extends ComputedXYDatumMultiValue {
46
- r: number
47
- opacity: number
48
- }
49
-
50
- const pluginName = 'ScatterBubbles'
51
-
52
- // 調整係數 - 因為圓和圓之間的空隙造成聚合起來的大圓會略大,所以稍作微調
53
- const adjustmentFactor = 0.9
54
-
55
- const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_SCATTER_BUBBLES_PARAMS> = {
56
- name: pluginName,
57
- defaultParams: DEFAULT_SCATTER_BUBBLES_PARAMS,
58
- layerIndex: LAYER_INDEX_OF_GRAPHIC_COVER,
59
- validator: (params, { validateColumns }) => {
60
- const result = validateColumns(params, {
61
- // radius: {
62
- // toBeTypes: ['number']
63
- // },
64
- fillColorType: {
65
- toBeOption: 'ColorType',
66
- },
67
- strokeColorType: {
68
- toBeOption: 'ColorType',
69
- },
70
- strokeWidth: {
71
- toBeTypes: ['number']
72
- },
73
- valueLinearOpacity: {
74
- toBeTypes: ['number[]']
75
- },
76
- arcScaleType: {
77
- toBe: 'ArcScaleType',
78
- test: (value) => {
79
- return value === 'area' || value === 'radius'
80
- }
81
- },
82
- sizeAdjust: {
83
- toBeTypes: ['number']
84
- }
85
- })
86
- return result
87
- }
88
- }
89
-
90
- function renderDots ({ graphicGSelection, circleGClassName, circleClassName, bubbleData, fullParams, fullChartParams, graphicReverseScale }: {
91
- graphicGSelection: d3.Selection<SVGGElement, any, any, any>
92
- circleGClassName: string
93
- circleClassName: string
94
- // visibleComputedLayoutData: ComputedXYDataMultiValue
95
- bubbleData: BubbleDatum[][]
96
- fullParams: ScatterBubblesParams
97
- fullChartParams: ChartParams
98
- graphicReverseScale: [number, number][]
99
- }) {
100
- const createEnterDuration = (enter: d3.Selection<d3.EnterElement, ComputedDatumMultiValue, SVGGElement, any>) => {
101
- const enterSize = enter.size()
102
- const eachDuration = fullChartParams.transitionDuration / enterSize
103
- return eachDuration
104
- }
105
- // enterDuration
106
- let enterDuration = 0
107
-
108
- graphicGSelection
109
- .each((categoryData, categoryIndex, g) => {
110
- d3.select(g[categoryIndex])
111
- .selectAll<SVGGElement, ComputedDatumMultiValue>('g')
112
- .data(bubbleData[categoryIndex], d => d.id)
113
- .join(
114
- enter => {
115
- // enterDuration
116
- enterDuration = createEnterDuration(enter)
117
-
118
- return enter
119
- .append('g')
120
- .classed(circleGClassName, true)
121
- },
122
- update => update,
123
- exit => exit.remove()
124
- )
125
- .attr('transform', d => `translate(${d.axisX}, ${d.axisY})`)
126
- .each((d, i, g) => {
127
- const circle = d3.select(g[i])
128
- .selectAll('circle')
129
- .data([d])
130
- .join(
131
- enter => {
132
- return enter
133
- .append('circle')
134
- .style('cursor', 'pointer')
135
- .style('vector-effect', 'non-scaling-stroke')
136
- .classed(circleClassName, true)
137
- .attr('opacity', 0)
138
- .transition()
139
- .delay((_d, _i) => {
140
- return i * enterDuration
141
- })
142
- .attr('opacity', _d => _d.opacity)
143
- },
144
- update => {
145
- return update
146
- .transition()
147
- .duration(50)
148
- // .attr('cx', d => d.axisX)
149
- // .attr('cy', d => d.axisY)
150
- .attr('opacity', _d => _d.opacity)
151
- },
152
- exit => exit.remove()
153
- )
154
- .attr('r', d => d.r)
155
- .attr('fill', (d, i) => getDatumColor({ datum: d, colorType: fullParams.fillColorType, fullChartParams }))
156
- .attr('stroke', (d, i) => getDatumColor({ datum: d, colorType: fullParams.strokeColorType, fullChartParams }))
157
- .attr('stroke-width', fullParams.strokeWidth)
158
- .attr('transform', `scale(${graphicReverseScale[categoryIndex][0] ?? 1}, ${graphicReverseScale[categoryIndex][1] ?? 1})`)
159
- })
160
- })
161
-
162
- const graphicCircleSelection: d3.Selection<SVGRectElement, BubbleDatum, SVGGElement, unknown> = graphicGSelection.selectAll(`circle.${circleClassName}`)
163
-
164
- return graphicCircleSelection
165
- }
166
-
167
-
168
- function highlightBubbles ({ selection, ids, fullChartParams }: {
169
- selection: d3.Selection<SVGGElement, BubbleDatum, any, any>
170
- ids: string[]
171
- fullChartParams: ChartParams
172
- }) {
173
- selection.interrupt('highlight')
174
- if (!ids.length) {
175
- // remove highlight
176
- selection
177
- .transition('highlight')
178
- .duration(200)
179
- .style('opacity', d => d.opacity)
180
- // selection
181
- // .attr('stroke-width', fullParams.strokeWidth)
182
-
183
- return
184
- }
185
-
186
- selection
187
- .each((d, i, n) => {
188
- if (ids.includes(d.id)) {
189
- const dot = d3.select<SVGGElement, BubbleDatum>(n[i])
190
- dot
191
- .style('opacity', d => d.opacity)
192
- .transition('highlight')
193
- .duration(200)
194
- // dot
195
- // .attr('stroke-width', fullParams.strokeWidthWhileHighlight)
196
- } else {
197
- const dot = d3.select(n[i])
198
- dot
199
- .style('opacity', fullChartParams.styles.unhighlightedOpacity)
200
- .transition('highlight')
201
- .duration(200)
202
- // dot
203
- // .attr('stroke-width', fullParams.strokeWidth)
204
-
205
- }
206
- })
207
- }
208
-
209
- function renderClipPath ({ defsSelection, clipPathData }: {
210
- defsSelection: d3.Selection<SVGDefsElement, any, any, any>
211
- clipPathData: ClipPathDatum[]
212
- }) {
213
- const clipPath = defsSelection
214
- .selectAll<SVGClipPathElement, Layout>('clipPath')
215
- .data(clipPathData)
216
- .join(
217
- enter => {
218
- return enter
219
- .append('clipPath')
220
- },
221
- update => update,
222
- exit => exit.remove()
223
- )
224
- .attr('id', d => d.id)
225
- .each((d, i, g) => {
226
- const rect = d3.select(g[i])
227
- .selectAll<SVGRectElement, typeof d>('rect')
228
- .data([d])
229
- .join('rect')
230
- .attr('x', 0)
231
- .attr('y', 0)
232
- .attr('width', _d => _d.width)
233
- .attr('height', _d => _d.height)
234
- })
235
-
236
- }
237
-
238
-
239
- export const ScatterBubbles = defineMultiValuePlugin(pluginConfig)(({ selection, name, subject, observer }) => {
240
-
241
- const destroy$ = new Subject()
242
-
243
- const clipPathID = getUniID(pluginName, 'clipPath-box')
244
- const circleGClassName = getClassName(pluginName, 'circleG')
245
- const circleClassName = getClassName(pluginName, 'circle')
246
-
247
- const {
248
- categorySelection$,
249
- axesSelection$,
250
- defsSelection$,
251
- graphicGSelection$
252
- } = multiValueSelectionsObservable({
253
- selection,
254
- pluginName,
255
- clipPathID,
256
- categoryLabels$: observer.categoryLabels$,
257
- containerPosition$: observer.containerPosition$,
258
- graphicTransform$: observer.graphicTransform$
259
- })
260
-
261
- const graphicReverseScale$: Observable<[number, number][]> = combineLatest({
262
- computedData: observer.computedData$,
263
- graphicReverseScale: observer.graphicReverseScale$
264
- }).pipe(
265
- takeUntil(destroy$),
266
- switchMap(async data => data),
267
- map(data => {
268
- return data.computedData.map((series, categoryIndex) => {
269
- return data.graphicReverseScale[categoryIndex]
270
- })
271
- })
272
- )
273
-
274
- const clipPathSubscription = combineLatest({
275
- defsSelection: defsSelection$,
276
- layout: observer.layout$,
277
- }).pipe(
278
- takeUntil(destroy$),
279
- switchMap(async (d) => d),
280
- ).subscribe(data => {
281
- // 外層的遮罩
282
- const clipPathData = [{
283
- id: clipPathID,
284
- width: data.layout.width,
285
- height: data.layout.height
286
- }]
287
- renderClipPath({
288
- defsSelection: data.defsSelection,
289
- clipPathData,
290
- })
291
- })
292
-
293
- const filteredValueList$ = observer.filteredXYMinMaxData$.pipe(
294
- takeUntil(destroy$),
295
- map(data => data.datumList.flat().map(d => d.value[2] ?? 0)),
296
- shareReplay(1)
297
- )
298
-
299
- const filteredMinMaxValue$ = observer.filteredXYMinMaxData$.pipe(
300
- takeUntil(destroy$),
301
- map(data => {
302
- return getMinMax(data.datumList.flat().map(d => d.value[2] ?? 0))
303
- })
304
- )
305
-
306
- const opacityScale$ = combineLatest({
307
- filteredMinMaxValue: filteredMinMaxValue$,
308
- fullParams: observer.fullParams$
309
- }).pipe(
310
- takeUntil(destroy$),
311
- switchMap(async (d) => d),
312
- map(data => {
313
- return d3.scaleLinear()
314
- .domain(data.filteredMinMaxValue)
315
- .range(data.fullParams.valueLinearOpacity)
316
- })
317
- )
318
-
319
- // 虛擬大圓(所有小圓聚合起來的大圓)的半徑
320
- const totalR$ = combineLatest({
321
- layout: observer.layout$,
322
- fullParams: observer.fullParams$
323
- }).pipe(
324
- takeUntil(destroy$),
325
- map(data => {
326
- // 場景最短邊
327
- const fullRadius = Math.min(...[data.layout.width, data.layout.height]) / 2
328
- return fullRadius * data.fullParams.sizeAdjust
329
- })
330
- )
331
-
332
- const totalValue$ = filteredValueList$.pipe(
333
- takeUntil(destroy$),
334
- map(data => {
335
- return data.reduce((acc, current) => acc + current, 0)
336
- }),
337
- filter(data => data > 0) // 避免後續計算scale的時候發生問題
338
- )
339
-
340
- const radiusScale$ = combineLatest({
341
- totalR: totalR$,
342
- totalValue: totalValue$,
343
- fullParams: observer.fullParams$
344
- }).pipe(
345
- takeUntil(destroy$),
346
- switchMap(async (d) => d),
347
- map(data => {
348
- // console.log({ totalR: data.totalR, totalValue: data.totalValue })
349
- return d3.scalePow()
350
- .domain([0, data.totalValue])
351
- .range([0, data.totalR])
352
- .exponent(data.fullParams.arcScaleType === 'area'
353
- ? 0.5 // 數值映射面積(0.5為取平方根)
354
- : 1 // 數值映射半徑
355
- )
356
- })
357
- )
358
-
359
- const scaleFactor$ = combineLatest({
360
- radiusScale: radiusScale$,
361
- fullParams: observer.fullParams$,
362
- totalR: totalR$,
363
- filteredValueList: filteredValueList$
364
- }).pipe(
365
- takeUntil(destroy$),
366
- switchMap(async (d) => d),
367
- map(data => {
368
- return data.fullParams.arcScaleType === 'area'
369
- ? 1
370
- // 當數值映射半徑時,多個小圓的總面積會小於大圓的面積,所以要計算縮放比例
371
- : (() => {
372
- const totalArea = data.totalR * data.totalR * Math.PI
373
- return Math.sqrt(totalArea / d3.sum(data.filteredValueList, d => Math.PI * Math.pow(data.radiusScale(d), 2)))
374
- })()
375
- })
376
- )
377
-
378
- const bubbleData$ = combineLatest({
379
- visibleComputedXYData: observer.visibleComputedXYData$,
380
- opacityScale: opacityScale$,
381
- radiusScale: radiusScale$,
382
- scaleFactor: scaleFactor$,
383
- fullParams: observer.fullParams$
384
- }).pipe(
385
- takeUntil(destroy$),
386
- switchMap(async (d) => d),
387
- map(data => {
388
- return data.visibleComputedXYData.map(category => {
389
- return category.map(_d => {
390
- const d: BubbleDatum = _d as BubbleDatum
391
- d.r = data.radiusScale(d.value[2]) * data.scaleFactor * adjustmentFactor
392
- d.opacity = data.opacityScale(d.value[2])
393
- return d
394
- })
395
- })
396
- })
397
- )
398
-
399
-
400
- const graphicSelection$ = combineLatest({
401
- graphicGSelection: graphicGSelection$,
402
- // visibleComputedLayoutData: observer.visibleComputedLayoutData$,
403
- bubbleData: bubbleData$,
404
- graphicReverseScale: graphicReverseScale$,
405
- fullChartParams: observer.fullChartParams$,
406
- fullParams: observer.fullParams$,
407
- }).pipe(
408
- takeUntil(destroy$),
409
- switchMap(async (d) => d),
410
- map(data => {
411
- return renderDots({
412
- graphicGSelection: data.graphicGSelection,
413
- circleGClassName,
414
- circleClassName,
415
- bubbleData: data.bubbleData,
416
- fullParams: data.fullParams,
417
- fullChartParams: data.fullChartParams,
418
- graphicReverseScale: data.graphicReverseScale
419
- })
420
- })
421
- )
422
-
423
- const valueLabels$ = observer.fullDataFormatter$.pipe(
424
- takeUntil(destroy$),
425
- map(dataFormatter => {
426
- return [
427
- dataFormatter.valueLabels[0] ?? 'X',
428
- dataFormatter.valueLabels[1] ?? 'Y',
429
- dataFormatter.valueLabels[2] ?? 'Value'
430
- ]
431
- }),
432
- distinctUntilChanged((a, b) => a[0] === b[0] && a[1] === b[1] && a[2] === b[2])
433
- )
434
-
435
- const highlightTarget$ = observer.fullChartParams$.pipe(
436
- takeUntil(destroy$),
437
- map(d => d.highlightTarget),
438
- distinctUntilChanged()
439
- )
440
-
441
- combineLatest({
442
- graphicSelection: graphicSelection$,
443
- computedData: observer.computedData$,
444
- CategoryDataMap: observer.CategoryDataMap$,
445
- highlightTarget: highlightTarget$,
446
- valueLabels: valueLabels$
447
- }).pipe(
448
- takeUntil(destroy$),
449
- switchMap(async (d) => d),
450
- ).subscribe(data => {
451
-
452
- data.graphicSelection
453
- .on('mouseover', (event, datum) => {
454
- // event.stopPropagation()
455
- // console.log({
456
- // type: 'multiValue',
457
- // eventName: 'mouseover',
458
- // pluginName,
459
- // highlightTarget: data.highlightTarget,
460
- // datum,
461
- // category: data.CategoryDataMap.get(datum.categoryLabel)!,
462
- // categoryIndex: datum.categoryIndex,
463
- // categoryLabel: datum.categoryLabel,
464
- // data: data.computedData,
465
- // event,
466
- // })
467
- subject.event$.next({
468
- type: 'multiValue',
469
- eventName: 'mouseover',
470
- pluginName,
471
- highlightTarget: data.highlightTarget,
472
- valueDetail: [
473
- {
474
- value: datum.value[0],
475
- valueIndex: 0,
476
- valueLabel: data.valueLabels[0]
477
- },
478
- {
479
- value: datum.value[1],
480
- valueIndex: 1,
481
- valueLabel: data.valueLabels[1]
482
- },
483
- {
484
- value: datum.value[2],
485
- valueIndex: 2,
486
- valueLabel: data.valueLabels[2]
487
- }
488
- ],
489
- datum,
490
- category: data.CategoryDataMap.get(datum.categoryLabel)!,
491
- categoryIndex: datum.categoryIndex,
492
- categoryLabel: datum.categoryLabel,
493
- data: data.computedData,
494
- event,
495
- })
496
- })
497
- .on('mousemove', (event, datum) => {
498
- // event.stopPropagation()
499
-
500
- subject.event$.next({
501
- type: 'multiValue',
502
- eventName: 'mousemove',
503
- pluginName,
504
- highlightTarget: data.highlightTarget,
505
- valueDetail: [
506
- {
507
- value: datum.value[0],
508
- valueIndex: 0,
509
- valueLabel: data.valueLabels[0]
510
- },
511
- {
512
- value: datum.value[1],
513
- valueIndex: 1,
514
- valueLabel: data.valueLabels[1]
515
- },
516
- {
517
- value: datum.value[2],
518
- valueIndex: 2,
519
- valueLabel: data.valueLabels[2]
520
- }
521
- ],
522
- datum,
523
- category: data.CategoryDataMap.get(datum.categoryLabel)!,
524
- categoryIndex: datum.categoryIndex,
525
- categoryLabel: datum.categoryLabel,
526
- data: data.computedData,
527
- event,
528
- })
529
- })
530
- .on('mouseout', (event, datum) => {
531
- // event.stopPropagation()
532
-
533
- subject.event$.next({
534
- type: 'multiValue',
535
- eventName: 'mouseout',
536
- pluginName,
537
- highlightTarget: data.highlightTarget,
538
- valueDetail: [
539
- {
540
- value: datum.value[0],
541
- valueIndex: 0,
542
- valueLabel: data.valueLabels[0]
543
- },
544
- {
545
- value: datum.value[1],
546
- valueIndex: 1,
547
- valueLabel: data.valueLabels[1]
548
- },
549
- {
550
- value: datum.value[2],
551
- valueIndex: 2,
552
- valueLabel: data.valueLabels[2]
553
- }
554
- ],
555
- datum,
556
- category: data.CategoryDataMap.get(datum.categoryLabel)!,
557
- categoryIndex: datum.categoryIndex,
558
- categoryLabel: datum.categoryLabel,
559
- data: data.computedData,
560
- event,
561
- })
562
- })
563
- .on('click', (event, datum) => {
564
- // event.stopPropagation()
565
-
566
- subject.event$.next({
567
- type: 'multiValue',
568
- eventName: 'click',
569
- pluginName,
570
- highlightTarget: data.highlightTarget,
571
- valueDetail: [
572
- {
573
- value: datum.value[0],
574
- valueIndex: 0,
575
- valueLabel: data.valueLabels[0]
576
- },
577
- {
578
- value: datum.value[1],
579
- valueIndex: 1,
580
- valueLabel: data.valueLabels[1]
581
- },
582
- {
583
- value: datum.value[2],
584
- valueIndex: 2,
585
- valueLabel: data.valueLabels[2]
586
- }
587
- ],
588
- datum,
589
- category: data.CategoryDataMap.get(datum.categoryLabel)!,
590
- categoryIndex: datum.categoryIndex,
591
- categoryLabel: datum.categoryLabel,
592
- data: data.computedData,
593
- event,
594
- })
595
- })
596
-
597
- })
598
-
599
- combineLatest({
600
- graphicSelection: graphicSelection$,
601
- highlight: observer.highlight$.pipe(
602
- map(data => data.map(d => d.id))
603
- ),
604
- fullChartParams: observer.fullChartParams$
605
- }).pipe(
606
- takeUntil(destroy$),
607
- switchMap(async d => d)
608
- ).subscribe(data => {
609
- highlightBubbles({
610
- selection: data.graphicSelection,
611
- ids: data.highlight,
612
- fullChartParams: data.fullChartParams
613
- })
614
- })
615
-
616
- // graphicGSelection$.subscribe(data => {
617
- // console.log('graphicGSelection$', data)
618
- // })
619
-
620
- // observer.visibleComputedLayoutData$.subscribe(data => {
621
- // console.log('visibleComputedLayoutData$', data)
622
- // })
623
-
624
- // observer.fullChartParams$.subscribe(data => {
625
- // console.log('fullChartParams$', data)
626
- // })
627
-
628
- // observer.fullParams$.subscribe(data => {
629
- // console.log('fullParams$', data)
630
- // })
631
-
632
- return () => {
633
- destroy$.next(undefined)
634
- }
635
- })
1
+ import * as d3 from 'd3'
2
+ import {
3
+ combineLatest,
4
+ map,
5
+ filter,
6
+ switchMap,
7
+ takeUntil,
8
+ distinctUntilChanged,
9
+ Observable,
10
+ Subject,
11
+ share,
12
+ shareReplay
13
+ } from 'rxjs'
14
+ import type {
15
+ ComputedDatumMultiValue,
16
+ ComputedDataMultiValue,
17
+ ComputedXYDatumMultiValue,
18
+ ComputedXYDataMultiValue,
19
+ DefinePluginConfig,
20
+ EventMultiValue,
21
+ ChartParams,
22
+ ContainerPositionScaled,
23
+ Layout,
24
+ TransformData,
25
+ ColorType
26
+ } from '../../../lib/core-types'
27
+ import {
28
+ defineMultiValuePlugin,
29
+ getMinMax
30
+ } from '../../../lib/core'
31
+ import type { ScatterBubblesParams } from '../../../lib/plugins-basic-types'
32
+ import { DEFAULT_SCATTER_BUBBLES_PARAMS } from '../defaults'
33
+ import { LAYER_INDEX_OF_GRAPHIC_COVER } from '../../const'
34
+ import { getDatumColor, getClassName, getUniID } from '../../utils/orbchartsUtils'
35
+ import { multiValueSelectionsObservable } from '../multiValueObservables'
36
+
37
+ type ClipPathDatum = {
38
+ id: string;
39
+ // x: number;
40
+ // y: number;
41
+ width: number;
42
+ height: number;
43
+ }
44
+
45
+ interface BubbleDatum extends ComputedXYDatumMultiValue {
46
+ r: number
47
+ opacity: number
48
+ }
49
+
50
+ const pluginName = 'ScatterBubbles'
51
+
52
+ // 調整係數 - 因為圓和圓之間的空隙造成聚合起來的大圓會略大,所以稍作微調
53
+ const adjustmentFactor = 0.9
54
+
55
+ const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_SCATTER_BUBBLES_PARAMS> = {
56
+ name: pluginName,
57
+ defaultParams: DEFAULT_SCATTER_BUBBLES_PARAMS,
58
+ layerIndex: LAYER_INDEX_OF_GRAPHIC_COVER,
59
+ validator: (params, { validateColumns }) => {
60
+ const result = validateColumns(params, {
61
+ // radius: {
62
+ // toBeTypes: ['number']
63
+ // },
64
+ fillColorType: {
65
+ toBeOption: 'ColorType',
66
+ },
67
+ strokeColorType: {
68
+ toBeOption: 'ColorType',
69
+ },
70
+ strokeWidth: {
71
+ toBeTypes: ['number']
72
+ },
73
+ valueLinearOpacity: {
74
+ toBeTypes: ['number[]']
75
+ },
76
+ arcScaleType: {
77
+ toBe: 'ArcScaleType',
78
+ test: (value) => {
79
+ return value === 'area' || value === 'radius'
80
+ }
81
+ },
82
+ sizeAdjust: {
83
+ toBeTypes: ['number']
84
+ }
85
+ })
86
+ return result
87
+ }
88
+ }
89
+
90
+ function renderDots ({ graphicGSelection, circleGClassName, circleClassName, bubbleData, fullParams, fullChartParams, graphicReverseScale }: {
91
+ graphicGSelection: d3.Selection<SVGGElement, any, any, any>
92
+ circleGClassName: string
93
+ circleClassName: string
94
+ // visibleComputedLayoutData: ComputedXYDataMultiValue
95
+ bubbleData: BubbleDatum[][]
96
+ fullParams: ScatterBubblesParams
97
+ fullChartParams: ChartParams
98
+ graphicReverseScale: [number, number][]
99
+ }) {
100
+ const createEnterDuration = (enter: d3.Selection<d3.EnterElement, ComputedDatumMultiValue, SVGGElement, any>) => {
101
+ const enterSize = enter.size()
102
+ const eachDuration = fullChartParams.transitionDuration / enterSize
103
+ return eachDuration
104
+ }
105
+ // enterDuration
106
+ let enterDuration = 0
107
+
108
+ graphicGSelection
109
+ .each((categoryData, categoryIndex, g) => {
110
+ d3.select(g[categoryIndex])
111
+ .selectAll<SVGGElement, ComputedDatumMultiValue>('g')
112
+ .data(bubbleData[categoryIndex], d => d.id)
113
+ .join(
114
+ enter => {
115
+ // enterDuration
116
+ enterDuration = createEnterDuration(enter)
117
+
118
+ return enter
119
+ .append('g')
120
+ .classed(circleGClassName, true)
121
+ },
122
+ update => update,
123
+ exit => exit.remove()
124
+ )
125
+ .attr('transform', d => `translate(${d.axisX}, ${d.axisY})`)
126
+ .each((d, i, g) => {
127
+ const circle = d3.select(g[i])
128
+ .selectAll('circle')
129
+ .data([d])
130
+ .join(
131
+ enter => {
132
+ return enter
133
+ .append('circle')
134
+ .style('cursor', 'pointer')
135
+ .style('vector-effect', 'non-scaling-stroke')
136
+ .classed(circleClassName, true)
137
+ .attr('opacity', 0)
138
+ .transition()
139
+ .delay((_d, _i) => {
140
+ return i * enterDuration
141
+ })
142
+ .attr('opacity', _d => _d.opacity)
143
+ },
144
+ update => {
145
+ return update
146
+ .transition()
147
+ .duration(50)
148
+ // .attr('cx', d => d.axisX)
149
+ // .attr('cy', d => d.axisY)
150
+ .attr('opacity', _d => _d.opacity)
151
+ },
152
+ exit => exit.remove()
153
+ )
154
+ .attr('r', d => d.r)
155
+ .attr('fill', (d, i) => getDatumColor({ datum: d, colorType: fullParams.fillColorType, fullChartParams }))
156
+ .attr('stroke', (d, i) => getDatumColor({ datum: d, colorType: fullParams.strokeColorType, fullChartParams }))
157
+ .attr('stroke-width', fullParams.strokeWidth)
158
+ .attr('transform', `scale(${graphicReverseScale[categoryIndex][0] ?? 1}, ${graphicReverseScale[categoryIndex][1] ?? 1})`)
159
+ })
160
+ })
161
+
162
+ const graphicCircleSelection: d3.Selection<SVGRectElement, BubbleDatum, SVGGElement, unknown> = graphicGSelection.selectAll(`circle.${circleClassName}`)
163
+
164
+ return graphicCircleSelection
165
+ }
166
+
167
+
168
+ function highlightBubbles ({ selection, ids, fullChartParams }: {
169
+ selection: d3.Selection<SVGGElement, BubbleDatum, any, any>
170
+ ids: string[]
171
+ fullChartParams: ChartParams
172
+ }) {
173
+ selection.interrupt('highlight')
174
+ if (!ids.length) {
175
+ // remove highlight
176
+ selection
177
+ .transition('highlight')
178
+ .duration(200)
179
+ .style('opacity', d => d.opacity)
180
+ // selection
181
+ // .attr('stroke-width', fullParams.strokeWidth)
182
+
183
+ return
184
+ }
185
+
186
+ selection
187
+ .each((d, i, n) => {
188
+ if (ids.includes(d.id)) {
189
+ const dot = d3.select<SVGGElement, BubbleDatum>(n[i])
190
+ dot
191
+ .style('opacity', d => d.opacity)
192
+ .transition('highlight')
193
+ .duration(200)
194
+ // dot
195
+ // .attr('stroke-width', fullParams.strokeWidthWhileHighlight)
196
+ } else {
197
+ const dot = d3.select(n[i])
198
+ dot
199
+ .style('opacity', fullChartParams.styles.unhighlightedOpacity)
200
+ .transition('highlight')
201
+ .duration(200)
202
+ // dot
203
+ // .attr('stroke-width', fullParams.strokeWidth)
204
+
205
+ }
206
+ })
207
+ }
208
+
209
+ function renderClipPath ({ defsSelection, clipPathData }: {
210
+ defsSelection: d3.Selection<SVGDefsElement, any, any, any>
211
+ clipPathData: ClipPathDatum[]
212
+ }) {
213
+ const clipPath = defsSelection
214
+ .selectAll<SVGClipPathElement, Layout>('clipPath')
215
+ .data(clipPathData)
216
+ .join(
217
+ enter => {
218
+ return enter
219
+ .append('clipPath')
220
+ },
221
+ update => update,
222
+ exit => exit.remove()
223
+ )
224
+ .attr('id', d => d.id)
225
+ .each((d, i, g) => {
226
+ const rect = d3.select(g[i])
227
+ .selectAll<SVGRectElement, typeof d>('rect')
228
+ .data([d])
229
+ .join('rect')
230
+ .attr('x', 0)
231
+ .attr('y', 0)
232
+ .attr('width', _d => _d.width)
233
+ .attr('height', _d => _d.height)
234
+ })
235
+
236
+ }
237
+
238
+
239
+ export const ScatterBubbles = defineMultiValuePlugin(pluginConfig)(({ selection, name, subject, observer }) => {
240
+
241
+ const destroy$ = new Subject()
242
+
243
+ const clipPathID = getUniID(pluginName, 'clipPath-box')
244
+ const circleGClassName = getClassName(pluginName, 'circleG')
245
+ const circleClassName = getClassName(pluginName, 'circle')
246
+
247
+ const {
248
+ categorySelection$,
249
+ axesSelection$,
250
+ defsSelection$,
251
+ graphicGSelection$
252
+ } = multiValueSelectionsObservable({
253
+ selection,
254
+ pluginName,
255
+ clipPathID,
256
+ categoryLabels$: observer.categoryLabels$,
257
+ containerPosition$: observer.containerPosition$,
258
+ graphicTransform$: observer.graphicTransform$
259
+ })
260
+
261
+ const graphicReverseScale$: Observable<[number, number][]> = combineLatest({
262
+ computedData: observer.computedData$,
263
+ graphicReverseScale: observer.graphicReverseScale$
264
+ }).pipe(
265
+ takeUntil(destroy$),
266
+ switchMap(async data => data),
267
+ map(data => {
268
+ return data.computedData.map((series, categoryIndex) => {
269
+ return data.graphicReverseScale[categoryIndex]
270
+ })
271
+ })
272
+ )
273
+
274
+ const clipPathSubscription = combineLatest({
275
+ defsSelection: defsSelection$,
276
+ layout: observer.layout$,
277
+ }).pipe(
278
+ takeUntil(destroy$),
279
+ switchMap(async (d) => d),
280
+ ).subscribe(data => {
281
+ // 外層的遮罩
282
+ const clipPathData = [{
283
+ id: clipPathID,
284
+ width: data.layout.width,
285
+ height: data.layout.height
286
+ }]
287
+ renderClipPath({
288
+ defsSelection: data.defsSelection,
289
+ clipPathData,
290
+ })
291
+ })
292
+
293
+ const filteredValueList$ = observer.filteredXYMinMaxData$.pipe(
294
+ takeUntil(destroy$),
295
+ map(data => data.datumList.flat().map(d => d.value[2] ?? 0)),
296
+ shareReplay(1)
297
+ )
298
+
299
+ const filteredMinMaxValue$ = observer.filteredXYMinMaxData$.pipe(
300
+ takeUntil(destroy$),
301
+ map(data => {
302
+ return getMinMax(data.datumList.flat().map(d => d.value[2] ?? 0))
303
+ })
304
+ )
305
+
306
+ const opacityScale$ = combineLatest({
307
+ filteredMinMaxValue: filteredMinMaxValue$,
308
+ fullParams: observer.fullParams$
309
+ }).pipe(
310
+ takeUntil(destroy$),
311
+ switchMap(async (d) => d),
312
+ map(data => {
313
+ return d3.scaleLinear()
314
+ .domain(data.filteredMinMaxValue)
315
+ .range(data.fullParams.valueLinearOpacity)
316
+ })
317
+ )
318
+
319
+ // 虛擬大圓(所有小圓聚合起來的大圓)的半徑
320
+ const totalR$ = combineLatest({
321
+ layout: observer.layout$,
322
+ fullParams: observer.fullParams$
323
+ }).pipe(
324
+ takeUntil(destroy$),
325
+ map(data => {
326
+ // 場景最短邊
327
+ const fullRadius = Math.min(...[data.layout.width, data.layout.height]) / 2
328
+ return fullRadius * data.fullParams.sizeAdjust
329
+ })
330
+ )
331
+
332
+ const totalValue$ = filteredValueList$.pipe(
333
+ takeUntil(destroy$),
334
+ map(data => {
335
+ return data.reduce((acc, current) => acc + current, 0)
336
+ }),
337
+ filter(data => data > 0) // 避免後續計算scale的時候發生問題
338
+ )
339
+
340
+ const radiusScale$ = combineLatest({
341
+ totalR: totalR$,
342
+ totalValue: totalValue$,
343
+ fullParams: observer.fullParams$
344
+ }).pipe(
345
+ takeUntil(destroy$),
346
+ switchMap(async (d) => d),
347
+ map(data => {
348
+ // console.log({ totalR: data.totalR, totalValue: data.totalValue })
349
+ return d3.scalePow()
350
+ .domain([0, data.totalValue])
351
+ .range([0, data.totalR])
352
+ .exponent(data.fullParams.arcScaleType === 'area'
353
+ ? 0.5 // 數值映射面積(0.5為取平方根)
354
+ : 1 // 數值映射半徑
355
+ )
356
+ })
357
+ )
358
+
359
+ const scaleFactor$ = combineLatest({
360
+ radiusScale: radiusScale$,
361
+ fullParams: observer.fullParams$,
362
+ totalR: totalR$,
363
+ filteredValueList: filteredValueList$
364
+ }).pipe(
365
+ takeUntil(destroy$),
366
+ switchMap(async (d) => d),
367
+ map(data => {
368
+ return data.fullParams.arcScaleType === 'area'
369
+ ? 1
370
+ // 當數值映射半徑時,多個小圓的總面積會小於大圓的面積,所以要計算縮放比例
371
+ : (() => {
372
+ const totalArea = data.totalR * data.totalR * Math.PI
373
+ return Math.sqrt(totalArea / d3.sum(data.filteredValueList, d => Math.PI * Math.pow(data.radiusScale(d), 2)))
374
+ })()
375
+ })
376
+ )
377
+
378
+ const bubbleData$ = combineLatest({
379
+ visibleComputedXYData: observer.visibleComputedXYData$,
380
+ opacityScale: opacityScale$,
381
+ radiusScale: radiusScale$,
382
+ scaleFactor: scaleFactor$,
383
+ fullParams: observer.fullParams$
384
+ }).pipe(
385
+ takeUntil(destroy$),
386
+ switchMap(async (d) => d),
387
+ map(data => {
388
+ return data.visibleComputedXYData.map(category => {
389
+ return category.map(_d => {
390
+ const d: BubbleDatum = _d as BubbleDatum
391
+ d.r = data.radiusScale(d.value[2]) * data.scaleFactor * adjustmentFactor
392
+ d.opacity = data.opacityScale(d.value[2])
393
+ return d
394
+ })
395
+ })
396
+ })
397
+ )
398
+
399
+
400
+ const graphicSelection$ = combineLatest({
401
+ graphicGSelection: graphicGSelection$,
402
+ // visibleComputedLayoutData: observer.visibleComputedLayoutData$,
403
+ bubbleData: bubbleData$,
404
+ graphicReverseScale: graphicReverseScale$,
405
+ fullChartParams: observer.fullChartParams$,
406
+ fullParams: observer.fullParams$,
407
+ }).pipe(
408
+ takeUntil(destroy$),
409
+ switchMap(async (d) => d),
410
+ map(data => {
411
+ return renderDots({
412
+ graphicGSelection: data.graphicGSelection,
413
+ circleGClassName,
414
+ circleClassName,
415
+ bubbleData: data.bubbleData,
416
+ fullParams: data.fullParams,
417
+ fullChartParams: data.fullChartParams,
418
+ graphicReverseScale: data.graphicReverseScale
419
+ })
420
+ })
421
+ )
422
+
423
+ const valueLabels$ = observer.fullDataFormatter$.pipe(
424
+ takeUntil(destroy$),
425
+ map(dataFormatter => {
426
+ return [
427
+ dataFormatter.valueLabels[0] ?? 'X',
428
+ dataFormatter.valueLabels[1] ?? 'Y',
429
+ dataFormatter.valueLabels[2] ?? 'Value'
430
+ ]
431
+ }),
432
+ distinctUntilChanged((a, b) => a[0] === b[0] && a[1] === b[1] && a[2] === b[2])
433
+ )
434
+
435
+ const highlightTarget$ = observer.fullChartParams$.pipe(
436
+ takeUntil(destroy$),
437
+ map(d => d.highlightTarget),
438
+ distinctUntilChanged()
439
+ )
440
+
441
+ combineLatest({
442
+ graphicSelection: graphicSelection$,
443
+ computedData: observer.computedData$,
444
+ CategoryDataMap: observer.CategoryDataMap$,
445
+ highlightTarget: highlightTarget$,
446
+ valueLabels: valueLabels$
447
+ }).pipe(
448
+ takeUntil(destroy$),
449
+ switchMap(async (d) => d),
450
+ ).subscribe(data => {
451
+
452
+ data.graphicSelection
453
+ .on('mouseover', (event, datum) => {
454
+ // event.stopPropagation()
455
+ // console.log({
456
+ // type: 'multiValue',
457
+ // eventName: 'mouseover',
458
+ // pluginName,
459
+ // highlightTarget: data.highlightTarget,
460
+ // datum,
461
+ // category: data.CategoryDataMap.get(datum.categoryLabel)!,
462
+ // categoryIndex: datum.categoryIndex,
463
+ // categoryLabel: datum.categoryLabel,
464
+ // data: data.computedData,
465
+ // event,
466
+ // })
467
+ subject.event$.next({
468
+ type: 'multiValue',
469
+ eventName: 'mouseover',
470
+ pluginName,
471
+ highlightTarget: data.highlightTarget,
472
+ valueDetail: [
473
+ {
474
+ value: datum.value[0],
475
+ valueIndex: 0,
476
+ valueLabel: data.valueLabels[0]
477
+ },
478
+ {
479
+ value: datum.value[1],
480
+ valueIndex: 1,
481
+ valueLabel: data.valueLabels[1]
482
+ },
483
+ {
484
+ value: datum.value[2],
485
+ valueIndex: 2,
486
+ valueLabel: data.valueLabels[2]
487
+ }
488
+ ],
489
+ datum,
490
+ category: data.CategoryDataMap.get(datum.categoryLabel)!,
491
+ categoryIndex: datum.categoryIndex,
492
+ categoryLabel: datum.categoryLabel,
493
+ data: data.computedData,
494
+ event,
495
+ })
496
+ })
497
+ .on('mousemove', (event, datum) => {
498
+ // event.stopPropagation()
499
+
500
+ subject.event$.next({
501
+ type: 'multiValue',
502
+ eventName: 'mousemove',
503
+ pluginName,
504
+ highlightTarget: data.highlightTarget,
505
+ valueDetail: [
506
+ {
507
+ value: datum.value[0],
508
+ valueIndex: 0,
509
+ valueLabel: data.valueLabels[0]
510
+ },
511
+ {
512
+ value: datum.value[1],
513
+ valueIndex: 1,
514
+ valueLabel: data.valueLabels[1]
515
+ },
516
+ {
517
+ value: datum.value[2],
518
+ valueIndex: 2,
519
+ valueLabel: data.valueLabels[2]
520
+ }
521
+ ],
522
+ datum,
523
+ category: data.CategoryDataMap.get(datum.categoryLabel)!,
524
+ categoryIndex: datum.categoryIndex,
525
+ categoryLabel: datum.categoryLabel,
526
+ data: data.computedData,
527
+ event,
528
+ })
529
+ })
530
+ .on('mouseout', (event, datum) => {
531
+ // event.stopPropagation()
532
+
533
+ subject.event$.next({
534
+ type: 'multiValue',
535
+ eventName: 'mouseout',
536
+ pluginName,
537
+ highlightTarget: data.highlightTarget,
538
+ valueDetail: [
539
+ {
540
+ value: datum.value[0],
541
+ valueIndex: 0,
542
+ valueLabel: data.valueLabels[0]
543
+ },
544
+ {
545
+ value: datum.value[1],
546
+ valueIndex: 1,
547
+ valueLabel: data.valueLabels[1]
548
+ },
549
+ {
550
+ value: datum.value[2],
551
+ valueIndex: 2,
552
+ valueLabel: data.valueLabels[2]
553
+ }
554
+ ],
555
+ datum,
556
+ category: data.CategoryDataMap.get(datum.categoryLabel)!,
557
+ categoryIndex: datum.categoryIndex,
558
+ categoryLabel: datum.categoryLabel,
559
+ data: data.computedData,
560
+ event,
561
+ })
562
+ })
563
+ .on('click', (event, datum) => {
564
+ // event.stopPropagation()
565
+
566
+ subject.event$.next({
567
+ type: 'multiValue',
568
+ eventName: 'click',
569
+ pluginName,
570
+ highlightTarget: data.highlightTarget,
571
+ valueDetail: [
572
+ {
573
+ value: datum.value[0],
574
+ valueIndex: 0,
575
+ valueLabel: data.valueLabels[0]
576
+ },
577
+ {
578
+ value: datum.value[1],
579
+ valueIndex: 1,
580
+ valueLabel: data.valueLabels[1]
581
+ },
582
+ {
583
+ value: datum.value[2],
584
+ valueIndex: 2,
585
+ valueLabel: data.valueLabels[2]
586
+ }
587
+ ],
588
+ datum,
589
+ category: data.CategoryDataMap.get(datum.categoryLabel)!,
590
+ categoryIndex: datum.categoryIndex,
591
+ categoryLabel: datum.categoryLabel,
592
+ data: data.computedData,
593
+ event,
594
+ })
595
+ })
596
+
597
+ })
598
+
599
+ combineLatest({
600
+ graphicSelection: graphicSelection$,
601
+ highlight: observer.highlight$.pipe(
602
+ map(data => data.map(d => d.id))
603
+ ),
604
+ fullChartParams: observer.fullChartParams$
605
+ }).pipe(
606
+ takeUntil(destroy$),
607
+ switchMap(async d => d)
608
+ ).subscribe(data => {
609
+ highlightBubbles({
610
+ selection: data.graphicSelection,
611
+ ids: data.highlight,
612
+ fullChartParams: data.fullChartParams
613
+ })
614
+ })
615
+
616
+ // graphicGSelection$.subscribe(data => {
617
+ // console.log('graphicGSelection$', data)
618
+ // })
619
+
620
+ // observer.visibleComputedLayoutData$.subscribe(data => {
621
+ // console.log('visibleComputedLayoutData$', data)
622
+ // })
623
+
624
+ // observer.fullChartParams$.subscribe(data => {
625
+ // console.log('fullChartParams$', data)
626
+ // })
627
+
628
+ // observer.fullParams$.subscribe(data => {
629
+ // console.log('fullParams$', data)
630
+ // })
631
+
632
+ return () => {
633
+ destroy$.next(undefined)
634
+ }
635
+ })