@@ -4,6 +4,7 @@ import { Column, ColumnOptions, Bar, BarOptions } from '../../../src';
4
4
import { createDiv } from '../../utils/dom' ;
5
5
import { delay } from '../../utils/delay' ;
6
6
import { near } from '../../utils/number' ;
7
+ import { dispatchEvent } from '../../utils/event' ;
7
8
import { subSalesByArea } from '../../data/sales' ;
8
9
9
10
const DATA = [
@@ -66,19 +67,27 @@ describe('column conversion tag', () => {
66
67
expect ( texts [ idx - 1 ] . attr ( 'text' ) ) . toBe ( ( ( DATA [ idx ] . y / DATA [ idx - 1 ] . y ) * 100 ) . toFixed ( 2 ) + '%' ) ;
67
68
}
68
69
} ) ;
70
+ texts . forEach ( ( text , idx ) => {
71
+ // origin info
72
+ expect ( text . get ( 'origin' ) . element ) . toBe ( plot . chart . geometries [ 0 ] . elements [ idx ] ) ;
73
+ expect ( text . get ( 'origin' ) . nextElement ) . toBe ( plot . chart . geometries [ 0 ] . elements [ idx + 1 ] ) ;
74
+ } ) ;
69
75
70
76
// 箭头
71
77
const arrows = group . findAllByName ( 'conversion-tag-arrow' ) ;
72
78
const arrowIds = arrows . map ( ( arrow ) => arrow . get ( 'id' ) ) as string [ ] ;
73
79
// 每一个都有唯一的 ID
74
80
expect ( uniq ( arrowIds ) ) . toHaveLength ( DATA . length - 1 ) ;
75
81
expect ( arrows ) . toHaveLength ( DATA . length - 1 ) ;
76
- arrows . forEach ( ( arrow ) => {
82
+ arrows . forEach ( ( arrow , idx ) => {
77
83
const bbox = arrow . getBBox ( ) ;
78
84
// spacing: 8
79
85
expect ( near ( bbox . width , totalWidth - 8 * 2 ) ) . toBeTruthy ( ) ;
80
86
// size: 32
81
87
expect ( near ( bbox . height , 32 ) ) . toBeTruthy ( ) ;
88
+ // origin info
89
+ expect ( arrow . get ( 'origin' ) . element ) . toBe ( plot . chart . geometries [ 0 ] . elements [ idx ] ) ;
90
+ expect ( arrow . get ( 'origin' ) . nextElement ) . toBe ( plot . chart . geometries [ 0 ] . elements [ idx + 1 ] ) ;
82
91
} ) ;
83
92
} ) ;
84
93
@@ -604,3 +613,45 @@ describe('conversion tag disabled with seriesField', () => {
604
613
expect ( group ) . toBeUndefined ( ) ;
605
614
} ) ;
606
615
} ) ;
616
+
617
+ describe ( 'conversion tag listent to events' , ( ) => {
618
+ const container = createDiv ( ) ;
619
+
620
+ const options : ColumnOptions = {
621
+ data : DATA ,
622
+ autoFit : false ,
623
+ width : 600 ,
624
+ height : 400 ,
625
+ xField : 'x' ,
626
+ yField : 'y' ,
627
+ conversionTag : { } ,
628
+ animation : false ,
629
+ } ;
630
+ const plot = new Column ( container , options ) ;
631
+
632
+ it ( 'events' , async ( ) => {
633
+ plot . render ( ) ;
634
+ let c ;
635
+ plot . on ( 'conversion-tag-group:mouseenter' , ( evt ) => {
636
+ c = evt ?. target ;
637
+ } ) ;
638
+
639
+ await delay ( 100 ) ;
640
+
641
+ const foreground = plot . chart . foregroundGroup ;
642
+ const group : IGroup = foreground . findAllByName ( 'conversion-tag-group' ) [ 0 ] as IGroup ;
643
+ // 箭头
644
+ const arrows = group . findAllByName ( 'conversion-tag-arrow' ) ;
645
+ const texts = group . findAllByName ( 'conversion-tag-text' ) ;
646
+
647
+ const canvas = plot . chart . getCanvas ( ) ;
648
+ const bbox = arrows [ 0 ] . getCanvasBBox ( ) ;
649
+ dispatchEvent ( bbox , canvas , 'mouseenter' ) ;
650
+
651
+ await delay ( 100 ) ;
652
+
653
+ expect ( c ?. get ( 'id' ) ) . toBe ( texts [ 0 ] . get ( 'id' ) ) ;
654
+ expect ( c ?. get ( 'origin' ) . element ) . toBe ( plot . chart . geometries [ 0 ] . elements [ 0 ] ) ;
655
+ expect ( c ?. get ( 'origin' ) . nextElement ) . toBe ( plot . chart . geometries [ 0 ] . elements [ 1 ] ) ;
656
+ } ) ;
657
+ } ) ;
0 commit comments