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

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 (112) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-plugins-basic.es.js +10763 -10611
  3. package/dist/orbcharts-plugins-basic.umd.js +208 -148
  4. package/dist/src/utils/commonUtils.d.ts +1 -0
  5. package/dist/src/utils/d3Graphics.d.ts +2 -1
  6. package/lib/core-types.ts +7 -7
  7. package/lib/core.ts +6 -6
  8. package/lib/plugins-basic-types.ts +6 -6
  9. package/package.json +44 -44
  10. package/src/base/BaseBars.ts +765 -765
  11. package/src/base/BaseBarsTriangle.ts +676 -676
  12. package/src/base/BaseDots.ts +464 -464
  13. package/src/base/BaseGroupAxis.ts +691 -681
  14. package/src/base/BaseLegend.ts +684 -684
  15. package/src/base/BaseLineAreas.ts +629 -629
  16. package/src/base/BaseLines.ts +706 -706
  17. package/src/base/BaseRacingBars.ts +551 -551
  18. package/src/base/BaseRacingLabels.ts +396 -392
  19. package/src/base/BaseRacingValueLabels.ts +403 -403
  20. package/src/base/BaseStackedBars.ts +782 -782
  21. package/src/base/BaseTooltip.ts +386 -385
  22. package/src/base/BaseValueAxis.ts +600 -600
  23. package/src/base/BaseXAxis.ts +427 -427
  24. package/src/base/BaseYAxis.ts +389 -389
  25. package/src/base/types.ts +2 -2
  26. package/src/const.ts +30 -30
  27. package/src/grid/defaults.ts +213 -198
  28. package/src/grid/gridObservables.ts +612 -612
  29. package/src/grid/index.ts +16 -16
  30. package/src/grid/plugins/Bars.ts +69 -69
  31. package/src/grid/plugins/BarsPN.ts +66 -66
  32. package/src/grid/plugins/BarsTriangle.ts +73 -73
  33. package/src/grid/plugins/Dots.ts +68 -68
  34. package/src/grid/plugins/GridLegend.ts +107 -107
  35. package/src/grid/plugins/GridTooltip.ts +66 -66
  36. package/src/grid/plugins/GroupAux.ts +1120 -1103
  37. package/src/grid/plugins/GroupAxis.ts +73 -73
  38. package/src/grid/plugins/GroupZoom.ts +218 -218
  39. package/src/grid/plugins/LineAreas.ts +65 -65
  40. package/src/grid/plugins/Lines.ts +59 -59
  41. package/src/grid/plugins/StackedBars.ts +64 -64
  42. package/src/grid/plugins/StackedValueAxis.ts +96 -96
  43. package/src/grid/plugins/ValueAxis.ts +94 -94
  44. package/src/index.ts +6 -6
  45. package/src/multiGrid/defaults.ts +244 -228
  46. package/src/multiGrid/index.ts +14 -14
  47. package/src/multiGrid/multiGridObservables.ts +50 -50
  48. package/src/multiGrid/plugins/MultiBars.ts +108 -108
  49. package/src/multiGrid/plugins/MultiBarsTriangle.ts +114 -114
  50. package/src/multiGrid/plugins/MultiDots.ts +102 -102
  51. package/src/multiGrid/plugins/MultiGridLegend.ts +169 -169
  52. package/src/multiGrid/plugins/MultiGridTooltip.ts +66 -66
  53. package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
  54. package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
  55. package/src/multiGrid/plugins/MultiLines.ts +101 -101
  56. package/src/multiGrid/plugins/MultiStackedBars.ts +106 -106
  57. package/src/multiGrid/plugins/MultiStackedValueAxis.ts +134 -134
  58. package/src/multiGrid/plugins/MultiValueAxis.ts +134 -134
  59. package/src/multiGrid/plugins/OverlappingStackedValueAxes.ts +300 -300
  60. package/src/multiGrid/plugins/OverlappingValueAxes.ts +300 -300
  61. package/src/multiValue/defaults.ts +388 -299
  62. package/src/multiValue/index.ts +12 -12
  63. package/src/multiValue/multiValueObservables.ts +666 -666
  64. package/src/multiValue/plugins/MultiValueLegend.ts +107 -107
  65. package/src/multiValue/plugins/MultiValueTooltip.ts +66 -66
  66. package/src/multiValue/plugins/RacingBars.ts +373 -362
  67. package/src/multiValue/plugins/RacingCounterTexts.ts +300 -300
  68. package/src/multiValue/plugins/RacingValueAxis.ts +114 -114
  69. package/src/multiValue/plugins/RankingAxis_legacy.ts +109 -109
  70. package/src/multiValue/plugins/Scatter.ts +426 -426
  71. package/src/multiValue/plugins/ScatterBubbles.ts +554 -554
  72. package/src/multiValue/plugins/XAxis.ts +107 -107
  73. package/src/multiValue/plugins/XYAux.ts +682 -681
  74. package/src/multiValue/plugins/XYAxes.ts +194 -194
  75. package/src/multiValue/plugins/XYAxes_legacy.ts +683 -683
  76. package/src/multiValue/plugins/XZoom.ts +299 -299
  77. package/src/noneData/defaults.ts +102 -102
  78. package/src/noneData/index.ts +3 -3
  79. package/src/noneData/plugins/Container.ts +27 -27
  80. package/src/noneData/plugins/Tooltip.ts +373 -373
  81. package/src/relationship/defaults.ts +220 -218
  82. package/src/relationship/index.ts +5 -5
  83. package/src/relationship/plugins/ForceDirected.ts +1168 -1168
  84. package/src/relationship/plugins/ForceDirectedBubbles.ts +1403 -1403
  85. package/src/relationship/plugins/RelationshipLegend.ts +100 -100
  86. package/src/relationship/plugins/RelationshipTooltip.ts +66 -66
  87. package/src/relationship/relationshipObservables.ts +49 -49
  88. package/src/series/defaults.ts +221 -219
  89. package/src/series/index.ts +9 -9
  90. package/src/series/plugins/Bubbles.ts +636 -636
  91. package/src/series/plugins/Pie.ts +623 -623
  92. package/src/series/plugins/PieEventTexts.ts +284 -284
  93. package/src/series/plugins/PieLabels.ts +640 -640
  94. package/src/series/plugins/Rose.ts +516 -516
  95. package/src/series/plugins/RoseLabels.ts +600 -600
  96. package/src/series/plugins/SeriesLegend.ts +107 -107
  97. package/src/series/plugins/SeriesTooltip.ts +66 -66
  98. package/src/series/seriesObservables.ts +145 -145
  99. package/src/series/seriesUtils.ts +51 -51
  100. package/src/tree/defaults.ts +102 -100
  101. package/src/tree/index.ts +4 -4
  102. package/src/tree/plugins/TreeLegend.ts +100 -100
  103. package/src/tree/plugins/TreeMap.ts +341 -341
  104. package/src/tree/plugins/TreeTooltip.ts +66 -66
  105. package/src/utils/commonUtils.ts +31 -22
  106. package/src/utils/d3Graphics.ts +176 -174
  107. package/src/utils/d3Utils.ts +92 -92
  108. package/src/utils/observables.ts +14 -14
  109. package/src/utils/orbchartsUtils.ts +129 -129
  110. package/tsconfig.base.json +13 -13
  111. package/tsconfig.json +2 -2
  112. 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
+ })