@orbcharts/plugins-basic 3.0.0-beta.17 → 3.0.0-beta.19

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 (113) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-plugins-basic.es.js +2609 -2595
  3. package/dist/orbcharts-plugins-basic.umd.js +36 -34
  4. package/dist/src/grid/defaults.d.ts +2 -2
  5. package/dist/src/multiGrid/defaults.d.ts +1 -1
  6. package/dist/src/multiValue/defaults.d.ts +1 -1
  7. package/lib/core-types.ts +7 -7
  8. package/lib/core.ts +6 -6
  9. package/lib/plugins-basic-types.ts +6 -6
  10. package/package.json +44 -44
  11. package/src/base/BaseBars.ts +765 -765
  12. package/src/base/BaseBarsTriangle.ts +676 -676
  13. package/src/base/BaseDots.ts +464 -464
  14. package/src/base/BaseGroupAxis.ts +691 -691
  15. package/src/base/BaseLegend.ts +684 -684
  16. package/src/base/BaseLineAreas.ts +629 -629
  17. package/src/base/BaseLines.ts +706 -706
  18. package/src/base/BaseRacingBars.ts +551 -551
  19. package/src/base/BaseRacingLabels.ts +396 -396
  20. package/src/base/BaseRacingValueLabels.ts +403 -403
  21. package/src/base/BaseStackedBars.ts +782 -782
  22. package/src/base/BaseTooltip.ts +386 -386
  23. package/src/base/BaseValueAxis.ts +600 -600
  24. package/src/base/BaseXAxis.ts +427 -427
  25. package/src/base/BaseYAxis.ts +389 -389
  26. package/src/base/types.ts +2 -2
  27. package/src/const.ts +30 -30
  28. package/src/grid/defaults.ts +213 -213
  29. package/src/grid/gridObservables.ts +612 -612
  30. package/src/grid/index.ts +16 -16
  31. package/src/grid/plugins/Bars.ts +69 -69
  32. package/src/grid/plugins/BarsPN.ts +66 -66
  33. package/src/grid/plugins/BarsTriangle.ts +73 -73
  34. package/src/grid/plugins/Dots.ts +68 -68
  35. package/src/grid/plugins/GridLegend.ts +107 -107
  36. package/src/grid/plugins/GridTooltip.ts +66 -66
  37. package/src/grid/plugins/GroupAux.ts +1120 -1120
  38. package/src/grid/plugins/GroupAxis.ts +73 -73
  39. package/src/grid/plugins/GroupZoom.ts +218 -218
  40. package/src/grid/plugins/LineAreas.ts +65 -65
  41. package/src/grid/plugins/Lines.ts +59 -59
  42. package/src/grid/plugins/StackedBars.ts +64 -64
  43. package/src/grid/plugins/StackedValueAxis.ts +96 -96
  44. package/src/grid/plugins/ValueAxis.ts +94 -94
  45. package/src/index.ts +6 -6
  46. package/src/multiGrid/defaults.ts +244 -244
  47. package/src/multiGrid/index.ts +14 -14
  48. package/src/multiGrid/multiGridObservables.ts +50 -50
  49. package/src/multiGrid/plugins/MultiBars.ts +108 -108
  50. package/src/multiGrid/plugins/MultiBarsTriangle.ts +114 -114
  51. package/src/multiGrid/plugins/MultiDots.ts +102 -102
  52. package/src/multiGrid/plugins/MultiGridLegend.ts +169 -169
  53. package/src/multiGrid/plugins/MultiGridTooltip.ts +66 -66
  54. package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
  55. package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
  56. package/src/multiGrid/plugins/MultiLines.ts +101 -101
  57. package/src/multiGrid/plugins/MultiStackedBars.ts +106 -106
  58. package/src/multiGrid/plugins/MultiStackedValueAxis.ts +134 -134
  59. package/src/multiGrid/plugins/MultiValueAxis.ts +134 -134
  60. package/src/multiGrid/plugins/OverlappingStackedValueAxes.ts +300 -300
  61. package/src/multiGrid/plugins/OverlappingValueAxes.ts +300 -300
  62. package/src/multiValue/defaults.ts +391 -388
  63. package/src/multiValue/index.ts +12 -12
  64. package/src/multiValue/multiValueObservables.ts +666 -666
  65. package/src/multiValue/plugins/MultiValueLegend.ts +107 -107
  66. package/src/multiValue/plugins/MultiValueTooltip.ts +66 -66
  67. package/src/multiValue/plugins/RacingBars.ts +373 -373
  68. package/src/multiValue/plugins/RacingCounterTexts.ts +300 -300
  69. package/src/multiValue/plugins/RacingValueAxis.ts +114 -114
  70. package/src/multiValue/plugins/RankingAxis_legacy.ts +109 -109
  71. package/src/multiValue/plugins/Scatter.ts +426 -426
  72. package/src/multiValue/plugins/ScatterBubbles.ts +554 -554
  73. package/src/multiValue/plugins/XAxis.ts +107 -107
  74. package/src/multiValue/plugins/XYAux.ts +682 -682
  75. package/src/multiValue/plugins/XYAxes.ts +194 -194
  76. package/src/multiValue/plugins/XYAxes_legacy.ts +683 -683
  77. package/src/multiValue/plugins/XZoom.ts +299 -299
  78. package/src/noneData/defaults.ts +102 -102
  79. package/src/noneData/index.ts +3 -3
  80. package/src/noneData/plugins/Container.ts +27 -27
  81. package/src/noneData/plugins/Tooltip.ts +373 -373
  82. package/src/relationship/defaults.ts +221 -220
  83. package/src/relationship/index.ts +5 -5
  84. package/src/relationship/plugins/ForceDirected.ts +1173 -1168
  85. package/src/relationship/plugins/ForceDirectedBubbles.ts +1411 -1403
  86. package/src/relationship/plugins/RelationshipLegend.ts +100 -100
  87. package/src/relationship/plugins/RelationshipTooltip.ts +66 -66
  88. package/src/relationship/relationshipObservables.ts +49 -49
  89. package/src/series/defaults.ts +221 -221
  90. package/src/series/index.ts +9 -9
  91. package/src/series/plugins/Bubbles.ts +636 -636
  92. package/src/series/plugins/Pie.ts +623 -623
  93. package/src/series/plugins/PieEventTexts.ts +284 -284
  94. package/src/series/plugins/PieLabels.ts +640 -640
  95. package/src/series/plugins/Rose.ts +516 -516
  96. package/src/series/plugins/RoseLabels.ts +600 -600
  97. package/src/series/plugins/SeriesLegend.ts +107 -107
  98. package/src/series/plugins/SeriesTooltip.ts +66 -66
  99. package/src/series/seriesObservables.ts +145 -145
  100. package/src/series/seriesUtils.ts +51 -51
  101. package/src/tree/defaults.ts +102 -102
  102. package/src/tree/index.ts +4 -4
  103. package/src/tree/plugins/TreeLegend.ts +100 -100
  104. package/src/tree/plugins/TreeMap.ts +341 -341
  105. package/src/tree/plugins/TreeTooltip.ts +66 -66
  106. package/src/utils/commonUtils.ts +31 -31
  107. package/src/utils/d3Graphics.ts +176 -176
  108. package/src/utils/d3Utils.ts +92 -92
  109. package/src/utils/observables.ts +14 -14
  110. package/src/utils/orbchartsUtils.ts +129 -129
  111. package/tsconfig.base.json +13 -13
  112. package/tsconfig.json +2 -2
  113. package/vite.config.js +22 -22
