@orbcharts/plugins-basic 3.0.0-beta.10 → 3.0.0-beta.11

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 (99) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-plugins-basic.es.js +177 -177
  3. package/dist/orbcharts-plugins-basic.umd.js +55 -55
  4. package/lib/core-types.ts +7 -7
  5. package/lib/core.ts +6 -6
  6. package/lib/plugins-basic-types.ts +6 -6
  7. package/package.json +44 -44
  8. package/src/base/BaseBars.ts +765 -765
  9. package/src/base/BaseBarsTriangle.ts +676 -676
  10. package/src/base/BaseDots.ts +464 -464
  11. package/src/base/BaseGroupAxis.ts +679 -679
  12. package/src/base/BaseLegend.ts +684 -684
  13. package/src/base/BaseLineAreas.ts +629 -629
  14. package/src/base/BaseLines.ts +706 -706
  15. package/src/base/BaseStackedBar.ts +782 -782
  16. package/src/base/BaseTooltip.ts +385 -385
  17. package/src/base/BaseValueAxis.ts +583 -583
  18. package/src/base/types.ts +2 -2
  19. package/src/const.ts +30 -30
  20. package/src/grid/defaults.ts +246 -246
  21. package/src/grid/gridObservables.ts +554 -554
  22. package/src/grid/index.ts +16 -16
  23. package/src/grid/plugins/Bars.ts +69 -69
  24. package/src/grid/plugins/BarsPN.ts +66 -66
  25. package/src/grid/plugins/BarsTriangle.ts +73 -73
  26. package/src/grid/plugins/Dots.ts +68 -68
  27. package/src/grid/plugins/GridLegend.ts +107 -107
  28. package/src/grid/plugins/GridTooltip.ts +66 -66
  29. package/src/grid/plugins/GridZoom.ts +218 -218
  30. package/src/grid/plugins/GroupAux.ts +1103 -1103
  31. package/src/grid/plugins/GroupAxis.ts +97 -97
  32. package/src/grid/plugins/LineAreas.ts +65 -65
  33. package/src/grid/plugins/Lines.ts +59 -59
  34. package/src/grid/plugins/StackedBar.ts +64 -64
  35. package/src/grid/plugins/StackedValueAxis.ts +96 -96
  36. package/src/grid/plugins/ValueAxis.ts +94 -94
  37. package/src/index.ts +6 -6
  38. package/src/multiGrid/defaults.ts +224 -224
  39. package/src/multiGrid/index.ts +14 -14
  40. package/src/multiGrid/multiGridObservables.ts +49 -49
  41. package/src/multiGrid/plugins/MultiBars.ts +108 -108
  42. package/src/multiGrid/plugins/MultiBarsTriangle.ts +114 -114
  43. package/src/multiGrid/plugins/MultiDots.ts +102 -102
  44. package/src/multiGrid/plugins/MultiGridLegend.ts +159 -159
  45. package/src/multiGrid/plugins/MultiGridTooltip.ts +66 -66
  46. package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
  47. package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
  48. package/src/multiGrid/plugins/MultiLines.ts +101 -101
  49. package/src/multiGrid/plugins/MultiStackedBar.ts +106 -106
  50. package/src/multiGrid/plugins/MultiStackedValueAxis.ts +134 -134
  51. package/src/multiGrid/plugins/MultiValueAxis.ts +134 -134
  52. package/src/multiGrid/plugins/OverlappingStackedValueAxes.ts +299 -299
  53. package/src/multiGrid/plugins/OverlappingValueAxes.ts +300 -300
  54. package/src/multiValue/defaults.ts +166 -166
  55. package/src/multiValue/index.ts +8 -8
  56. package/src/multiValue/multiValueObservables.ts +297 -297
  57. package/src/multiValue/plugins/MultiValueLegend.ts +107 -107
  58. package/src/multiValue/plugins/MultiValueTooltip.ts +66 -66
  59. package/src/multiValue/plugins/Scatter.ts +426 -426
  60. package/src/multiValue/plugins/ScatterBubbles.ts +554 -554
  61. package/src/multiValue/plugins/XYAux.ts +681 -681
  62. package/src/multiValue/plugins/XYAxes.ts +684 -684
  63. package/src/multiValue/plugins/XYZoom.ts +299 -299
  64. package/src/noneData/defaults.ts +102 -102
  65. package/src/noneData/index.ts +3 -3
  66. package/src/noneData/plugins/Container.ts +27 -27
  67. package/src/noneData/plugins/Tooltip.ts +373 -373
  68. package/src/relationship/defaults.ts +196 -195
  69. package/src/relationship/index.ts +5 -5
  70. package/src/relationship/plugins/ForceDirected.ts +1168 -1166
  71. package/src/relationship/plugins/ForceDirectedBubbles.ts +1393 -1390
  72. package/src/relationship/plugins/RelationshipLegend.ts +100 -100
  73. package/src/relationship/plugins/RelationshipTooltip.ts +66 -66
  74. package/src/relationship/relationshipObservables.ts +49 -49
  75. package/src/series/defaults.ts +207 -206
  76. package/src/series/index.ts +9 -9
  77. package/src/series/plugins/Bubbles.ts +603 -606
  78. package/src/series/plugins/Pie.ts +623 -623
  79. package/src/series/plugins/PieEventTexts.ts +284 -284
  80. package/src/series/plugins/PieLabels.ts +640 -640
  81. package/src/series/plugins/Rose.ts +516 -516
  82. package/src/series/plugins/RoseLabels.ts +600 -600
  83. package/src/series/plugins/SeriesLegend.ts +107 -107
  84. package/src/series/plugins/SeriesTooltip.ts +66 -66
  85. package/src/series/seriesObservables.ts +145 -145
  86. package/src/series/seriesUtils.ts +51 -51
  87. package/src/tree/defaults.ts +78 -78
  88. package/src/tree/index.ts +4 -4
  89. package/src/tree/plugins/TreeLegend.ts +100 -100
  90. package/src/tree/plugins/TreeMap.ts +333 -333
  91. package/src/tree/plugins/TreeTooltip.ts +66 -66
  92. package/src/utils/commonUtils.ts +21 -21
  93. package/src/utils/d3Graphics.ts +174 -174
  94. package/src/utils/d3Utils.ts +74 -74
  95. package/src/utils/observables.ts +14 -14
  96. package/src/utils/orbchartsUtils.ts +115 -115
  97. package/tsconfig.base.json +13 -13
  98. package/tsconfig.json +2 -2
  99. 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
