@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,682 +1,682 @@
1
- import * as d3 from 'd3'
2
- import {
3
- // of,
4
- iif,
5
- debounceTime,
6
- EMPTY,
7
- combineLatest,
8
- switchMap,
9
- map,
10
- filter,
11
- first,
12
- takeUntil,
13
- distinctUntilChanged,
14
- shareReplay,
15
- Subject,
16
- Observable } from 'rxjs'
17
- import {
18
- defineMultiValuePlugin } from '../../../lib/core'
19
- import type { DefinePluginConfig } from '../../../lib/core-types'
20
- import type {
21
- ColorType,
22
- TransformData,
23
- DataFormatterMultiValue,
24
- ChartParams,
25
- Layout,
26
- } from '../../../lib/core-types'
27
- import { DEFAULT_X_Y_AUX_PARAMS } from '../defaults'
28
- import { parseTickFormatValue } from '../../utils/d3Utils'
29
- import { measureTextWidth } from '../../utils/commonUtils'
30
- import { getColor, getClassName, getUniID } from '../../utils/orbchartsUtils'
31
- import { d3EventObservable } from '../../utils/observables'
32
- import { multiValueXYPositionObservable } from '../multiValueObservables'
33
- import type { XYAuxParams } from '../../../lib/plugins-basic-types'
34
- import { multiValueSelectionsObservable } from '../multiValueObservables'
35
- import { renderTspansOnAxis } from '../../utils/d3Graphics'
36
- import { LAYER_INDEX_OF_AUX } from '../../const'
37
-
38
- interface LineDatum {
39
- id: string
40
- x1: number
41
- x2: number
42
- y1: number
43
- y2: number
44
- dashArray: string
45
- colorType: ColorType
46
- }
47
-
48
- interface LabelDatum {
49
- id: string
50
- text: string
51
- textArr: string[]
52
- textWidth: number
53
- textHeight: number
54
- colorType: ColorType
55
- textColorType: ColorType
56
- x: number
57
- y: number
58
- rectWidth: number
59
- rectHeight: number
60
- rectX: number
61
- rectY: number
62
- textX: number
63
- textY: number
64
- }
65
-
66
- const pluginName = 'XYAux'
67
- const labelClassName = getClassName(pluginName, 'label-box')
68
-
69
- const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_X_Y_AUX_PARAMS> = {
70
- name: pluginName,
71
- defaultParams: DEFAULT_X_Y_AUX_PARAMS,
72
- layerIndex: LAYER_INDEX_OF_AUX,
73
- validator: (params, { validateColumns }) => {
74
- const result = validateColumns(params, {
75
- xAxis: {
76
- toBeTypes: ['object']
77
- },
78
- yAxis: {
79
- toBeTypes: ['object']
80
- }
81
- })
82
- if (params.xAxis) {
83
- const forceResult = validateColumns(params.xAxis, {
84
- showLine: {
85
- toBeTypes: ['boolean']
86
- },
87
- showLabel: {
88
- toBeTypes: ['boolean']
89
- },
90
- lineDashArray: {
91
- toBeTypes: ['string']
92
- },
93
- lineColorType: {
94
- toBeOption: 'ColorType'
95
- },
96
- labelColorType: {
97
- toBeOption: 'ColorType'
98
- },
99
- labelTextColorType: {
100
- toBeOption: 'ColorType'
101
- },
102
- labelTextFormat: {
103
- toBeTypes: ['string', 'Function']
104
- },
105
- labelPadding: {
106
- toBeTypes: ['number']
107
- },
108
- })
109
- if (forceResult.status === 'error') {
110
- return forceResult
111
- }
112
- }
113
- if (params.yAxis) {
114
- const forceResult = validateColumns(params.yAxis, {
115
- showLine: {
116
- toBeTypes: ['boolean']
117
- },
118
- showLabel: {
119
- toBeTypes: ['boolean']
120
- },
121
- lineDashArray: {
122
- toBeTypes: ['string']
123
- },
124
- lineColorType: {
125
- toBeOption: 'ColorType'
126
- },
127
- labelColorType: {
128
- toBeOption: 'ColorType'
129
- },
130
- labelTextColorType: {
131
- toBeOption: 'ColorType'
132
- },
133
- labelTextFormat: {
134
- toBeTypes: ['string', 'Function']
135
- },
136
- labelPadding: {
137
- toBeTypes: ['number']
138
- },
139
- })
140
- if (forceResult.status === 'error') {
141
- return forceResult
142
- }
143
- }
144
- return result
145
- }
146
- }
147
-
148
- function createLineData ({ axisX, axisY, layout, fullParams }: {
149
- axisX: number
150
- axisY: number
151
- layout: Layout
152
- fullParams: XYAuxParams
153
- }): LineDatum[] {
154
- if ((axisX >= 0 && axisX <= layout.width && axisY >= 0 && axisY <= layout.height) === false) {
155
- return []
156
- }
157
- return [
158
- {
159
- id: 'line-x',
160
- x1: axisX,
161
- x2: axisX,
162
- y1: 0,
163
- y2: layout.height,
164
- dashArray: fullParams.xAxis.lineDashArray ?? 'none',
165
- colorType: fullParams.xAxis.lineColorType
166
- },
167
- {
168
- id: 'line-0',
169
- x1: 0,
170
- x2: layout.width,
171
- y1: axisY,
172
- y2: axisY,
173
- dashArray: fullParams.yAxis.lineDashArray ?? 'none',
174
- colorType: fullParams.yAxis.lineColorType
175
- }
176
- ]
177
- }
178
-
179
- function createLabelData ({ axisX, axisY, xValue, yValue, fullParams, textSizePx, layout, columnAmount, rowAmount }: {
180
- axisX: number
181
- axisY: number
182
- xValue: number
183
- yValue: number
184
- fullParams: XYAuxParams
185
- textSizePx: number
186
- layout: Layout
187
- columnAmount: number
188
- rowAmount: number
189
- }): LabelDatum[] {
190
- if ((axisX >= 0 && axisX <= layout.width && axisY >= 0 && axisY <= layout.height) === false) {
191
- return []
192
- }
193
- const rectPaddingWidth = 6
194
- const rectPaddingHeight = 3
195
-
196
- // x
197
- const xX = axisX
198
- const xY = layout.height + (fullParams.xAxis.labelPadding * rowAmount) // rowAmount 是為了把外部 container 的變形逆轉回來
199
- const xText = parseTickFormatValue(xValue, fullParams.xAxis.labelTextFormat)
200
- const xTextArr = xText.split('\n')
201
- const xMaxLengthText = xTextArr.reduce((acc, current) => current.length > acc.length ? current : acc, '')
202
- const xTextWidth = measureTextWidth(xMaxLengthText, textSizePx)
203
- const xTextHeight = textSizePx * xTextArr.length
204
- const xRectWidth = xTextWidth + (rectPaddingWidth * 2)
205
- const xRectHeight = xTextHeight + (rectPaddingHeight * 2)
206
- const xRectX = - xRectWidth / 2
207
- const xRectY = - rectPaddingHeight
208
- const xTextX = xRectX + rectPaddingWidth
209
- const xTextY = xRectY + rectPaddingHeight
210
- // y
211
- const yX = - (fullParams.yAxis.labelPadding * columnAmount) // columnAmount 是為了把外部 container 的變形逆轉回來
212
- const yY = axisY
213
- const yText = parseTickFormatValue(yValue, fullParams.yAxis.labelTextFormat)
214
- const yTextArr = yText.split('\n')
215
- const yMaxLengthText = yTextArr.reduce((acc, current) => current.length > acc.length ? current : acc, '')
216
- const yTextWidth = measureTextWidth(yMaxLengthText, textSizePx)
217
- const yTextHeight = textSizePx * yTextArr.length
218
- const yRectWidth = yTextWidth + (rectPaddingWidth * 2)
219
- const yRectHeight = yTextHeight + (rectPaddingHeight * 2)
220
- const yRectX = - yTextWidth - rectPaddingWidth
221
- const yRectY = - rectPaddingHeight - yTextHeight / 2
222
- const yTextX = yRectX + rectPaddingWidth
223
- const yTextY = yRectY + rectPaddingHeight
224
- return [
225
- {
226
- id: 'label-x',
227
- x: xX,
228
- y: xY,
229
- text: xText,
230
- textArr: xTextArr,
231
- textWidth: xTextWidth,
232
- textHeight: xTextHeight,
233
- colorType: fullParams.xAxis.labelColorType,
234
- textColorType: fullParams.xAxis.labelTextColorType,
235
- rectWidth: xRectWidth,
236
- rectHeight: xRectHeight,
237
- rectX: xRectX,
238
- rectY: xRectY,
239
- textX: xTextX,
240
- textY: xTextY
241
- },
242
- {
243
- id: 'label-y',
244
- x: yX,
245
- y: yY,
246
- text: yText,
247
- textArr: yTextArr,
248
- textWidth: yTextWidth,
249
- textHeight: yTextHeight,
250
- colorType: fullParams.yAxis.labelColorType,
251
- textColorType: fullParams.xAxis.labelTextColorType,
252
- rectWidth: yRectWidth,
253
- rectHeight: yRectHeight,
254
- rectX: yRectX,
255
- rectY: yRectY,
256
- textX: yTextX,
257
- textY: yTextY
258
- }
259
- ]
260
- }
261
-
262
- function renderLine ({ selection, pluginName, lineData, fullParams, fullChartParams }: {
263
- selection: d3.Selection<any, string, any, unknown>
264
- pluginName: string
265
- lineData: LineDatum[]
266
- fullParams: XYAuxParams
267
- fullChartParams: ChartParams
268
- }) {
269
- const gClassName = getClassName(pluginName, 'auxline')
270
- const auxLineSelection = selection
271
- .selectAll<SVGLineElement, LineDatum>(`line.${gClassName}`)
272
- .data(lineData)
273
- .join(
274
- enter => {
275
- return enter
276
- .append('line')
277
- .classed(gClassName, true)
278
- .style('stroke-width', 1)
279
- .style('pointer-events', 'none')
280
- .style('vector-effect', 'non-scaling-stroke')
281
- .attr('x1', d => d.x1)
282
- .attr('y1', d => d.y1)
283
- .attr('x2', d => d.x2)
284
- .attr('y2', d => d.y2)
285
- },
286
- update => {
287
- const updateSelection = update
288
- .transition()
289
- .duration(50)
290
- .attr('x1', d => d.x1)
291
- .attr('y1', d => d.y1)
292
- .attr('x2', d => d.x2)
293
- .attr('y2', d => d.y2)
294
- return updateSelection
295
- },
296
- exit => exit.remove()
297
- )
298
- .style('stroke', d => getColor(d.colorType, fullChartParams))
299
- .style('stroke-dasharray', d => d.dashArray)
300
-
301
- return auxLineSelection
302
- }
303
-
304
- function removeLine (selection: d3.Selection<any, string, any, unknown>) {
305
- const update = selection
306
- .selectAll<SVGLineElement, LineDatum>('line')
307
- .data([])
308
-
309
- update.exit().remove()
310
- }
311
-
312
- function renderLabel ({ selection, labelData, fullParams, fullDataFormatter, fullChartParams, textReverseTransform, textSizePx }: {
313
- selection: d3.Selection<any, string, any, unknown>
314
- labelData: LabelDatum[]
315
- fullParams: XYAuxParams
316
- fullDataFormatter: DataFormatterMultiValue
317
- fullChartParams: ChartParams
318
- // gridAxesReverseTransformValue: string
319
- textReverseTransform: string
320
- textSizePx: number
321
- }) {
322
- // const rectHeight = textSizePx + 6
323
-
324
- const axisLabelSelection = selection
325
- .selectAll<SVGGElement, LabelDatum>(`g.${labelClassName}`)
326
- .data(labelData)
327
- .join(
328
- enter => {
329
- return enter
330
- .append('g')
331
- .classed(labelClassName, true)
332
- .style('cursor', 'pointer')
333
- .attr("transform", (d, i) => {
334
- return `translate(${d.x}, ${d.y})`
335
- })
336
- },
337
- update => {
338
- const updateSelection = update
339
- .transition()
340
- .duration(50)
341
- .attr("transform", (d, i) => {
342
- return `translate(${d.x}, ${d.y})`
343
- })
344
- return updateSelection
345
- },
346
- exit => exit.remove()
347
- )
348
- .each((datum, i, n) => {
349
- // // const rectWidth = measureTextWidth(datum.text, textSizePx) + 12
350
- // const rectWidth = datum.textWidth + 12
351
- // const rectHeight = datum.textHeight + 6
352
- // // -- label偏移位置 --
353
- // let rectX = - rectWidth / 2
354
- // let rectY = 2
355
-
356
- // -- rect --
357
- d3.select(n[i])
358
- .selectAll<SVGRectElement, LabelDatum>('rect')
359
- .data([datum])
360
- .join(
361
- enter => enter.append('rect')
362
- .style('cursor', 'pointer')
363
- .attr('rx', 5)
364
- .attr('ry', 5),
365
- update => update,
366
- exit => exit.remove()
367
- )
368
- .attr('width', d => `${d.rectWidth}px`)
369
- .attr('height', d => `${d.rectHeight}px`)
370
- .attr('fill', d => getColor(d.colorType, fullChartParams))
371
- .attr('x', d => d.rectX)
372
- .attr('y', d => d.rectY)
373
- .style('transform', textReverseTransform)
374
-
375
- // -- text --
376
- d3.select(n[i])
377
- .selectAll<SVGTextElement, LabelDatum>('text')
378
- .data([datum])
379
- .join(
380
- enter => enter.append('text')
381
- .style('dominant-baseline', 'hanging')
382
- .style('cursor', 'pointer')
383
- .style('pointer-events', 'none'),
384
- update => update,
385
- exit => exit.remove()
386
- )
387
- .style('transform', textReverseTransform)
388
- .attr('fill', d => getColor(d.textColorType, fullChartParams))
389
- .attr('font-size', fullChartParams.styles.textSize)
390
- .attr('x', d => d.textX)
391
- .attr('y', d => d.textY)
392
- .each((d, i, n) => {
393
- renderTspansOnAxis(d3.select(n[i]), {
394
- textArr: datum.textArr,
395
- textSizePx,
396
- groupAxisPosition: i === 0
397
- ? 'bottom' // x axis
398
- : 'left' // y axis
399
- })
400
- })
401
- })
402
-
403
- return axisLabelSelection
404
- }
405
-
406
- function removeLabel (selection: d3.Selection<any, string, any, unknown>) {
407
- const gUpdate = selection
408
- .selectAll<SVGGElement, LabelDatum>(`g.${labelClassName}`)
409
- .data([])
410
-
411
- gUpdate.exit().remove()
412
- }
413
-
414
-
415
- export const XYAux = defineMultiValuePlugin(pluginConfig)(({ selection, rootSelection, name, subject, observer }) => {
416
- const destroy$ = new Subject()
417
-
418
- let isLabelMouseover: boolean = false
419
-
420
- const rootRectSelection: d3.Selection<SVGRectElement, any, any, any> = rootSelection
421
- .insert('rect', 'g')
422
- .classed(getClassName(pluginName, 'rect'), true)
423
- .attr('opacity', 0)
424
-
425
- // const axisSelection: d3.Selection<SVGGElement, any, any, any> = selection
426
- // .append('g')
427
-
428
- const {
429
- categorySelection$,
430
- axesSelection$,
431
- defsSelection$,
432
- graphicGSelection$
433
- } = multiValueSelectionsObservable({
434
- selection,
435
- pluginName,
436
- clipPathID: 'test',
437
- categoryLabels$: observer.isCategorySeprate$.pipe(
438
- switchMap(isCategorySeprate => {
439
- return iif(
440
- () => isCategorySeprate,
441
- observer.categoryLabels$,
442
- // 如果沒分開的話只取一筆
443
- observer.categoryLabels$.pipe(
444
- map(d => [d[0]])
445
- )
446
- )
447
- })
448
- ),
449
- multiValueContainerPosition$: observer.multiValueContainerPosition$,
450
- multiValueGraphicTransform$: observer.multiValueGraphicTransform$
451
- })
452
-
453
- observer.layout$.pipe(
454
- takeUntil(destroy$),
455
- ).subscribe(d => {
456
- rootRectSelection
457
- .attr('width', d.rootWidth)
458
- .attr('height', d.rootHeight)
459
- })
460
-
461
- // const highlightTarget$ = observer.fullChartParams$.pipe(
462
- // takeUntil(destroy$),
463
- // map(d => d.highlightTarget),
464
- // distinctUntilChanged()
465
- // )
466
-
467
- // const rootMousemove$: Observable<any> = d3EventObservable(rootSelection, 'mousemove')
468
- // .pipe(
469
- // takeUntil(destroy$),
470
- // debounceTime(10)
471
- // )
472
-
473
- // let r = 0
474
- // rootMousemove$.subscribe(d => {
475
- // r++
476
- // console.log('r:', r)
477
- // })
478
-
479
- const columnAmount$ = observer.multiValueContainerPosition$.pipe(
480
- map(multiValueContainerPosition => {
481
- const maxColumnIndex = multiValueContainerPosition.reduce((acc, current) => {
482
- return current.columnIndex > acc ? current.columnIndex : acc
483
- }, 0)
484
- return maxColumnIndex + 1
485
- }),
486
- distinctUntilChanged()
487
- )
488
-
489
- const rowAmount$ = observer.multiValueContainerPosition$.pipe(
490
- map(multiValueContainerPosition => {
491
- const maxRowIndex = multiValueContainerPosition.reduce((acc, current) => {
492
- return current.rowIndex > acc ? current.rowIndex : acc
493
- }, 0)
494
- return maxRowIndex + 1
495
- }),
496
- distinctUntilChanged()
497
- )
498
-
499
- const textReverseTransform$ = observer.multiValueContainerPosition$.pipe(
500
- takeUntil(destroy$),
501
- switchMap(async (d) => d),
502
- map(multiValueContainerPosition => {
503
- // const axesRotateXYReverseValue = `rotateX(${data.gridAxesReverseTransform.rotateX}deg) rotateY(${data.gridAxesReverseTransform.rotateY}deg)`
504
- // const axesRotateReverseValue = `rotate(${data.gridAxesReverseTransform.rotate}deg)`
505
- const containerScaleReverseValue = `scale(${1 / multiValueContainerPosition[0].scale[0]}, ${1 / multiValueContainerPosition[0].scale[1]})`
506
- // 抵消最外層scale
507
- return `${containerScaleReverseValue}`
508
- }),
509
- distinctUntilChanged()
510
- )
511
-
512
- const xyPosition$ = multiValueXYPositionObservable({
513
- rootSelection,
514
- fullDataFormatter$: observer.fullDataFormatter$,
515
- filteredMinMaxXYData$: observer.filteredMinMaxXYData$,
516
- multiValueContainerPosition$: observer.multiValueContainerPosition$,
517
- layout$: observer.layout$
518
- }).pipe(
519
- takeUntil(destroy$)
520
- )
521
-
522
- combineLatest({
523
- axesSelection: axesSelection$,
524
- // rootMousemove: rootMousemove$,
525
- layout: observer.layout$,
526
- xyPosition: xyPosition$,
527
- // computedData: observer.computedData$,
528
- fullParams: observer.fullParams$,
529
- fullDataFormatter: observer.fullDataFormatter$,
530
- fullChartParams: observer.fullChartParams$,
531
- // highlightTarget: highlightTarget$,
532
- textReverseTransform: textReverseTransform$,
533
- // CategoryDataMap: observer.CategoryDataMap$,
534
- textSizePx: observer.textSizePx$,
535
- columnAmount: columnAmount$,
536
- rowAmount: rowAmount$
537
- }).pipe(
538
- takeUntil(destroy$),
539
- switchMap(async d => d),
540
- ).subscribe(data => {
541
- // 依event的座標取得group資料
542
- const { x, y, xValue, yValue } = data.xyPosition
543
-
544
- const lineData = createLineData({
545
- axisX: x,
546
- axisY: y,
547
- layout: data.layout,
548
- fullParams: data.fullParams,
549
- })
550
- renderLine({
551
- selection: data.axesSelection,
552
- pluginName: name,
553
- lineData,
554
- fullParams: data.fullParams,
555
- fullChartParams: data.fullChartParams
556
- })
557
- const labelData = createLabelData({
558
- axisX: x,
559
- axisY: y,
560
- xValue,
561
- yValue,
562
- fullParams: data.fullParams,
563
- textSizePx: data.textSizePx,
564
- layout: data.layout,
565
- columnAmount: data.columnAmount,
566
- rowAmount: data.rowAmount
567
- })
568
- const labelSelection = renderLabel({
569
- selection: data.axesSelection,
570
- labelData,
571
- fullParams: data.fullParams,
572
- fullDataFormatter: data.fullDataFormatter,
573
- fullChartParams: data.fullChartParams,
574
- textReverseTransform: data.textReverseTransform,
575
- textSizePx: data.textSizePx
576
- })
577
-
578
- // label的事件
579
- // labelSelection
580
- // .on('mouseover', (event, datum) => {
581
- // event.stopPropagation()
582
- // // const { groupIndex, groupLabel } = data.xyPositionFn(event)
583
-
584
- // isLabelMouseover = true
585
-
586
- // subject.event$.next({
587
- // type: 'multiValue',
588
- // eventName: 'mouseover',
589
- // pluginName,
590
- // highlightTarget: data.highlightTarget,
591
- // datum,
592
- // category: [],
593
- // categoryIndex: -1,
594
- // categoryLabel: '',
595
- // data: data.computedData,
596
- // event,
597
- // })
598
- // })
599
- // .on('mousemove', (event, datum) => {
600
- // event.stopPropagation()
601
- // // const { groupIndex, groupLabel } = data.xyPositionFn(event)
602
-
603
- // subject.event$.next({
604
- // type: 'multiValue',
605
- // eventName: 'mousemove',
606
- // pluginName,
607
- // highlightTarget: data.highlightTarget,
608
- // datum,
609
- // category: [],
610
- // categoryIndex: -1,
611
- // categoryLabel: '',
612
- // data: data.computedData,
613
- // event,
614
- // })
615
- // })
616
- // .on('mouseout', (event, datum) => {
617
- // event.stopPropagation()
618
- // // const { groupIndex, groupLabel } = data.xyPositionFn(event)
619
-
620
- // isLabelMouseover = false
621
-
622
- // subject.event$.next({
623
- // type: 'multiValue',
624
- // eventName: 'mouseout',
625
- // pluginName,
626
- // highlightTarget: data.highlightTarget,
627
- // datum,
628
- // category: [],
629
- // categoryIndex: -1,
630
- // categoryLabel: '',
631
- // data: data.computedData,
632
- // event,
633
- // })
634
- // })
635
- // .on('click', (event, datum) => {
636
- // event.stopPropagation()
637
- // // const { groupIndex, groupLabel } = data.xyPositionFn(event)
638
-
639
- // subject.event$.next({
640
- // type: 'multiValue',
641
- // eventName: 'click',
642
- // pluginName,
643
- // highlightTarget: data.highlightTarget,
644
- // datum,
645
- // category: [],
646
- // categoryIndex: -1,
647
- // categoryLabel: '',
648
- // data: data.computedData,
649
- // event,
650
- // })
651
- // })
652
-
653
- })
654
-
655
-
656
- const rootRectMouseout$ = d3EventObservable(rootRectSelection, 'mouseout').pipe(
657
- takeUntil(destroy$),
658
- )
659
-
660
- combineLatest({
661
- rootRectMouseout: rootRectMouseout$,
662
- axesSelection: axesSelection$,
663
- }).pipe(
664
- takeUntil(destroy$),
665
- switchMap(async d => d)
666
- ).subscribe(data => {
667
- setTimeout(() => {
668
- // // @Q@ workaround - 不知為何和 label 會有衝突,當滑鼠移動到 label 上時,會觸發 mouseout 事件
669
- // if (isLabelMouseover == true) {
670
- // return
671
- // }
672
-
673
- removeLine(data.axesSelection)
674
- removeLabel(data.axesSelection)
675
- })
676
- })
677
-
678
- return () => {
679
- destroy$.next(undefined)
680
- rootRectSelection.remove()
681
- }
1
+ import * as d3 from 'd3'
2
+ import {
3
+ // of,
4
+ iif,
5
+ debounceTime,
6
+ EMPTY,
7
+ combineLatest,
8
+ switchMap,
9
+ map,
10
+ filter,
11
+ first,
12
+ takeUntil,
13
+ distinctUntilChanged,
14
+ shareReplay,
15
+ Subject,
16
+ Observable } from 'rxjs'
17
+ import {
18
+ defineMultiValuePlugin } from '../../../lib/core'
19
+ import type { DefinePluginConfig } from '../../../lib/core-types'
20
+ import type {
21
+ ColorType,
22
+ TransformData,
23
+ DataFormatterMultiValue,
24
+ ChartParams,
25
+ Layout,
26
+ } from '../../../lib/core-types'
27
+ import { DEFAULT_X_Y_AUX_PARAMS } from '../defaults'
28
+ import { parseTickFormatValue } from '../../utils/d3Utils'
29
+ import { measureTextWidth } from '../../utils/commonUtils'
30
+ import { getColor, getClassName, getUniID } from '../../utils/orbchartsUtils'
31
+ import { d3EventObservable } from '../../utils/observables'
32
+ import { multiValueXYPositionObservable } from '../multiValueObservables'
33
+ import type { XYAuxParams } from '../../../lib/plugins-basic-types'
34
+ import { multiValueSelectionsObservable } from '../multiValueObservables'
35
+ import { renderTspansOnAxis } from '../../utils/d3Graphics'
36
+ import { LAYER_INDEX_OF_AUX } from '../../const'
37
+
38
+ interface LineDatum {
39
+ id: string
40
+ x1: number
41
+ x2: number
42
+ y1: number
43
+ y2: number
44
+ dashArray: string
45
+ colorType: ColorType
46
+ }
47
+
48
+ interface LabelDatum {
49
+ id: string
50
+ text: string
51
+ textArr: string[]
52
+ textWidth: number
53
+ textHeight: number
54
+ colorType: ColorType
55
+ textColorType: ColorType
56
+ x: number
57
+ y: number
58
+ rectWidth: number
59
+ rectHeight: number
60
+ rectX: number
61
+ rectY: number
62
+ textX: number
63
+ textY: number
64
+ }
65
+
66
+ const pluginName = 'XYAux'
67
+ const labelClassName = getClassName(pluginName, 'label-box')
68
+
69
+ const pluginConfig: DefinePluginConfig<typeof pluginName, typeof DEFAULT_X_Y_AUX_PARAMS> = {
70
+ name: pluginName,
71
+ defaultParams: DEFAULT_X_Y_AUX_PARAMS,
72
+ layerIndex: LAYER_INDEX_OF_AUX,
73
+ validator: (params, { validateColumns }) => {
74
+ const result = validateColumns(params, {
75
+ xAxis: {
76
+ toBeTypes: ['object']
77
+ },
78
+ yAxis: {
79
+ toBeTypes: ['object']
80
+ }
81
+ })
82
+ if (params.xAxis) {
83
+ const forceResult = validateColumns(params.xAxis, {
84
+ showLine: {
85
+ toBeTypes: ['boolean']
86
+ },
87
+ showLabel: {
88
+ toBeTypes: ['boolean']
89
+ },
90
+ lineDashArray: {
91
+ toBeTypes: ['string']
92
+ },
93
+ lineColorType: {
94
+ toBeOption: 'ColorType'
95
+ },
96
+ labelColorType: {
97
+ toBeOption: 'ColorType'
98
+ },
99
+ labelTextColorType: {
100
+ toBeOption: 'ColorType'
101
+ },
102
+ labelTextFormat: {
103
+ toBeTypes: ['string', 'Function']
104
+ },
105
+ labelPadding: {
106
+ toBeTypes: ['number']
107
+ },
108
+ })
109
+ if (forceResult.status === 'error') {
110
+ return forceResult
111
+ }
112
+ }
113
+ if (params.yAxis) {
114
+ const forceResult = validateColumns(params.yAxis, {
115
+ showLine: {
116
+ toBeTypes: ['boolean']
117
+ },
118
+ showLabel: {
119
+ toBeTypes: ['boolean']
120
+ },
121
+ lineDashArray: {
122
+ toBeTypes: ['string']
123
+ },
124
+ lineColorType: {
125
+ toBeOption: 'ColorType'
126
+ },
127
+ labelColorType: {
128
+ toBeOption: 'ColorType'
129
+ },
130
+ labelTextColorType: {
131
+ toBeOption: 'ColorType'
132
+ },
133
+ labelTextFormat: {
134
+ toBeTypes: ['string', 'Function']
135
+ },
136
+ labelPadding: {
137
+ toBeTypes: ['number']
138
+ },
139
+ })
140
+ if (forceResult.status === 'error') {
141
+ return forceResult
142
+ }
143
+ }
144
+ return result
145
+ }
146
+ }
147
+
148
+ function createLineData ({ axisX, axisY, layout, fullParams }: {
149
+ axisX: number
150
+ axisY: number
151
+ layout: Layout
152
+ fullParams: XYAuxParams
153
+ }): LineDatum[] {
154
+ if ((axisX >= 0 && axisX <= layout.width && axisY >= 0 && axisY <= layout.height) === false) {
155
+ return []
156
+ }
157
+ return [
158
+ {
159
+ id: 'line-x',
160
+ x1: axisX,
161
+ x2: axisX,
162
+ y1: 0,
163
+ y2: layout.height,
164
+ dashArray: fullParams.xAxis.lineDashArray ?? 'none',
165
+ colorType: fullParams.xAxis.lineColorType
166
+ },
167
+ {
168
+ id: 'line-0',
169
+ x1: 0,
170
+ x2: layout.width,
171
+ y1: axisY,
172
+ y2: axisY,
173
+ dashArray: fullParams.yAxis.lineDashArray ?? 'none',
174
+ colorType: fullParams.yAxis.lineColorType
175
+ }
176
+ ]
177
+ }
178
+
179
+ function createLabelData ({ axisX, axisY, xValue, yValue, fullParams, textSizePx, layout, columnAmount, rowAmount }: {
180
+ axisX: number
181
+ axisY: number
182
+ xValue: number
183
+ yValue: number
184
+ fullParams: XYAuxParams
185
+ textSizePx: number
186
+ layout: Layout
187
+ columnAmount: number
188
+ rowAmount: number
189
+ }): LabelDatum[] {
190
+ if ((axisX >= 0 && axisX <= layout.width && axisY >= 0 && axisY <= layout.height) === false) {
191
+ return []
192
+ }
193
+ const rectPaddingWidth = 6
194
+ const rectPaddingHeight = 3
195
+
196
+ // x
197
+ const xX = axisX
198
+ const xY = layout.height + (fullParams.xAxis.labelPadding * rowAmount) // rowAmount 是為了把外部 container 的變形逆轉回來
199
+ const xText = parseTickFormatValue(xValue, fullParams.xAxis.labelTextFormat)
200
+ const xTextArr = xText.split('\n')
201
+ const xMaxLengthText = xTextArr.reduce((acc, current) => current.length > acc.length ? current : acc, '')
202
+ const xTextWidth = measureTextWidth(xMaxLengthText, textSizePx)
203
+ const xTextHeight = textSizePx * xTextArr.length
204
+ const xRectWidth = xTextWidth + (rectPaddingWidth * 2)
205
+ const xRectHeight = xTextHeight + (rectPaddingHeight * 2)
206
+ const xRectX = - xRectWidth / 2
207
+ const xRectY = - rectPaddingHeight
208
+ const xTextX = xRectX + rectPaddingWidth
209
+ const xTextY = xRectY + rectPaddingHeight
210
+ // y
211
+ const yX = - (fullParams.yAxis.labelPadding * columnAmount) // columnAmount 是為了把外部 container 的變形逆轉回來
212
+ const yY = axisY
213
+ const yText = parseTickFormatValue(yValue, fullParams.yAxis.labelTextFormat)
214
+ const yTextArr = yText.split('\n')
215
+ const yMaxLengthText = yTextArr.reduce((acc, current) => current.length > acc.length ? current : acc, '')
216
+ const yTextWidth = measureTextWidth(yMaxLengthText, textSizePx)
217
+ const yTextHeight = textSizePx * yTextArr.length
218
+ const yRectWidth = yTextWidth + (rectPaddingWidth * 2)
219
+ const yRectHeight = yTextHeight + (rectPaddingHeight * 2)
220
+ const yRectX = - yTextWidth - rectPaddingWidth
221
+ const yRectY = - rectPaddingHeight - yTextHeight / 2
222
+ const yTextX = yRectX + rectPaddingWidth
223
+ const yTextY = yRectY + rectPaddingHeight
224
+ return [
225
+ {
226
+ id: 'label-x',
227
+ x: xX,
228
+ y: xY,
229
+ text: xText,
230
+ textArr: xTextArr,
231
+ textWidth: xTextWidth,
232
+ textHeight: xTextHeight,
233
+ colorType: fullParams.xAxis.labelColorType,
234
+ textColorType: fullParams.xAxis.labelTextColorType,
235
+ rectWidth: xRectWidth,
236
+ rectHeight: xRectHeight,
237
+ rectX: xRectX,
238
+ rectY: xRectY,
239
+ textX: xTextX,
240
+ textY: xTextY
241
+ },
242
+ {
243
+ id: 'label-y',
244
+ x: yX,
245
+ y: yY,
246
+ text: yText,
247
+ textArr: yTextArr,
248
+ textWidth: yTextWidth,
249
+ textHeight: yTextHeight,
250
+ colorType: fullParams.yAxis.labelColorType,
251
+ textColorType: fullParams.xAxis.labelTextColorType,
252
+ rectWidth: yRectWidth,
253
+ rectHeight: yRectHeight,
254
+ rectX: yRectX,
255
+ rectY: yRectY,
256
+ textX: yTextX,
257
+ textY: yTextY
258
+ }
259
+ ]
260
+ }
261
+
262
+ function renderLine ({ selection, pluginName, lineData, fullParams, fullChartParams }: {
263
+ selection: d3.Selection<any, string, any, unknown>
264
+ pluginName: string
265
+ lineData: LineDatum[]
266
+ fullParams: XYAuxParams
267
+ fullChartParams: ChartParams
268
+ }) {
269
+ const gClassName = getClassName(pluginName, 'auxline')
270
+ const auxLineSelection = selection
271
+ .selectAll<SVGLineElement, LineDatum>(`line.${gClassName}`)
272
+ .data(lineData)
273
+ .join(
274
+ enter => {
275
+ return enter
276
+ .append('line')
277
+ .classed(gClassName, true)
278
+ .style('stroke-width', 1)
279
+ .style('pointer-events', 'none')
280
+ .style('vector-effect', 'non-scaling-stroke')
281
+ .attr('x1', d => d.x1)
282
+ .attr('y1', d => d.y1)
283
+ .attr('x2', d => d.x2)
284
+ .attr('y2', d => d.y2)
285
+ },
286
+ update => {
287
+ const updateSelection = update
288
+ .transition()
289
+ .duration(50)
290
+ .attr('x1', d => d.x1)
291
+ .attr('y1', d => d.y1)
292
+ .attr('x2', d => d.x2)
293
+ .attr('y2', d => d.y2)
294
+ return updateSelection
295
+ },
296
+ exit => exit.remove()
297
+ )
298
+ .style('stroke', d => getColor(d.colorType, fullChartParams))
299
+ .style('stroke-dasharray', d => d.dashArray)
300
+
301
+ return auxLineSelection
302
+ }
303
+
304
+ function removeLine (selection: d3.Selection<any, string, any, unknown>) {
305
+ const update = selection
306
+ .selectAll<SVGLineElement, LineDatum>('line')
307
+ .data([])
308
+
309
+ update.exit().remove()
310
+ }
311
+
312
+ function renderLabel ({ selection, labelData, fullParams, fullDataFormatter, fullChartParams, textReverseTransform, textSizePx }: {
313
+ selection: d3.Selection<any, string, any, unknown>
314
+ labelData: LabelDatum[]
315
+ fullParams: XYAuxParams
316
+ fullDataFormatter: DataFormatterMultiValue
317
+ fullChartParams: ChartParams
318
+ // gridAxesReverseTransformValue: string
319
+ textReverseTransform: string
320
+ textSizePx: number
321
+ }) {
322
+ // const rectHeight = textSizePx + 6
323
+
324
+ const axisLabelSelection = selection
325
+ .selectAll<SVGGElement, LabelDatum>(`g.${labelClassName}`)
326
+ .data(labelData)
327
+ .join(
328
+ enter => {
329
+ return enter
330
+ .append('g')
331
+ .classed(labelClassName, true)
332
+ .style('cursor', 'pointer')
333
+ .attr("transform", (d, i) => {
334
+ return `translate(${d.x}, ${d.y})`
335
+ })
336
+ },
337
+ update => {
338
+ const updateSelection = update
339
+ .transition()
340
+ .duration(50)
341
+ .attr("transform", (d, i) => {
342
+ return `translate(${d.x}, ${d.y})`
343
+ })
344
+ return updateSelection
345
+ },
346
+ exit => exit.remove()
347
+ )
348
+ .each((datum, i, n) => {
349
+ // // const rectWidth = measureTextWidth(datum.text, textSizePx) + 12
350
+ // const rectWidth = datum.textWidth + 12
351
+ // const rectHeight = datum.textHeight + 6
352
+ // // -- label偏移位置 --
353
+ // let rectX = - rectWidth / 2
354
+ // let rectY = 2
355
+
356
+ // -- rect --
357
+ d3.select(n[i])
358
+ .selectAll<SVGRectElement, LabelDatum>('rect')
359
+ .data([datum])
360
+ .join(
361
+ enter => enter.append('rect')
362
+ .style('cursor', 'pointer')
363
+ .attr('rx', 5)
364
+ .attr('ry', 5),
365
+ update => update,
366
+ exit => exit.remove()
367
+ )
368
+ .attr('width', d => `${d.rectWidth}px`)
369
+ .attr('height', d => `${d.rectHeight}px`)
370
+ .attr('fill', d => getColor(d.colorType, fullChartParams))
371
+ .attr('x', d => d.rectX)
372
+ .attr('y', d => d.rectY)
373
+ .style('transform', textReverseTransform)
374
+
375
+ // -- text --
376
+ d3.select(n[i])
377
+ .selectAll<SVGTextElement, LabelDatum>('text')
378
+ .data([datum])
379
+ .join(
380
+ enter => enter.append('text')
381
+ .style('dominant-baseline', 'hanging')
382
+ .style('cursor', 'pointer')
383
+ .style('pointer-events', 'none'),
384
+ update => update,
385
+ exit => exit.remove()
386
+ )
387
+ .style('transform', textReverseTransform)
388
+ .attr('fill', d => getColor(d.textColorType, fullChartParams))
389
+ .attr('font-size', fullChartParams.styles.textSize)
390
+ .attr('x', d => d.textX)
391
+ .attr('y', d => d.textY)
392
+ .each((d, i, n) => {
393
+ renderTspansOnAxis(d3.select(n[i]), {
394
+ textArr: datum.textArr,
395
+ textSizePx,
396
+ groupAxisPosition: i === 0
397
+ ? 'bottom' // x axis
398
+ : 'left' // y axis
399
+ })
400
+ })
401
+ })
402
+
403
+ return axisLabelSelection
404
+ }
405
+
406
+ function removeLabel (selection: d3.Selection<any, string, any, unknown>) {
407
+ const gUpdate = selection
408
+ .selectAll<SVGGElement, LabelDatum>(`g.${labelClassName}`)
409
+ .data([])
410
+
411
+ gUpdate.exit().remove()
412
+ }
413
+
414
+
415
+ export const XYAux = defineMultiValuePlugin(pluginConfig)(({ selection, rootSelection, name, subject, observer }) => {
416
+ const destroy$ = new Subject()
417
+
418
+ let isLabelMouseover: boolean = false
419
+
420
+ const rootRectSelection: d3.Selection<SVGRectElement, any, any, any> = rootSelection
421
+ .insert('rect', 'g')
422
+ .classed(getClassName(pluginName, 'rect'), true)
423
+ .attr('opacity', 0)
424
+
425
+ // const axisSelection: d3.Selection<SVGGElement, any, any, any> = selection
426
+ // .append('g')
427
+
428
+ const {
429
+ categorySelection$,
430
+ axesSelection$,
431
+ defsSelection$,
432
+ graphicGSelection$
433
+ } = multiValueSelectionsObservable({
434
+ selection,
435
+ pluginName,
436
+ clipPathID: 'test',
437
+ categoryLabels$: observer.isCategorySeprate$.pipe(
438
+ switchMap(isCategorySeprate => {
439
+ return iif(
440
+ () => isCategorySeprate,
441
+ observer.categoryLabels$,
442
+ // 如果沒分開的話只取一筆
443
+ observer.categoryLabels$.pipe(
444
+ map(d => [d[0]])
445
+ )
446
+ )
447
+ })
448
+ ),
449
+ multiValueContainerPosition$: observer.multiValueContainerPosition$,
450
+ multiValueGraphicTransform$: observer.multiValueGraphicTransform$
451
+ })
452
+
453
+ observer.layout$.pipe(
454
+ takeUntil(destroy$),
455
+ ).subscribe(d => {
456
+ rootRectSelection
457
+ .attr('width', d.rootWidth)
458
+ .attr('height', d.rootHeight)
459
+ })
460
+
461
+ // const highlightTarget$ = observer.fullChartParams$.pipe(
462
+ // takeUntil(destroy$),
463
+ // map(d => d.highlightTarget),
464
+ // distinctUntilChanged()
465
+ // )
466
+
467
+ // const rootMousemove$: Observable<any> = d3EventObservable(rootSelection, 'mousemove')
468
+ // .pipe(
469
+ // takeUntil(destroy$),
470
+ // debounceTime(10)
471
+ // )
472
+
473
+ // let r = 0
474
+ // rootMousemove$.subscribe(d => {
475
+ // r++
476
+ // console.log('r:', r)
477
+ // })
478
+
479
+ const columnAmount$ = observer.multiValueContainerPosition$.pipe(
480
+ map(multiValueContainerPosition => {
481
+ const maxColumnIndex = multiValueContainerPosition.reduce((acc, current) => {
482
+ return current.columnIndex > acc ? current.columnIndex : acc
483
+ }, 0)
484
+ return maxColumnIndex + 1
485
+ }),
486
+ distinctUntilChanged()
487
+ )
488
+
489
+ const rowAmount$ = observer.multiValueContainerPosition$.pipe(
490
+ map(multiValueContainerPosition => {
491
+ const maxRowIndex = multiValueContainerPosition.reduce((acc, current) => {
492
+ return current.rowIndex > acc ? current.rowIndex : acc
493
+ }, 0)
494
+ return maxRowIndex + 1
495
+ }),
496
+ distinctUntilChanged()
497
+ )
498
+
499
+ const textReverseTransform$ = observer.multiValueContainerPosition$.pipe(
500
+ takeUntil(destroy$),
501
+ switchMap(async (d) => d),
502
+ map(multiValueContainerPosition => {
503
+ // const axesRotateXYReverseValue = `rotateX(${data.gridAxesReverseTransform.rotateX}deg) rotateY(${data.gridAxesReverseTransform.rotateY}deg)`
504
+ // const axesRotateReverseValue = `rotate(${data.gridAxesReverseTransform.rotate}deg)`
505
+ const containerScaleReverseValue = `scale(${1 / multiValueContainerPosition[0].scale[0]}, ${1 / multiValueContainerPosition[0].scale[1]})`
506
+ // 抵消最外層scale
507
+ return `${containerScaleReverseValue}`
508
+ }),
509
+ distinctUntilChanged()
510
+ )
511
+
512
+ const xyPosition$ = multiValueXYPositionObservable({
513
+ rootSelection,
514
+ fullDataFormatter$: observer.fullDataFormatter$,
515
+ filteredMinMaxXYData$: observer.filteredMinMaxXYData$,
516
+ multiValueContainerPosition$: observer.multiValueContainerPosition$,
517
+ layout$: observer.layout$
518
+ }).pipe(
519
+ takeUntil(destroy$)
520
+ )
521
+
522
+ combineLatest({
523
+ axesSelection: axesSelection$,
524
+ // rootMousemove: rootMousemove$,
525
+ layout: observer.layout$,
526
+ xyPosition: xyPosition$,
527
+ // computedData: observer.computedData$,
528
+ fullParams: observer.fullParams$,
529
+ fullDataFormatter: observer.fullDataFormatter$,
530
+ fullChartParams: observer.fullChartParams$,
531
+ // highlightTarget: highlightTarget$,
532
+ textReverseTransform: textReverseTransform$,
533
+ // CategoryDataMap: observer.CategoryDataMap$,
534
+ textSizePx: observer.textSizePx$,
535
+ columnAmount: columnAmount$,
536
+ rowAmount: rowAmount$
537
+ }).pipe(
538
+ takeUntil(destroy$),
539
+ switchMap(async d => d),
540
+ ).subscribe(data => {
541
+ // 依event的座標取得group資料
542
+ const { x, y, xValue, yValue } = data.xyPosition
543
+
544
+ const lineData = createLineData({
545
+ axisX: x,
546
+ axisY: y,
547
+ layout: data.layout,
548
+ fullParams: data.fullParams,
549
+ })
550
+ renderLine({
551
+ selection: data.axesSelection,
552
+ pluginName: name,
553
+ lineData,
554
+ fullParams: data.fullParams,
555
+ fullChartParams: data.fullChartParams
556
+ })
557
+ const labelData = createLabelData({
558
+ axisX: x,
559
+ axisY: y,
560
+ xValue,
561
+ yValue,
562
+ fullParams: data.fullParams,
563
+ textSizePx: data.textSizePx,
564
+ layout: data.layout,
565
+ columnAmount: data.columnAmount,
566
+ rowAmount: data.rowAmount
567
+ })
568
+ const labelSelection = renderLabel({
569
+ selection: data.axesSelection,
570
+ labelData,
571
+ fullParams: data.fullParams,
572
+ fullDataFormatter: data.fullDataFormatter,
573
+ fullChartParams: data.fullChartParams,
574
+ textReverseTransform: data.textReverseTransform,
575
+ textSizePx: data.textSizePx
576
+ })
577
+
578
+ // label的事件
579
+ // labelSelection
580
+ // .on('mouseover', (event, datum) => {
581
+ // event.stopPropagation()
582
+ // // const { groupIndex, groupLabel } = data.xyPositionFn(event)
583
+
584
+ // isLabelMouseover = true
585
+
586
+ // subject.event$.next({
587
+ // type: 'multiValue',
588
+ // eventName: 'mouseover',
589
+ // pluginName,
590
+ // highlightTarget: data.highlightTarget,
591
+ // datum,
592
+ // category: [],
593
+ // categoryIndex: -1,
594
+ // categoryLabel: '',
595
+ // data: data.computedData,
596
+ // event,
597
+ // })
598
+ // })
599
+ // .on('mousemove', (event, datum) => {
600
+ // event.stopPropagation()
601
+ // // const { groupIndex, groupLabel } = data.xyPositionFn(event)
602
+
603
+ // subject.event$.next({
604
+ // type: 'multiValue',
605
+ // eventName: 'mousemove',
606
+ // pluginName,
607
+ // highlightTarget: data.highlightTarget,
608
+ // datum,
609
+ // category: [],
610
+ // categoryIndex: -1,
611
+ // categoryLabel: '',
612
+ // data: data.computedData,
613
+ // event,
614
+ // })
615
+ // })
616
+ // .on('mouseout', (event, datum) => {
617
+ // event.stopPropagation()
618
+ // // const { groupIndex, groupLabel } = data.xyPositionFn(event)
619
+
620
+ // isLabelMouseover = false
621
+
622
+ // subject.event$.next({
623
+ // type: 'multiValue',
624
+ // eventName: 'mouseout',
625
+ // pluginName,
626
+ // highlightTarget: data.highlightTarget,
627
+ // datum,
628
+ // category: [],
629
+ // categoryIndex: -1,
630
+ // categoryLabel: '',
631
+ // data: data.computedData,
632
+ // event,
633
+ // })
634
+ // })
635
+ // .on('click', (event, datum) => {
636
+ // event.stopPropagation()
637
+ // // const { groupIndex, groupLabel } = data.xyPositionFn(event)
638
+
639
+ // subject.event$.next({
640
+ // type: 'multiValue',
641
+ // eventName: 'click',
642
+ // pluginName,
643
+ // highlightTarget: data.highlightTarget,
644
+ // datum,
645
+ // category: [],
646
+ // categoryIndex: -1,
647
+ // categoryLabel: '',
648
+ // data: data.computedData,
649
+ // event,
650
+ // })
651
+ // })
652
+
653
+ })
654
+
655
+
656
+ const rootRectMouseout$ = d3EventObservable(rootRectSelection, 'mouseout').pipe(
657
+ takeUntil(destroy$),
658
+ )
659
+
660
+ combineLatest({
661
+ rootRectMouseout: rootRectMouseout$,
662
+ axesSelection: axesSelection$,
663
+ }).pipe(
664
+ takeUntil(destroy$),
665
+ switchMap(async d => d)
666
+ ).subscribe(data => {
667
+ setTimeout(() => {
668
+ // // @Q@ workaround - 不知為何和 label 會有衝突,當滑鼠移動到 label 上時,會觸發 mouseout 事件
669
+ // if (isLabelMouseover == true) {
670
+ // return
671
+ // }
672
+
673
+ removeLine(data.axesSelection)
674
+ removeLabel(data.axesSelection)
675
+ })
676
+ })
677
+
678
+ return () => {
679
+ destroy$.next(undefined)
680
+ rootRectSelection.remove()
681
+ }
682
682
  })