@@ -1,426 +1,426 @@
1
- import * as d3 from 'd3'
2
- import {
3
- combineLatest,
4
- map,
5
- switchMap,
6
- takeUntil,
7
- distinctUntilChanged,
8
- Observable,
9
- Subject
10
- } from 'rxjs'
11
- import type {
12
- ComputedDatumMultiValue,
13
- ComputedDataMultiValue,
14
- ComputedXYDataMultiValue,
15
- DefinePluginConfig,
16
- EventMultiValue,
17
- ChartParams,
18
- ContainerPositionScaled,
19
- Layout,
20
- TransformData,
21
- ColorType
22
- } from '../../../lib/core-types'
23
- import {
24
- defineMultiValuePlugin
25
- } from '../../../lib/core'
26
- import type { ScatterParams } from '../../../lib/plugins-basic-types'
27
- import { DEFAULT_SCATTER_PARAMS } from '../defaults'
28
- import { LAYER_INDEX_OF_GRAPHIC_COVER } from '../../const'
29
- import { getDatumColor, getClassName, getUniID } from '../../utils/orbchartsUtils'
30
- import { multiValueSelectionsObservable } from '../multiValueObservables'
31
-
32
- type ClipPathDatum = {
33
- id: string;
34
- // x: number;
35
- // y: number;
36
- width: number;
37
- height: number;
38
- }
39
-
40
- const pluginName = 'Scatter'
41
-
42
- const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_SCATTER_PARAMS> = {
43
- name: pluginName,
44
- defaultParams: DEFAULT_SCATTER_PARAMS,
45
- layerIndex: LAYER_INDEX_OF_GRAPHIC_COVER,
46
- validator: (params, { validateColumns }) => {
47
- const result = validateColumns(params, {
48
- radius: {
49
- toBeTypes: ['number']
50
- },
51
- fillColorType: {
52
- toBeOption: 'ColorType',
53
- },
54
- strokeColorType: {
55
- toBeOption: 'ColorType',
56
- },
57
- strokeWidth: {
58
- toBeTypes: ['number']
59
- },
60
- // strokeWidthWhileHighlight: {
61
- // toBeTypes: ['number']
62
- // },
63
- // onlyShowHighlighted: {
64
- // toBeTypes: ['boolean']
65
- // }
66
- })
67
- return result
68
- }
69
- }
70
-
71
- function renderDots ({ graphicGSelection, circleGClassName, circleClassName, visibleComputedXYData, fullParams, fullChartParams, graphicReverseScale }: {
72
- graphicGSelection: d3.Selection<SVGGElement, any, any, any>
73
- circleGClassName: string
74
- circleClassName: string
75
- visibleComputedXYData: ComputedXYDataMultiValue
76
- fullParams: ScatterParams
77
- fullChartParams: ChartParams
78
- graphicReverseScale: [number, number][]
79
- }) {
80
- const createEnterDuration = (enter: d3.Selection<d3.EnterElement, ComputedDatumMultiValue, SVGGElement, any>) => {
81
- const enterSize = enter.size()
82
- const eachDuration = fullChartParams.transitionDuration / enterSize
83
- return eachDuration
84
- }
85
- // enterDuration
86
- let enterDuration = 0
87
-
88
- graphicGSelection
89
- .each((categoryData, categoryIndex, g) => {
90
- d3.select(g[categoryIndex])
91
- .selectAll<SVGGElement, ComputedDatumMultiValue>('g')
92
- .data(visibleComputedXYData[categoryIndex], d => d.id)
93
- .join(
94
- enter => {
95
- // enterDuration
96
- enterDuration = createEnterDuration(enter)
97
-
98
- return enter
99
- .append('g')
100
- .classed(circleGClassName, true)
101
- },
102
- update => update,
103
- exit => exit.remove()
104
- )
105
- .attr('transform', d => `translate(${d.axisX}, ${d.axisY})`)
106
- .each((d, i, g) => {
107
- const circle = d3.select(g[i])
108
- .selectAll('circle')
109
- .data([d])
110
- .join(
111
- enter => {
112
- return enter
113
- .append('circle')
114
- .style('cursor', 'pointer')
115
- .style('vector-effect', 'non-scaling-stroke')
116
- .classed(circleClassName, true)
117
- .attr('opacity', 0)
118
- .transition()
119
- .delay((_d, _i) => {
120
- return i * enterDuration
121
- })
122
- .attr('opacity', 1)
123
- },
124
- update => {
125
- return update
126
- .transition()
127
- .duration(50)
128
- // .attr('cx', d => d.axisX)
129
- // .attr('cy', d => d.axisY)
130
- .attr('opacity', 1)
131
- },
132
- exit => exit.remove()
133
- )
134
- .attr('r', fullParams.radius)
135
- .attr('fill', (d, i) => getDatumColor({ datum: d, colorType: fullParams.fillColorType, fullChartParams }))
136
- .attr('stroke', (d, i) => getDatumColor({ datum: d, colorType: fullParams.strokeColorType, fullChartParams }))
137
- .attr('stroke-width', fullParams.strokeWidth)
138
- .attr('transform', `scale(${graphicReverseScale[categoryIndex][0] ?? 1}, ${graphicReverseScale[categoryIndex][1] ?? 1})`)
139
- })
140
- })
141
-
142
- const graphicCircleSelection: d3.Selection<SVGRectElement, ComputedDatumMultiValue, SVGGElement, unknown> = graphicGSelection.selectAll(`circle.${circleClassName}`)
143
-
144
- return graphicCircleSelection
145
- }
146
-
147
-
148
- function highlightDots ({ selection, ids, fullChartParams }: {
149
- selection: d3.Selection<SVGGElement, ComputedDatumMultiValue, any, any>
150
- ids: string[]
151
- fullChartParams: ChartParams
152
- }) {
153
- selection.interrupt('highlight')
154
- if (!ids.length) {
155
- // remove highlight
156
- selection
157
- .transition('highlight')
158
- .duration(200)
159
- .style('opacity', 1)
160
- // selection
161
- // .attr('stroke-width', fullParams.strokeWidth)
162
-
163
- return
164
- }
165
-
166
- selection
167
- .each((d, i, n) => {
168
- if (ids.includes(d.id)) {
169
- const dot = d3.select(n[i])
170
- dot
171
- .style('opacity', 1)
172
- .transition('highlight')
173
- .duration(200)
174
- // dot
175
- // .attr('stroke-width', fullParams.strokeWidthWhileHighlight)
176
- } else {
177
- const dot = d3.select(n[i])
178
- dot
179
- .style('opacity', fullChartParams.styles.unhighlightedOpacity)
180
- .transition('highlight')
181
- .duration(200)
182
- // dot
183
- // .attr('stroke-width', fullParams.strokeWidth)
184
-
185
- }
186
- })
187
- }
188
-
189
- function renderClipPath ({ defsSelection, clipPathData }: {
190
- defsSelection: d3.Selection<SVGDefsElement, any, any, any>
191
- clipPathData: ClipPathDatum[]
192
- }) {
193
- const clipPath = defsSelection
194
- .selectAll<SVGClipPathElement, Layout>('clipPath')
195
- .data(clipPathData)
196
- .join(
197
- enter => {
198
- return enter
199
- .append('clipPath')
200
- },
201
- update => update,
202
- exit => exit.remove()
203
- )
204
- .attr('id', d => d.id)
205
- .each((d, i, g) => {
206
- const rect = d3.select(g[i])
207
- .selectAll<SVGRectElement, typeof d>('rect')
208
- .data([d])
209
- .join('rect')
210
- .attr('x', 0)
211
- .attr('y', 0)
212
- .attr('width', _d => _d.width)
213
- .attr('height', _d => _d.height)
214
- })
215
-
216
- }
217
-
218
-
219
- export const Scatter = defineMultiValuePlugin(pluginConfig)(({ selection, name, subject, observer }) => {
220
-
221
- const destroy$ = new Subject()
222
-
223
- const clipPathID = getUniID(pluginName, 'clipPath-box')
224
- const circleGClassName = getClassName(pluginName, 'circleG')
225
- const circleClassName = getClassName(pluginName, 'circle')
226
-
227
- const {
228
- categorySelection$,
229
- axesSelection$,
230
- defsSelection$,
231
- graphicGSelection$
232
- } = multiValueSelectionsObservable({
233
- selection,
234
- pluginName,
235
- clipPathID,
236
- categoryLabels$: observer.categoryLabels$,
237
- containerPosition$: observer.containerPosition$,
238
- graphicTransform$: observer.graphicTransform$
239
- })
240
-
241
- const graphicReverseScale$: Observable<[number, number][]> = combineLatest({
242
- computedData: observer.computedData$,
243
- graphicReverseScale: observer.graphicReverseScale$
244
- }).pipe(
245
- takeUntil(destroy$),
246
- switchMap(async data => data),
247
- map(data => {
248
- return data.computedData.map((series, categoryIndex) => {
249
- return data.graphicReverseScale[categoryIndex]
250
- })
251
- })
252
- )
253
-
254
- const clipPathSubscription = combineLatest({
255
- defsSelection: defsSelection$,
256
- layout: observer.layout$,
257
- }).pipe(
258
- takeUntil(destroy$),
259
- switchMap(async (d) => d),
260
- ).subscribe(data => {
261
- // 外層的遮罩
262
- const clipPathData = [{
263
- id: clipPathID,
264
- width: data.layout.width,
265
- height: data.layout.height
266
- }]
267
- renderClipPath({
268
- defsSelection: data.defsSelection,
269
- clipPathData,
270
- })
271
- })
272
-
273
- const graphicSelection$ = combineLatest({
274
- graphicGSelection: graphicGSelection$,
275
- visibleComputedXYData: observer.visibleComputedXYData$,
276
- graphicReverseScale: graphicReverseScale$,
277
- fullChartParams: observer.fullChartParams$,
278
- fullParams: observer.fullParams$,
279
- }).pipe(
280
- takeUntil(destroy$),
281
- switchMap(async (d) => d),
282
- map(data => {
283
- return renderDots({
284
- graphicGSelection: data.graphicGSelection,
285
- circleGClassName,
286
- circleClassName,
287
- visibleComputedXYData: data.visibleComputedXYData,
288
- fullParams: data.fullParams,
289
- fullChartParams: data.fullChartParams,
290
- graphicReverseScale: data.graphicReverseScale
291
- })
292
- })
293
- )
294
-
295
- const highlightTarget$ = observer.fullChartParams$.pipe(
296
- takeUntil(destroy$),
297
- map(d => d.highlightTarget),
298
- distinctUntilChanged()
299
- )
300
-
301
- combineLatest({
302
- graphicSelection: graphicSelection$,
303
- computedData: observer.computedData$,
304
- CategoryDataMap: observer.CategoryDataMap$,
305
- highlightTarget: highlightTarget$
306
- }).pipe(
307
- takeUntil(destroy$),
308
- switchMap(async (d) => d),
309
- ).subscribe(data => {
310
-
311
- data.graphicSelection
312
- .on('mouseover', (event, datum) => {
313
- // event.stopPropagation()
314
- // console.log({
315
- // type: 'multiValue',
316
- // eventName: 'mouseover',
317
- // pluginName,
318
- // highlightTarget: data.highlightTarget,
319
- // datum,
320
- // category: data.CategoryDataMap.get(datum.categoryLabel)!,
321
- // categoryIndex: datum.categoryIndex,
322
- // categoryLabel: datum.categoryLabel,
323
- // data: data.computedData,
324
- // event,
325
- // })
326
- subject.event$.next({
327
- type: 'multiValue',
328
- eventName: 'mouseover',
329
- pluginName,
330
- highlightTarget: data.highlightTarget,
331
- datum,
332
- category: data.CategoryDataMap.get(datum.categoryLabel)!,
333
- categoryIndex: datum.categoryIndex,
334
- categoryLabel: datum.categoryLabel,
335
- data: data.computedData,
336
- event,
337
- })
338
- })
339
- .on('mousemove', (event, datum) => {
340
- // event.stopPropagation()
341
-
342
- subject.event$.next({
343
- type: 'multiValue',
344
- eventName: 'mousemove',
345
- pluginName,
346
- highlightTarget: data.highlightTarget,
347
- datum,
348
- category: data.CategoryDataMap.get(datum.categoryLabel)!,
349
- categoryIndex: datum.categoryIndex,
350
- categoryLabel: datum.categoryLabel,
351
- data: data.computedData,
352
- event,
353
- })
354
- })
355
- .on('mouseout', (event, datum) => {
356
- // event.stopPropagation()
357
-
358
- subject.event$.next({
359
- type: 'multiValue',
360
- eventName: 'mouseout',
361
- pluginName,
362
- highlightTarget: data.highlightTarget,
363
- datum,
364
- category: data.CategoryDataMap.get(datum.categoryLabel)!,
365
- categoryIndex: datum.categoryIndex,
366
- categoryLabel: datum.categoryLabel,
367
- data: data.computedData,
368
- event,
369
- })
370
- })
371
- .on('click', (event, datum) => {
372
- // event.stopPropagation()
373
-
374
- subject.event$.next({
375
- type: 'multiValue',
376
- eventName: 'click',
377
- pluginName,
378
- highlightTarget: data.highlightTarget,
379
- datum,
380
- category: data.CategoryDataMap.get(datum.categoryLabel)!,
381
- categoryIndex: datum.categoryIndex,
382
- categoryLabel: datum.categoryLabel,
383
- data: data.computedData,
384
- event,
385
- })
386
- })
387
-
388
- })
389
-
390
- combineLatest({
391
- graphicSelection: graphicSelection$,
392
- highlight: observer.highlight$.pipe(
393
- map(data => data.map(d => d.id))
394
- ),
395
- fullChartParams: observer.fullChartParams$
396
- }).pipe(
397
- takeUntil(destroy$),
398
- switchMap(async d => d)
399
- ).subscribe(data => {
400
- highlightDots({
401
- selection: data.graphicSelection,
402
- ids: data.highlight,
403
- fullChartParams: data.fullChartParams
404
- })
405
- })
406
-
407
- // graphicGSelection$.subscribe(data => {
408
- // console.log('graphicGSelection$', data)
409
- // })
410
-
411
- // observer.visibleComputedXYData$.subscribe(data => {
412
- // console.log('visibleComputedXYData$', data)
413
- // })
414
-
415
- // observer.fullChartParams$.subscribe(data => {
416
- // console.log('fullChartParams$', data)
417
- // })
418
-
419
- // observer.fullParams$.subscribe(data => {
420
- // console.log('fullParams$', data)
421
- // })
422
-
423
- return () => {
424
- destroy$.next(undefined)
425
- }
426
- })
1
+ import * as d3 from 'd3'
2
+ import {
3
+ combineLatest,
4
+ map,
5
+ switchMap,
6
+ takeUntil,
7
+ distinctUntilChanged,
8
+ Observable,
9
+ Subject
10
+ } from 'rxjs'
11
+ import type {
12
+ ComputedDatumMultiValue,
13
+ ComputedDataMultiValue,
14
+ ComputedXYDataMultiValue,
15
+ DefinePluginConfig,
16
+ EventMultiValue,
17
+ ChartParams,
18
+ ContainerPositionScaled,
19
+ Layout,
20
+ TransformData,
21
+ ColorType
22
+ } from '../../../lib/core-types'
23
+ import {
24
+ defineMultiValuePlugin
25
+ } from '../../../lib/core'
26
+ import type { ScatterParams } from '../../../lib/plugins-basic-types'
27
+ import { DEFAULT_SCATTER_PARAMS } from '../defaults'
28
+ import { LAYER_INDEX_OF_GRAPHIC_COVER } from '../../const'
29
+ import { getDatumColor, getClassName, getUniID } from '../../utils/orbchartsUtils'
30
+ import { multiValueSelectionsObservable } from '../multiValueObservables'
31
+
32
+ type ClipPathDatum = {
33
+ id: string;
34
+ // x: number;
35
+ // y: number;
36
+ width: number;
37
+ height: number;
38
+ }
39
+
40
+ const pluginName = 'Scatter'
41
+
42
+ const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_SCATTER_PARAMS> = {
43
+ name: pluginName,
44
+ defaultParams: DEFAULT_SCATTER_PARAMS,
45
+ layerIndex: LAYER_INDEX_OF_GRAPHIC_COVER,
46
+ validator: (params, { validateColumns }) => {
47
+ const result = validateColumns(params, {
48
+ radius: {
49
+ toBeTypes: ['number']
50
+ },
51
+ fillColorType: {
52
+ toBeOption: 'ColorType',
53
+ },
54
+ strokeColorType: {
55
+ toBeOption: 'ColorType',
56
+ },
57
+ strokeWidth: {
58
+ toBeTypes: ['number']
59
+ },
60
+ // strokeWidthWhileHighlight: {
61
+ // toBeTypes: ['number']
62
+ // },
63
+ // onlyShowHighlighted: {
64
+ // toBeTypes: ['boolean']
65
+ // }
66
+ })
67
+ return result
68
+ }
69
+ }
70
+
71
+ function renderDots ({ graphicGSelection, circleGClassName, circleClassName, visibleComputedXYData, fullParams, fullChartParams, graphicReverseScale }: {
72
+ graphicGSelection: d3.Selection<SVGGElement, any, any, any>
73
+ circleGClassName: string
74
+ circleClassName: string
75
+ visibleComputedXYData: ComputedXYDataMultiValue
76
+ fullParams: ScatterParams
77
+ fullChartParams: ChartParams
78
+ graphicReverseScale: [number, number][]
79
+ }) {
80
+ const createEnterDuration = (enter: d3.Selection<d3.EnterElement, ComputedDatumMultiValue, SVGGElement, any>) => {
81
+ const enterSize = enter.size()
82
+ const eachDuration = fullChartParams.transitionDuration / enterSize
83
+ return eachDuration
84
+ }
85
+ // enterDuration
86
+ let enterDuration = 0
87
+
88
+ graphicGSelection
89
+ .each((categoryData, categoryIndex, g) => {
90
+ d3.select(g[categoryIndex])
91
+ .selectAll<SVGGElement, ComputedDatumMultiValue>('g')
92
+ .data(visibleComputedXYData[categoryIndex], d => d.id)
93
+ .join(
94
+ enter => {
95
+ // enterDuration
96
+ enterDuration = createEnterDuration(enter)
97
+
98
+ return enter
99
+ .append('g')
100
+ .classed(circleGClassName, true)
101
+ },
102
+ update => update,
103
+ exit => exit.remove()
104
+ )
105
+ .attr('transform', d => `translate(${d.axisX}, ${d.axisY})`)
106
+ .each((d, i, g) => {
107
+ const circle = d3.select(g[i])
108
+ .selectAll('circle')
109
+ .data([d])
110
+ .join(
111
+ enter => {
112
+ return enter
113
+ .append('circle')
114
+ .style('cursor', 'pointer')
115
+ .style('vector-effect', 'non-scaling-stroke')
116
+ .classed(circleClassName, true)
117
+ .attr('opacity', 0)
118
+ .transition()
119
+ .delay((_d, _i) => {
120
+ return i * enterDuration
121
+ })
122
+ .attr('opacity', 1)
123
+ },
124
+ update => {
125
+ return update
126
+ .transition()
127
+ .duration(50)
128
+ // .attr('cx', d => d.axisX)
129
+ // .attr('cy', d => d.axisY)
130
+ .attr('opacity', 1)
131
+ },
132
+ exit => exit.remove()
133
+ )
134
+ .attr('r', fullParams.radius)
135
+ .attr('fill', (d, i) => getDatumColor({ datum: d, colorType: fullParams.fillColorType, fullChartParams }))
136
+ .attr('stroke', (d, i) => getDatumColor({ datum: d, colorType: fullParams.strokeColorType, fullChartParams }))
137
+ .attr('stroke-width', fullParams.strokeWidth)
138
+ .attr('transform', `scale(${graphicReverseScale[categoryIndex][0] ?? 1}, ${graphicReverseScale[categoryIndex][1] ?? 1})`)
139
+ })
140
+ })
141
+
142
+ const graphicCircleSelection: d3.Selection<SVGRectElement, ComputedDatumMultiValue, SVGGElement, unknown> = graphicGSelection.selectAll(`circle.${circleClassName}`)
143
+
144
+ return graphicCircleSelection
145
+ }
146
+
147
+
148
+ function highlightDots ({ selection, ids, fullChartParams }: {
149
+ selection: d3.Selection<SVGGElement, ComputedDatumMultiValue, any, any>
150
+ ids: string[]
151
+ fullChartParams: ChartParams
152
+ }) {
153
+ selection.interrupt('highlight')
154
+ if (!ids.length) {
155
+ // remove highlight
156
+ selection
157
+ .transition('highlight')
158
+ .duration(200)
159
+ .style('opacity', 1)
160
+ // selection
161
+ // .attr('stroke-width', fullParams.strokeWidth)
162
+
163
+ return
164
+ }
165
+
166
+ selection
167
+ .each((d, i, n) => {
168
+ if (ids.includes(d.id)) {
169
+ const dot = d3.select(n[i])
170
+ dot
171
+ .style('opacity', 1)
172
+ .transition('highlight')
173
+ .duration(200)
174
+ // dot
175
+ // .attr('stroke-width', fullParams.strokeWidthWhileHighlight)
176
+ } else {
177
+ const dot = d3.select(n[i])
178
+ dot
179
+ .style('opacity', fullChartParams.styles.unhighlightedOpacity)
180
+ .transition('highlight')
181
+ .duration(200)
182
+ // dot
183
+ // .attr('stroke-width', fullParams.strokeWidth)
184
+
185
+ }
186
+ })
187
+ }
188
+
189
+ function renderClipPath ({ defsSelection, clipPathData }: {
190
+ defsSelection: d3.Selection<SVGDefsElement, any, any, any>
191
+ clipPathData: ClipPathDatum[]
192
+ }) {
193
+ const clipPath = defsSelection
194
+ .selectAll<SVGClipPathElement, Layout>('clipPath')
195
+ .data(clipPathData)
196
+ .join(
197
+ enter => {
198
+ return enter
199
+ .append('clipPath')
200
+ },
201
+ update => update,
202
+ exit => exit.remove()
203
+ )
204
+ .attr('id', d => d.id)
205
+ .each((d, i, g) => {
206
+ const rect = d3.select(g[i])
207
+ .selectAll<SVGRectElement, typeof d>('rect')
208
+ .data([d])
209
+ .join('rect')
210
+ .attr('x', 0)
211
+ .attr('y', 0)
212
+ .attr('width', _d => _d.width)
213
+ .attr('height', _d => _d.height)
214
+ })
215
+
216
+ }
217
+
218
+
219
+ export const Scatter = defineMultiValuePlugin(pluginConfig)(({ selection, name, subject, observer }) => {
220
+
221
+ const destroy$ = new Subject()
222
+
223
+ const clipPathID = getUniID(pluginName, 'clipPath-box')
224
+ const circleGClassName = getClassName(pluginName, 'circleG')
225
+ const circleClassName = getClassName(pluginName, 'circle')
226
+
227
+ const {
228
+ categorySelection$,
229
+ axesSelection$,
230
+ defsSelection$,
231
+ graphicGSelection$
232
+ } = multiValueSelectionsObservable({
233
+ selection,
234
+ pluginName,
235
+ clipPathID,
236
+ categoryLabels$: observer.categoryLabels$,
237
+ containerPosition$: observer.containerPosition$,
238
+ graphicTransform$: observer.graphicTransform$
239
+ })
240
+
241
+ const graphicReverseScale$: Observable<[number, number][]> = combineLatest({
242
+ computedData: observer.computedData$,
243
+ graphicReverseScale: observer.graphicReverseScale$
244
+ }).pipe(
245
+ takeUntil(destroy$),
246
+ switchMap(async data => data),
247
+ map(data => {
248
+ return data.computedData.map((series, categoryIndex) => {
249
+ return data.graphicReverseScale[categoryIndex]
250
+ })
251
+ })
252
+ )
253
+
254
+ const clipPathSubscription = combineLatest({
255
+ defsSelection: defsSelection$,
256
+ layout: observer.layout$,
257
+ }).pipe(
258
+ takeUntil(destroy$),
259
+ switchMap(async (d) => d),
260
+ ).subscribe(data => {
261
+ // 外層的遮罩
262
+ const clipPathData = [{
263
+ id: clipPathID,
264
+ width: data.layout.width,
265
+ height: data.layout.height
266
+ }]
267
+ renderClipPath({
268
+ defsSelection: data.defsSelection,
269
+ clipPathData,
270
+ })
271
+ })
272
+
273
+ const graphicSelection$ = combineLatest({
274
+ graphicGSelection: graphicGSelection$,
275
+ visibleComputedXYData: observer.visibleComputedXYData$,
276
+ graphicReverseScale: graphicReverseScale$,
277
+ fullChartParams: observer.fullChartParams$,
278
+ fullParams: observer.fullParams$,
279
+ }).pipe(
280
+ takeUntil(destroy$),
281
+ switchMap(async (d) => d),
282
+ map(data => {
283
+ return renderDots({
284
+ graphicGSelection: data.graphicGSelection,
285
+ circleGClassName,
286
+ circleClassName,
287
+ visibleComputedXYData: data.visibleComputedXYData,
288
+ fullParams: data.fullParams,
289
+ fullChartParams: data.fullChartParams,
290
+ graphicReverseScale: data.graphicReverseScale
291
+ })
292
+ })
293
+ )
294
+
295
+ const highlightTarget$ = observer.fullChartParams$.pipe(
296
+ takeUntil(destroy$),
297
+ map(d => d.highlightTarget),
298
+ distinctUntilChanged()
299
+ )
300
+
301
+ combineLatest({
302
+ graphicSelection: graphicSelection$,
303
+ computedData: observer.computedData$,
304
+ CategoryDataMap: observer.CategoryDataMap$,
305
+ highlightTarget: highlightTarget$
306
+ }).pipe(
307
+ takeUntil(destroy$),
308
+ switchMap(async (d) => d),
309
+ ).subscribe(data => {
310
+
311
+ data.graphicSelection
312
+ .on('mouseover', (event, datum) => {
313
+ // event.stopPropagation()
314
+ // console.log({
315
+ // type: 'multiValue',
316
+ // eventName: 'mouseover',
317
+ // pluginName,
318
+ // highlightTarget: data.highlightTarget,
319
+ // datum,
320
+ // category: data.CategoryDataMap.get(datum.categoryLabel)!,
321
+ // categoryIndex: datum.categoryIndex,
322
+ // categoryLabel: datum.categoryLabel,
323
+ // data: data.computedData,
324
+ // event,
325
+ // })
326
+ subject.event$.next({
327
+ type: 'multiValue',
328
+ eventName: 'mouseover',
329
+ pluginName,
330
+ highlightTarget: data.highlightTarget,
331
+ datum,
332
+ category: data.CategoryDataMap.get(datum.categoryLabel)!,
333
+ categoryIndex: datum.categoryIndex,
334
+ categoryLabel: datum.categoryLabel,
335
+ data: data.computedData,
336
+ event,
337
+ })
338
+ })
339
+ .on('mousemove', (event, datum) => {
340
+ // event.stopPropagation()
341
+
342
+ subject.event$.next({
343
+ type: 'multiValue',
344
+ eventName: 'mousemove',
345
+ pluginName,
346
+ highlightTarget: data.highlightTarget,
347
+ datum,
348
+ category: data.CategoryDataMap.get(datum.categoryLabel)!,
349
+ categoryIndex: datum.categoryIndex,
350
+ categoryLabel: datum.categoryLabel,
351
+ data: data.computedData,
352
+ event,
353
+ })
354
+ })
355
+ .on('mouseout', (event, datum) => {
356
+ // event.stopPropagation()
357
+
358
+ subject.event$.next({
359
+ type: 'multiValue',
360
+ eventName: 'mouseout',
361
+ pluginName,
362
+ highlightTarget: data.highlightTarget,
363
+ datum,
364
+ category: data.CategoryDataMap.get(datum.categoryLabel)!,
365
+ categoryIndex: datum.categoryIndex,
366
+ categoryLabel: datum.categoryLabel,
367
+ data: data.computedData,
368
+ event,
369
+ })
370
+ })
371
+ .on('click', (event, datum) => {
372
+ // event.stopPropagation()
373
+
374
+ subject.event$.next({
375
+ type: 'multiValue',
376
+ eventName: 'click',
377
+ pluginName,
378
+ highlightTarget: data.highlightTarget,
379
+ datum,
380
+ category: data.CategoryDataMap.get(datum.categoryLabel)!,
381
+ categoryIndex: datum.categoryIndex,
382
+ categoryLabel: datum.categoryLabel,
383
+ data: data.computedData,
384
+ event,
385
+ })
386
+ })
387
+
388
+ })
389
+
390
+ combineLatest({
391
+ graphicSelection: graphicSelection$,
392
+ highlight: observer.highlight$.pipe(
393
+ map(data => data.map(d => d.id))
394
+ ),
395
+ fullChartParams: observer.fullChartParams$
396
+ }).pipe(
397
+ takeUntil(destroy$),
398
+ switchMap(async d => d)
399
+ ).subscribe(data => {
400
+ highlightDots({
401
+ selection: data.graphicSelection,
402
+ ids: data.highlight,
403
+ fullChartParams: data.fullChartParams
404
+ })
405
+ })
406
+
407
+ // graphicGSelection$.subscribe(data => {
408
+ // console.log('graphicGSelection$', data)
409
+ // })
410
+
411
+ // observer.visibleComputedXYData$.subscribe(data => {
412
+ // console.log('visibleComputedXYData$', data)
413
+ // })
414
+
415
+ // observer.fullChartParams$.subscribe(data => {
416
+ // console.log('fullChartParams$', data)
417
+ // })
418
+
419
+ // observer.fullParams$.subscribe(data => {
420
+ // console.log('fullParams$', data)
421
+ // })
422
+
423
+ return () => {
424
+ destroy$.next(undefined)
425
+ }
426
+ })