@orbcharts/plugins-basic 3.0.0-beta.13 → 3.0.0-beta.14

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 (100) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-plugins-basic/src/utils/d3Utils.d.ts +1 -0
  3. package/dist/orbcharts-plugins-basic.es.js +5558 -5443
  4. package/dist/orbcharts-plugins-basic.umd.js +159 -78
  5. package/lib/core-types.ts +7 -7
  6. package/lib/core.ts +6 -6
  7. package/lib/plugins-basic-types.ts +6 -6
  8. package/package.json +44 -44
  9. package/src/base/BaseBars.ts +765 -765
  10. package/src/base/BaseBarsTriangle.ts +676 -676
  11. package/src/base/BaseDots.ts +464 -464
  12. package/src/base/BaseGroupAxis.ts +679 -679
  13. package/src/base/BaseLegend.ts +684 -684
  14. package/src/base/BaseLineAreas.ts +629 -629
  15. package/src/base/BaseLines.ts +706 -706
  16. package/src/base/BaseStackedBar.ts +782 -782
  17. package/src/base/BaseTooltip.ts +385 -385
  18. package/src/base/BaseValueAxis.ts +583 -583
  19. package/src/base/types.ts +2 -2
  20. package/src/const.ts +30 -30
  21. package/src/grid/defaults.ts +250 -246
  22. package/src/grid/gridObservables.ts +554 -554
  23. package/src/grid/index.ts +16 -16
  24. package/src/grid/plugins/Bars.ts +69 -69
  25. package/src/grid/plugins/BarsPN.ts +66 -66
  26. package/src/grid/plugins/BarsTriangle.ts +73 -73
  27. package/src/grid/plugins/Dots.ts +68 -68
  28. package/src/grid/plugins/GridLegend.ts +107 -107
  29. package/src/grid/plugins/GridTooltip.ts +66 -66
  30. package/src/grid/plugins/GridZoom.ts +218 -218
  31. package/src/grid/plugins/GroupAux.ts +1103 -1103
  32. package/src/grid/plugins/GroupAxis.ts +97 -97
  33. package/src/grid/plugins/LineAreas.ts +65 -65
  34. package/src/grid/plugins/Lines.ts +59 -59
  35. package/src/grid/plugins/StackedBar.ts +64 -64
  36. package/src/grid/plugins/StackedValueAxis.ts +96 -96
  37. package/src/grid/plugins/ValueAxis.ts +94 -94
  38. package/src/index.ts +6 -6
  39. package/src/multiGrid/defaults.ts +228 -224
  40. package/src/multiGrid/index.ts +14 -14
  41. package/src/multiGrid/multiGridObservables.ts +49 -49
  42. package/src/multiGrid/plugins/MultiBars.ts +108 -108
  43. package/src/multiGrid/plugins/MultiBarsTriangle.ts +114 -114
  44. package/src/multiGrid/plugins/MultiDots.ts +102 -102
  45. package/src/multiGrid/plugins/MultiGridLegend.ts +159 -159
  46. package/src/multiGrid/plugins/MultiGridTooltip.ts +66 -66
  47. package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
  48. package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
  49. package/src/multiGrid/plugins/MultiLines.ts +101 -101
  50. package/src/multiGrid/plugins/MultiStackedBar.ts +106 -106
  51. package/src/multiGrid/plugins/MultiStackedValueAxis.ts +134 -134
  52. package/src/multiGrid/plugins/MultiValueAxis.ts +134 -134
  53. package/src/multiGrid/plugins/OverlappingStackedValueAxes.ts +299 -299
  54. package/src/multiGrid/plugins/OverlappingValueAxes.ts +300 -300
  55. package/src/multiValue/defaults.ts +166 -166
  56. package/src/multiValue/index.ts +8 -8
  57. package/src/multiValue/multiValueObservables.ts +297 -297
  58. package/src/multiValue/plugins/MultiValueLegend.ts +107 -107
  59. package/src/multiValue/plugins/MultiValueTooltip.ts +66 -66
  60. package/src/multiValue/plugins/Scatter.ts +426 -426
  61. package/src/multiValue/plugins/ScatterBubbles.ts +554 -554
  62. package/src/multiValue/plugins/XYAux.ts +681 -681
  63. package/src/multiValue/plugins/XYAxes.ts +684 -684
  64. package/src/multiValue/plugins/XYZoom.ts +299 -299
  65. package/src/noneData/defaults.ts +102 -102
  66. package/src/noneData/index.ts +3 -3
  67. package/src/noneData/plugins/Container.ts +27 -27
  68. package/src/noneData/plugins/Tooltip.ts +373 -373
  69. package/src/relationship/defaults.ts +218 -196
  70. package/src/relationship/index.ts +5 -5
  71. package/src/relationship/plugins/ForceDirected.ts +1168 -1168
  72. package/src/relationship/plugins/ForceDirectedBubbles.ts +1403 -1395
  73. package/src/relationship/plugins/RelationshipLegend.ts +100 -100
  74. package/src/relationship/plugins/RelationshipTooltip.ts +66 -66
  75. package/src/relationship/relationshipObservables.ts +49 -49
  76. package/src/series/defaults.ts +230 -207
  77. package/src/series/index.ts +9 -9
  78. package/src/series/plugins/Bubbles.ts +620 -606
  79. package/src/series/plugins/Pie.ts +623 -623
  80. package/src/series/plugins/PieEventTexts.ts +284 -284
  81. package/src/series/plugins/PieLabels.ts +640 -640
  82. package/src/series/plugins/Rose.ts +516 -516
  83. package/src/series/plugins/RoseLabels.ts +600 -600
  84. package/src/series/plugins/SeriesLegend.ts +107 -107
  85. package/src/series/plugins/SeriesTooltip.ts +66 -66
  86. package/src/series/seriesObservables.ts +145 -145
  87. package/src/series/seriesUtils.ts +51 -51
  88. package/src/tree/defaults.ts +100 -78
  89. package/src/tree/index.ts +4 -4
  90. package/src/tree/plugins/TreeLegend.ts +100 -100
  91. package/src/tree/plugins/TreeMap.ts +341 -333
  92. package/src/tree/plugins/TreeTooltip.ts +66 -66
  93. package/src/utils/commonUtils.ts +21 -21
  94. package/src/utils/d3Graphics.ts +174 -174
  95. package/src/utils/d3Utils.ts +92 -74
  96. package/src/utils/observables.ts +14 -14
  97. package/src/utils/orbchartsUtils.ts +129 -115
  98. package/tsconfig.base.json +13 -13
  99. package/tsconfig.json +2 -2
  100. 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
+ })