- ComputedLayoutDataMultiValue,
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, visibleComputedLayoutData, fullParams, fullChartParams, graphicReverseScale }: {
72
- graphicGSelection: d3.Selection<SVGGElement, any, any, any>
73
- circleGClassName: string
74
- circleClassName: string
75
- visibleComputedLayoutData: ComputedLayoutDataMultiValue
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(visibleComputedLayoutData[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
- multiValueContainerPosition$: observer.multiValueContainerPosition$,
238
- multiValueGraphicTransform$: observer.multiValueGraphicTransform$
239
- })
240
-
241
- const graphicReverseScale$: Observable<[number, number][]> = combineLatest({
242
- computedData: observer.computedData$,
243
- multiValueGraphicReverseScale: observer.multiValueGraphicReverseScale$
244
- }).pipe(
245
- takeUntil(destroy$),
246
- switchMap(async data => data),
247
- map(data => {
248
- return data.computedData.map((series, categoryIndex) => {
249
- return data.multiValueGraphicReverseScale[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
- visibleComputedLayoutData: observer.visibleComputedLayoutData$,
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
- visibleComputedLayoutData: data.visibleComputedLayoutData,
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.multiValueHighlight$.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.visibleComputedLayoutData$.subscribe(data => {
412
- // console.log('visibleComputedLayoutData$', 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
+ ComputedLayoutDataMultiValue,
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, visibleComputedLayoutData, fullParams, fullChartParams, graphicReverseScale }: {
72
+ graphicGSelection: d3.Selection<SVGGElement, any, any, any>
73
+ circleGClassName: string
74
+ circleClassName: string
75
+ visibleComputedLayoutData: ComputedLayoutDataMultiValue
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(visibleComputedLayoutData[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
+ multiValueContainerPosition$: observer.multiValueContainerPosition$,
238
+ multiValueGraphicTransform$: observer.multiValueGraphicTransform$
239
+ })
240
+
241
+ const graphicReverseScale$: Observable<[number, number][]> = combineLatest({
242
+ computedData: observer.computedData$,
243
+ multiValueGraphicReverseScale: observer.multiValueGraphicReverseScale$
244
+ }).pipe(
245
+ takeUntil(destroy$),
246
+ switchMap(async data => data),
247
+ map(data => {
248
+ return data.computedData.map((series, categoryIndex) => {
249
+ return data.multiValueGraphicReverseScale[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
+ visibleComputedLayoutData: observer.visibleComputedLayoutData$,
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
+ visibleComputedLayoutData: data.visibleComputedLayoutData,
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.multiValueHighlight$.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.visibleComputedLayoutData$.subscribe(data => {
412
+ // console.log('visibleComputedLayoutData$', 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
+ })