@orbcharts/plugins-basic 3.0.0-alpha.51 → 3.0.0-alpha.52

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,12 +10,14 @@ import {
10
10
  first,
11
11
  takeUntil,
12
12
  distinctUntilChanged,
13
+ shareReplay,
13
14
  Subject,
14
15
  Observable } from 'rxjs'
15
16
  import {
16
17
  defineGridPlugin } from '@orbcharts/core'
17
18
  import type {
18
19
  TransformData,
20
+ DataFormatterGrid,
19
21
  ChartParams } from '@orbcharts/core'
20
22
  import { DEFAULT_GROUP_AREA_PARAMS } from '../defaults'
21
23
  import { parseTickFormatValue } from '../../utils/d3Utils'
@@ -25,6 +27,7 @@ import { d3EventObservable } from '../../utils/observables'
25
27
  import { gridGroupPositionFnObservable } from '../gridObservables'
26
28
  import { createAxisPointScale } from '@orbcharts/core'
27
29
  import type { GroupAuxParams } from '../types'
30
+ import { gridSelectionsObservable } from '../gridObservables'
28
31
 
29
32
  interface LineDatum {
30
33
  id: string
@@ -126,12 +129,14 @@ function createLabelData ({ groupLabel, axisX, fullParams }: {
126
129
  : []
127
130
  }
128
131
 
129
- function renderLabel ({ selection, labelData, fullParams, fullChartParams, gridAxesReverseTransformValue, textSizePx }: {
132
+ function renderLabel ({ selection, labelData, fullParams, fullDataFormatter, fullChartParams, labelTransform, textSizePx }: {
130
133
  selection: d3.Selection<any, unknown, any, unknown>
131
134
  labelData: LabelDatum[]
132
135
  fullParams: GroupAuxParams
136
+ fullDataFormatter: DataFormatterGrid
133
137
  fullChartParams: ChartParams
134
- gridAxesReverseTransformValue: string
138
+ // gridAxesReverseTransformValue: string
139
+ labelTransform: string
135
140
  textSizePx: number
136
141
  }) {
137
142
  const rectHeight = textSizePx + 4
@@ -159,7 +164,22 @@ function renderLabel ({ selection, labelData, fullParams, fullChartParams, gridA
159
164
 
160
165
  axisLabelSelection.each((datum, i, n) => {
161
166
  const rectWidth = measureTextWidth(datum.text, textSizePx) + 12
162
- const rectX = - rectWidth / 2
167
+ // -- label偏移位置 --
168
+ let rectX = - rectWidth / 2
169
+ let rectY = -2
170
+ if (fullDataFormatter.grid.groupAxis.position === 'bottom') {
171
+ rectX = - rectWidth / 2
172
+ rectY = 2
173
+ } else if (fullDataFormatter.grid.groupAxis.position === 'left') {
174
+ rectX = - rectWidth + 2
175
+ rectY = - rectHeight / 2
176
+ } else if (fullDataFormatter.grid.groupAxis.position === 'right') {
177
+ rectX = - 2
178
+ rectY = - rectHeight / 2
179
+ } else if (fullDataFormatter.grid.groupAxis.position === 'top') {
180
+ rectX = - rectWidth / 2
181
+ rectY = - rectHeight + 2
182
+ }
163
183
 
164
184
  const rectUpdate = d3.select(n[i])
165
185
  .selectAll<SVGRectElement, LabelDatum>('rect')
@@ -170,14 +190,14 @@ function renderLabel ({ selection, labelData, fullParams, fullChartParams, gridA
170
190
  .attr('height', `${rectHeight}px`)
171
191
  .attr('fill', d => getColor(fullParams.labelColorType, fullChartParams))
172
192
  .attr('x', rectX)
173
- .attr('y', -2)
193
+ .attr('y', rectY)
174
194
  .attr('rx', 5)
175
195
  .attr('ry', 5)
176
196
  .style('cursor', 'pointer')
177
197
  // .style('pointer-events', 'none')
178
198
  const rect = rectUpdate.merge(rectEnter)
179
199
  .attr('width', d => `${rectWidth}px`)
180
- .style('transform', gridAxesReverseTransformValue)
200
+ .style('transform', labelTransform)
181
201
  rectUpdate.exit().remove()
182
202
 
183
203
  const textUpdate = d3.select(n[i])
@@ -191,10 +211,11 @@ function renderLabel ({ selection, labelData, fullParams, fullChartParams, gridA
191
211
  // .style('pointer-events', 'none')
192
212
  const text = textUpdate.merge(textEnter)
193
213
  .text(d => d.text)
194
- .style('transform', gridAxesReverseTransformValue)
214
+ .style('transform', labelTransform)
195
215
  .attr('fill', d => getColor(fullParams.labelTextColorType, fullChartParams))
196
216
  .attr('font-size', fullChartParams.styles.textSize)
197
217
  .attr('x', rectX + 6)
218
+ .attr('y', rectY)
198
219
  textUpdate.exit().remove()
199
220
  })
200
221
 
@@ -212,13 +233,30 @@ function removeLabel (selection: d3.Selection<any, unknown, any, unknown>) {
212
233
  export const GroupAux = defineGridPlugin(pluginName, DEFAULT_GROUP_AREA_PARAMS)(({ selection, rootSelection, name, subject, observer }) => {
213
234
  const destroy$ = new Subject()
214
235
 
236
+ let isLabelMouseover = false
237
+
215
238
  const rootRectSelection: d3.Selection<SVGRectElement, any, any, any> = rootSelection
216
239
  .insert('rect', 'g')
217
240
  .classed(getClassName(pluginName, 'rect'), true)
218
241
  .attr('opacity', 0)
219
242
 
220
- const axisSelection: d3.Selection<SVGGElement, any, any, any> = selection
221
- .append('g')
243
+ // const axisSelection: d3.Selection<SVGGElement, any, any, any> = selection
244
+ // .append('g')
245
+
246
+ const {
247
+ seriesSelection$,
248
+ axesSelection$,
249
+ defsSelection$,
250
+ graphicGSelection$
251
+ } = gridSelectionsObservable({
252
+ selection,
253
+ pluginName,
254
+ clipPathID: 'test',
255
+ seriesLabels$: observer.seriesLabels$,
256
+ gridContainerPosition$: observer.gridContainerPosition$,
257
+ gridAxesTransform$: observer.gridAxesTransform$,
258
+ gridGraphicTransform$: observer.gridGraphicTransform$
259
+ })
222
260
 
223
261
  observer.layout$.pipe(
224
262
  takeUntil(destroy$),
@@ -228,15 +266,15 @@ export const GroupAux = defineGridPlugin(pluginName, DEFAULT_GROUP_AREA_PARAMS)(
228
266
  .attr('height', d.rootHeight)
229
267
  })
230
268
 
231
- observer.gridAxesTransform$
232
- .pipe(
233
- takeUntil(destroy$),
234
- map(d => d.value),
235
- distinctUntilChanged()
236
- ).subscribe(d => {
237
- axisSelection
238
- .style('transform', d)
239
- })
269
+ // observer.gridAxesTransform$
270
+ // .pipe(
271
+ // takeUntil(destroy$),
272
+ // map(d => d.value),
273
+ // distinctUntilChanged()
274
+ // ).subscribe(d => {
275
+ // axisSelection
276
+ // .style('transform', d)
277
+ // })
240
278
 
241
279
  // const visibleComputedData$ = observer.computedData$.pipe(
242
280
  // takeUntil(destroy$),
@@ -379,176 +417,253 @@ export const GroupAux = defineGridPlugin(pluginName, DEFAULT_GROUP_AREA_PARAMS)(
379
417
  distinctUntilChanged()
380
418
  )
381
419
 
382
- combineLatest({
383
- computedData: observer.computedData$,
384
- gridAxesSize: observer.gridAxesSize$,
385
- fullParams: observer.fullParams$,
386
- fullChartParams: observer.fullChartParams$,
387
- highlightTarget: highlightTarget$,
388
- SeriesDataMap: observer.SeriesDataMap$,
389
- GroupDataMap: observer.GroupDataMap$,
390
- gridGroupPositionFn: gridGroupPositionFn$,
391
- groupScale: groupScale$,
392
- }).pipe(
393
- takeUntil(destroy$),
394
- switchMap(async (d) => d),
395
- ).subscribe(data => {
420
+ // combineLatest({
421
+ // computedData: observer.computedData$,
422
+ // gridAxesSize: observer.gridAxesSize$,
423
+ // fullParams: observer.fullParams$,
424
+ // fullChartParams: observer.fullChartParams$,
425
+ // highlightTarget: highlightTarget$,
426
+ // SeriesDataMap: observer.SeriesDataMap$,
427
+ // GroupDataMap: observer.GroupDataMap$,
428
+ // gridGroupPositionFn: gridGroupPositionFn$,
429
+ // groupScale: groupScale$,
430
+ // }).pipe(
431
+ // takeUntil(destroy$),
432
+ // switchMap(async (d) => d),
433
+ // ).subscribe(data => {
396
434
 
397
- // store.selection
398
- rootSelection
399
- .on('mouseover', (event, datum) => {
400
- // event.stopPropagation()
401
-
402
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
403
-
404
- subject.event$.next({
405
- type: 'grid',
406
- pluginName: name,
407
- eventName: 'mouseover',
408
- highlightTarget: data.highlightTarget,
409
- datum: null,
410
- gridIndex: 0, // @Q@ 暫不處理
411
- series: [],
412
- seriesIndex: -1,
413
- seriesLabel: '',
414
- groups: data.GroupDataMap.get(groupLabel) ?? [],
415
- groupIndex,
416
- groupLabel,
417
- event,
418
- data: data.computedData
419
- })
420
- })
421
- .on('mousemove', (event, datum) => {
422
- // event.stopPropagation()
435
+ // // store.selection
436
+ // rootSelection
437
+ // .on('mouseover', (event, datum) => {
438
+ // // event.stopPropagation()
439
+
440
+ // const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
441
+
442
+ // subject.event$.next({
443
+ // type: 'grid',
444
+ // pluginName: name,
445
+ // eventName: 'mouseover',
446
+ // highlightTarget: data.highlightTarget,
447
+ // datum: null,
448
+ // gridIndex: 0, // @Q@ 暫不處理
449
+ // series: [],
450
+ // seriesIndex: -1,
451
+ // seriesLabel: '',
452
+ // groups: data.GroupDataMap.get(groupLabel) ?? [],
453
+ // // groups: [],
454
+ // groupIndex,
455
+ // groupLabel,
456
+ // event,
457
+ // data: data.computedData
458
+ // })
459
+ // })
460
+ // .on('mousemove', (event, datum) => {
461
+ // // event.stopPropagation()
462
+
463
+ // const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
464
+
465
+ // subject.event$.next({
466
+ // type: 'grid',
467
+ // pluginName: name,
468
+ // eventName: 'mousemove',
469
+ // highlightTarget: data.highlightTarget,
470
+ // datum: null,
471
+ // gridIndex: 0, // @Q@ 暫不處理
472
+ // series: [],
473
+ // seriesIndex: -1,
474
+ // seriesLabel: '',
475
+ // groups: data.GroupDataMap.get(groupLabel) ?? [],
476
+ // // groups: [],
477
+ // groupIndex,
478
+ // groupLabel,
479
+ // event,
480
+ // data: data.computedData
481
+ // })
482
+ // })
483
+ // .on('mouseout', (event, datum) => {
484
+ // // event.stopPropagation()
485
+
486
+ // const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
487
+
488
+ // subject.event$.next({
489
+ // type: 'grid',
490
+ // pluginName: name,
491
+ // eventName: 'mouseout',
492
+ // highlightTarget: data.highlightTarget,
493
+ // datum: null,
494
+ // gridIndex: 0, // @Q@ 暫不處理
495
+ // series: [],
496
+ // seriesIndex: -1,
497
+ // seriesLabel: '',
498
+ // groups: data.GroupDataMap.get(groupLabel) ?? [],
499
+ // // groups: [],
500
+ // groupIndex,
501
+ // groupLabel,
502
+ // event,
503
+ // data: data.computedData
504
+ // })
505
+ // })
506
+ // .on('click', (event, datum) => {
507
+ // event.stopPropagation()
508
+
509
+ // const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
510
+
511
+ // subject.event$.next({
512
+ // type: 'grid',
513
+ // pluginName: name,
514
+ // eventName: 'click',
515
+ // highlightTarget: data.highlightTarget,
516
+ // datum: null,
517
+ // gridIndex: 0, // @Q@ 暫不處理
518
+ // series: [],
519
+ // seriesIndex: -1,
520
+ // seriesLabel: '',
521
+ // // groups: data.GroupDataMap.get(groupLabel) ?? [],
522
+ // groups: [],
523
+ // groupIndex,
524
+ // groupLabel,
525
+ // event,
526
+ // data: data.computedData
527
+ // })
528
+ // })
423
529
 
424
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
530
+ // // barSelection$.next(barSelection!)
531
+ // })
425
532
 
426
- subject.event$.next({
427
- type: 'grid',
428
- pluginName: name,
429
- eventName: 'mousemove',
430
- highlightTarget: data.highlightTarget,
431
- datum: null,
432
- gridIndex: 0, // @Q@ 暫不處理
433
- series: [],
434
- seriesIndex: -1,
435
- seriesLabel: '',
436
- groups: data.GroupDataMap.get(groupLabel) ?? [],
437
- groupIndex,
438
- groupLabel,
439
- event,
440
- data: data.computedData
441
- })
442
- })
443
- .on('mouseout', (event, datum) => {
444
- // event.stopPropagation()
533
+ const rootMousemove$: Observable<any> = d3EventObservable(rootSelection, 'mousemove').pipe(
534
+ takeUntil(destroy$),
535
+ )
445
536
 
446
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
447
537
 
448
- subject.event$.next({
449
- type: 'grid',
450
- pluginName: name,
451
- eventName: 'mouseout',
452
- highlightTarget: data.highlightTarget,
453
- datum: null,
454
- gridIndex: 0, // @Q@ 暫不處理
455
- series: [],
456
- seriesIndex: -1,
457
- seriesLabel: '',
458
- groups: data.GroupDataMap.get(groupLabel) ?? [],
459
- groupIndex,
460
- groupLabel,
461
- event,
462
- data: data.computedData
463
- })
464
- })
465
- .on('click', (event, datum) => {
466
- event.stopPropagation()
538
+ // const mousemoveGroupLabel$ = combineLatest({
539
+ // rootMousemove: rootMousemove$,
540
+ // gridGroupPositionFn: gridGroupPositionFn$,
541
+ // }).pipe(
542
+ // takeUntil(destroy$),
543
+ // switchMap(async d => d),
544
+ // map(data => {
545
+ // const { groupIndex, groupLabel } = data.gridGroupPositionFn(data.rootMousemove)
546
+ // return { groupIndex, groupLabel }
547
+ // }),
548
+ // shareReplay(1)
549
+ // )
467
550
 
468
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
551
+ const labelTransform$ = combineLatest({
552
+ fullParams: observer.fullParams$,
553
+ fullDataFormatter: observer.fullDataFormatter$,
554
+ gridAxesReverseTransform: observer.gridAxesReverseTransform$,
555
+ gridContainerPosition: observer.gridContainerPosition$
556
+ }).pipe(
557
+ takeUntil(destroy$),
558
+ switchMap(async d => d),
559
+ map(data => {
560
+ const axisReverseTranslateValue = `translate(${data.gridAxesReverseTransform.translate[0]}px, ${data.gridAxesReverseTransform.translate[1]}px)`
561
+ const axisReverseRotateValue = `rotate(${data.gridAxesReverseTransform.rotate}deg) rotateX(${data.gridAxesReverseTransform.rotateX}deg) rotateY(${data.gridAxesReverseTransform.rotateY}deg)`
562
+ const containerScaleReverseScaleValue = `scale(${1 / data.gridContainerPosition[0].scale[0]}, ${1 / data.gridContainerPosition[0].scale[1]})`
563
+ const tickTextRotateDeg = (data.fullDataFormatter.grid.groupAxis.position === 'left' && data.fullDataFormatter.grid.valueAxis.position === 'top')
564
+ || (data.fullDataFormatter.grid.groupAxis.position === 'right' && data.fullDataFormatter.grid.valueAxis.position === 'bottom')
565
+ // ? data.fullParams.tickTextRotate + 180 // 修正文字倒轉
566
+ // : data.fullParams.tickTextRotate
567
+ ? 180 // 修正文字倒轉
568
+ : 0
569
+
570
+ const textRotateValue = `rotate(${tickTextRotateDeg}deg)`
571
+
572
+ // 必須按照順序(先抵消外層rotate,再抵消最外層scale,最後再做本身的rotate)
573
+ return `${axisReverseTranslateValue} ${axisReverseRotateValue} ${containerScaleReverseScaleValue} ${textRotateValue}`
574
+ }),
575
+ distinctUntilChanged()
576
+ )
469
577
 
470
- subject.event$.next({
471
- type: 'grid',
472
- pluginName: name,
473
- eventName: 'click',
474
- highlightTarget: data.highlightTarget,
475
- datum: null,
476
- gridIndex: 0, // @Q@ 暫不處理
477
- series: [],
478
- seriesIndex: -1,
479
- seriesLabel: '',
480
- groups: data.GroupDataMap.get(groupLabel) ?? [],
481
- groupIndex,
482
- groupLabel,
483
- event,
484
- data: data.computedData
485
- })
486
- })
578
+ const columnAmount$ = observer.gridContainerPosition$.pipe(
579
+ takeUntil(destroy$),
580
+ map(gridContainerPosition => {
581
+ const maxColumnIndex = gridContainerPosition.reduce((acc, current) => {
582
+ return current.columnIndex > acc ? current.columnIndex : acc
583
+ }, 0)
584
+ return maxColumnIndex + 1
585
+ }),
586
+ distinctUntilChanged()
587
+ )
487
588
 
488
- // barSelection$.next(barSelection!)
489
- })
589
+ const rowAmount$ = observer.gridContainerPosition$.pipe(
590
+ takeUntil(destroy$),
591
+ map(gridContainerPosition => {
592
+ const maxRowIndex = gridContainerPosition.reduce((acc, current) => {
593
+ return current.rowIndex > acc ? current.rowIndex : acc
594
+ }, 0)
595
+ return maxRowIndex + 1
596
+ }),
597
+ distinctUntilChanged()
598
+ )
490
599
 
491
- // -- highlight(無論highlightTarget設定為何,一律依從groupLabel來顯示) --
492
600
  combineLatest({
493
- // highlight: highlight$,
494
- event: subject.event$.pipe(
495
- filter(d => d.eventName === 'mouseover' || d.eventName === 'mousemove')
496
- ),
601
+ axesSelection: axesSelection$,
602
+ columnAmount: columnAmount$,
603
+ rowAmount: rowAmount$,
604
+ layout: observer.layout$,
605
+ rootMousemove: rootMousemove$,
606
+ gridGroupPositionFn: gridGroupPositionFn$,
497
607
  computedData: observer.computedData$,
498
608
  groupScale: groupScale$,
499
609
  gridAxesSize: observer.gridAxesSize$,
500
610
  fullParams: observer.fullParams$,
611
+ fullDataFormatter: observer.fullDataFormatter$,
501
612
  fullChartParams: observer.fullChartParams$,
502
613
  highlightTarget: highlightTarget$,
503
- gridAxesReverseTransform: observer.gridAxesReverseTransform$,
614
+ // gridAxesReverseTransform: observer.gridAxesReverseTransform$,
615
+ labelTransform: labelTransform$,
504
616
  GroupDataMap: observer.GroupDataMap$,
505
- gridGroupPositionFn: gridGroupPositionFn$,
506
617
  textSizePx: observer.textSizePx$
507
- }).pipe(
508
- takeUntil(destroy$),
509
- switchMap(async d => d)
510
- ).subscribe(data => {
511
- // const groups = data.event.eventName === 'mouseover' || data.event.eventName === 'mousemove'
512
- // ? data.event.groups
513
- // : []
514
-
515
- // const groupLabel = data.event.eventName === 'mouseover' || data.event.eventName === 'mousemove'
516
- // ? data.event.groupLabel
517
- // : ''
518
- const axisX = data.groupScale(data.event.groupLabel) ?? 0
618
+ }).subscribe(data => {
619
+ // 由於event座標是基於底層的,但是container會有多欄,所以要重新計算
620
+ const eventData = {
621
+ offsetX: data.rootMousemove.offsetX * data.columnAmount % data.layout.rootWidth,
622
+ offsetY: data.rootMousemove.offsetY * data.rowAmount % data.layout.rootHeight
623
+ }
624
+ // 依event的座標取得group資料
625
+ const { groupIndex, groupLabel } = data.gridGroupPositionFn(eventData)
626
+
627
+ const axisX = data.groupScale(groupLabel) ?? 0
519
628
 
520
629
  const lineData = createLineData({
521
- groupLabel: data.event.groupLabel,
630
+ groupLabel: groupLabel,
522
631
  axisX,
523
632
  axisHeight: data.gridAxesSize.height,
524
633
  fullParams: data.fullParams,
525
634
  })
526
635
  renderLine({
527
- selection: axisSelection,
636
+ // selection: axisSelection,
637
+ selection: data.axesSelection,
528
638
  pluginName: name,
529
639
  lineData,
530
640
  fullParams: data.fullParams,
531
641
  fullChartParams: data.fullChartParams
532
642
  })
533
643
  const labelData = createLabelData({
534
- groupLabel: data.event.groupLabel,
644
+ groupLabel: groupLabel,
535
645
  axisX,
536
646
  fullParams: data.fullParams
537
647
  })
538
648
  const labelSelection = renderLabel({
539
- selection: axisSelection,
649
+ // selection: axisSelection,
650
+ selection: data.axesSelection,
540
651
  labelData,
541
652
  fullParams: data.fullParams,
653
+ fullDataFormatter: data.fullDataFormatter,
542
654
  fullChartParams: data.fullChartParams,
543
- gridAxesReverseTransformValue: data.gridAxesReverseTransform.value,
655
+ // gridAxesReverseTransformValue: data.gridAxesReverseTransform.value,
656
+ labelTransform: data.labelTransform,
544
657
  textSizePx: data.textSizePx
545
658
  })
546
659
 
547
660
  // label的事件
548
661
  labelSelection
549
662
  .on('mouseover', (event, datum) => {
550
-
551
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
663
+ event.stopPropagation()
664
+ // const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
665
+
666
+ isLabelMouseover = true
552
667
 
553
668
  subject.event$.next({
554
669
  type: 'grid',
@@ -560,7 +675,7 @@ export const GroupAux = defineGridPlugin(pluginName, DEFAULT_GROUP_AREA_PARAMS)(
560
675
  series: [],
561
676
  seriesIndex: -1,
562
677
  seriesLabel: '',
563
- groups: data.event.groups,
678
+ groups: data.GroupDataMap.get(groupLabel) ?? [],
564
679
  groupIndex,
565
680
  groupLabel,
566
681
  event,
@@ -568,7 +683,8 @@ export const GroupAux = defineGridPlugin(pluginName, DEFAULT_GROUP_AREA_PARAMS)(
568
683
  })
569
684
  })
570
685
  .on('mousemove', (event, datum) => {
571
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
686
+ event.stopPropagation()
687
+ // const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
572
688
 
573
689
  subject.event$.next({
574
690
  type: 'grid',
@@ -580,7 +696,7 @@ export const GroupAux = defineGridPlugin(pluginName, DEFAULT_GROUP_AREA_PARAMS)(
580
696
  series: [],
581
697
  seriesIndex: -1,
582
698
  seriesLabel: '',
583
- groups: data.event.groups,
699
+ groups: data.GroupDataMap.get(groupLabel) ?? [],
584
700
  groupIndex,
585
701
  groupLabel,
586
702
  event,
@@ -588,7 +704,10 @@ export const GroupAux = defineGridPlugin(pluginName, DEFAULT_GROUP_AREA_PARAMS)(
588
704
  })
589
705
  })
590
706
  .on('mouseout', (event, datum) => {
591
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
707
+ event.stopPropagation()
708
+ // const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
709
+
710
+ isLabelMouseover = false
592
711
 
593
712
  subject.event$.next({
594
713
  type: 'grid',
@@ -600,7 +719,7 @@ export const GroupAux = defineGridPlugin(pluginName, DEFAULT_GROUP_AREA_PARAMS)(
600
719
  series: [],
601
720
  seriesIndex: -1,
602
721
  seriesLabel: '',
603
- groups: data.event.groups,
722
+ groups: data.GroupDataMap.get(groupLabel) ?? [],
604
723
  groupIndex,
605
724
  groupLabel,
606
725
  event,
@@ -608,7 +727,8 @@ export const GroupAux = defineGridPlugin(pluginName, DEFAULT_GROUP_AREA_PARAMS)(
608
727
  })
609
728
  })
610
729
  .on('click', (event, datum) => {
611
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
730
+ event.stopPropagation()
731
+ // const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
612
732
 
613
733
  subject.event$.next({
614
734
  type: 'grid',
@@ -620,23 +740,180 @@ export const GroupAux = defineGridPlugin(pluginName, DEFAULT_GROUP_AREA_PARAMS)(
620
740
  series: [],
621
741
  seriesIndex: -1,
622
742
  seriesLabel: '',
623
- groups: data.event.groups,
743
+ groups: data.GroupDataMap.get(groupLabel) ?? [],
624
744
  groupIndex,
625
745
  groupLabel,
626
746
  event,
627
747
  data: data.computedData
628
748
  })
629
749
  })
750
+
630
751
  })
631
752
 
632
- const rootMouseout$ = d3EventObservable(rootRectSelection, 'mouseout').pipe(
753
+ // // -- highlight(無論highlightTarget設定為何,一律依從groupLabel來顯示) --
754
+ // combineLatest({
755
+ // event: subject.event$.pipe(
756
+ // filter(d => d.eventName === 'mouseover' || d.eventName === 'mousemove')
757
+ // ),
758
+ // computedData: observer.computedData$,
759
+ // groupScale: groupScale$,
760
+ // gridAxesSize: observer.gridAxesSize$,
761
+ // fullParams: observer.fullParams$,
762
+ // fullChartParams: observer.fullChartParams$,
763
+ // highlightTarget: highlightTarget$,
764
+ // gridAxesReverseTransform: observer.gridAxesReverseTransform$,
765
+ // GroupDataMap: observer.GroupDataMap$,
766
+ // gridGroupPositionFn: gridGroupPositionFn$,
767
+ // textSizePx: observer.textSizePx$
768
+ // }).pipe(
769
+ // takeUntil(destroy$),
770
+ // switchMap(async d => d)
771
+ // ).subscribe(data => {
772
+ // // const groups = data.event.eventName === 'mouseover' || data.event.eventName === 'mousemove'
773
+ // // ? data.event.groups
774
+ // // : []
775
+
776
+ // // const groupLabel = data.event.eventName === 'mouseover' || data.event.eventName === 'mousemove'
777
+ // // ? data.event.groupLabel
778
+ // // : ''
779
+ // const axisX = data.groupScale(data.event.groupLabel) ?? 0
780
+
781
+ // const lineData = createLineData({
782
+ // groupLabel: data.event.groupLabel,
783
+ // axisX,
784
+ // axisHeight: data.gridAxesSize.height,
785
+ // fullParams: data.fullParams,
786
+ // })
787
+ // renderLine({
788
+ // selection: axisSelection,
789
+ // pluginName: name,
790
+ // lineData,
791
+ // fullParams: data.fullParams,
792
+ // fullChartParams: data.fullChartParams
793
+ // })
794
+ // const labelData = createLabelData({
795
+ // groupLabel: data.event.groupLabel,
796
+ // axisX,
797
+ // fullParams: data.fullParams
798
+ // })
799
+ // const labelSelection = renderLabel({
800
+ // selection: axisSelection,
801
+ // labelData,
802
+ // fullParams: data.fullParams,
803
+ // fullChartParams: data.fullChartParams,
804
+ // gridAxesReverseTransformValue: data.gridAxesReverseTransform.value,
805
+ // textSizePx: data.textSizePx
806
+ // })
807
+
808
+ // // label的事件
809
+ // labelSelection
810
+ // .on('mouseover', (event, datum) => {
811
+
812
+ // const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
813
+
814
+ // subject.event$.next({
815
+ // type: 'grid',
816
+ // pluginName: name,
817
+ // eventName: 'mouseover',
818
+ // highlightTarget: data.highlightTarget,
819
+ // datum: null,
820
+ // gridIndex: 0, // @Q@ 暫不處理
821
+ // series: [],
822
+ // seriesIndex: -1,
823
+ // seriesLabel: '',
824
+ // groups: data.event.groups,
825
+ // groupIndex,
826
+ // groupLabel,
827
+ // event,
828
+ // data: data.computedData
829
+ // })
830
+ // })
831
+ // .on('mousemove', (event, datum) => {
832
+ // const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
833
+
834
+ // subject.event$.next({
835
+ // type: 'grid',
836
+ // pluginName: name,
837
+ // eventName: 'mousemove',
838
+ // highlightTarget: data.highlightTarget,
839
+ // datum: null,
840
+ // gridIndex: 0, // @Q@ 暫不處理
841
+ // series: [],
842
+ // seriesIndex: -1,
843
+ // seriesLabel: '',
844
+ // groups: data.event.groups,
845
+ // groupIndex,
846
+ // groupLabel,
847
+ // event,
848
+ // data: data.computedData
849
+ // })
850
+ // })
851
+ // .on('mouseout', (event, datum) => {
852
+ // const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
853
+
854
+ // subject.event$.next({
855
+ // type: 'grid',
856
+ // pluginName: name,
857
+ // eventName: 'mouseout',
858
+ // highlightTarget: data.highlightTarget,
859
+ // datum: null,
860
+ // gridIndex: 0, // @Q@ 暫不處理
861
+ // series: [],
862
+ // seriesIndex: -1,
863
+ // seriesLabel: '',
864
+ // groups: data.event.groups,
865
+ // groupIndex,
866
+ // groupLabel,
867
+ // event,
868
+ // data: data.computedData
869
+ // })
870
+ // })
871
+ // .on('click', (event, datum) => {
872
+ // const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
873
+
874
+ // subject.event$.next({
875
+ // type: 'grid',
876
+ // pluginName: name,
877
+ // eventName: 'click',
878
+ // highlightTarget: data.highlightTarget,
879
+ // datum: null,
880
+ // gridIndex: 0, // @Q@ 暫不處理
881
+ // series: [],
882
+ // seriesIndex: -1,
883
+ // seriesLabel: '',
884
+ // groups: data.event.groups,
885
+ // groupIndex,
886
+ // groupLabel,
887
+ // event,
888
+ // data: data.computedData
889
+ // })
890
+ // })
891
+ // })
892
+
893
+
894
+
895
+ const rootRectMouseout$ = d3EventObservable(rootRectSelection, 'mouseout').pipe(
633
896
  takeUntil(destroy$),
634
897
  )
635
898
 
636
- rootMouseout$.subscribe(event => {
637
- console.log('rootMouseout')
638
- removeLine(axisSelection)
639
- removeLabel(axisSelection)
899
+
900
+ combineLatest({
901
+ rootRectMouseout: rootRectMouseout$,
902
+ axesSelection: axesSelection$,
903
+ }).pipe(
904
+ takeUntil(destroy$),
905
+ switchMap(async d => d)
906
+ ).subscribe(data => {
907
+
908
+ setTimeout(() => {
909
+ // @Q@ workaround - 不知為何和 label 會有衝突,當滑鼠移動到 label 上時,會觸發 mouseout 事件
910
+ if (isLabelMouseover == true) {
911
+ return
912
+ }
913
+
914
+ removeLine(data.axesSelection)
915
+ removeLabel(data.axesSelection)
916
+ })
640
917
  })
641
918
 
642
919
  return () => {