1
1
import { Scatter } from '../../../../src' ;
2
2
import { createDiv } from '../../../utils/dom' ;
3
+ import { delay } from '../../../utils/delay' ;
3
4
4
5
const data = [
5
6
{ x : 1 , y : 4.181 } ,
@@ -72,7 +73,7 @@ describe('scatter', () => {
72
73
expect ( elements [ 0 ] . getModel ( ) . size ) . toBe ( 5 ) ;
73
74
} ) ;
74
75
75
- it ( 'regressionLine: algorithm' , ( ) => {
76
+ it ( 'regressionLine: algorithm' , async ( ) => {
76
77
const scatter = new Scatter ( createDiv ( 'regressionLine*algorithm' ) , {
77
78
data,
78
79
width : 400 ,
@@ -86,16 +87,18 @@ describe('scatter', () => {
86
87
lineWidth : 1 ,
87
88
fill : '#5B8FF9' ,
88
89
} ,
90
+ animation : false ,
89
91
regressionLine : {
90
92
algorithm : [
91
- [ 0 , 0 ] ,
92
- [ 200 , 200 ] ,
93
+ [ 8 , 6 ] ,
94
+ [ 16 , 7 ] ,
95
+ [ 24 , 7 ] ,
93
96
] ,
94
97
} ,
95
98
} ) ;
96
99
97
100
scatter . render ( ) ;
98
-
101
+ await delay ( 500 ) ;
99
102
const geometry = scatter . chart . geometries [ 0 ] ;
100
103
const annotation = scatter . chart . annotation ( ) ;
101
104
// @ts -ignore
@@ -106,5 +109,50 @@ describe('scatter', () => {
106
109
// @ts -ignore
107
110
expect ( elements [ 0 ] . getModel ( ) . style . fill ) . toBe ( '#5B8FF9' ) ;
108
111
expect ( elements [ 0 ] . getModel ( ) . size ) . toBe ( 5 ) ;
112
+ const { width } = scatter . chart ;
113
+ const pathGroup = scatter . chart
114
+ . getComponents ( )
115
+ . find ( ( item ) => item . type === 'annotation' )
116
+ . component . cfg . group . cfg . children [ 0 ] . getChildren ( ) ;
117
+ const { path } = pathGroup ?. [ 0 ] ?. cfg ?. attrs ;
118
+ expect ( path . length ) . toBe ( 3 ) ;
119
+ expect ( scatter . chart . getXScale ( ) . scale ( 8 ) * width < path [ 0 ] [ 1 ] ) . toBeTruthy ( ) ;
120
+ } ) ;
121
+ it ( 'regressionLine: algorithm callback' , async ( ) => {
122
+ const scatter = new Scatter ( createDiv ( 'regressionLine*algorithm' ) , {
123
+ data,
124
+ width : 400 ,
125
+ height : 300 ,
126
+ appendPadding : 10 ,
127
+ xField : 'x' ,
128
+ yField : 'y' ,
129
+ size : 5 ,
130
+ pointStyle : {
131
+ stroke : '#777777' ,
132
+ lineWidth : 1 ,
133
+ fill : '#5B8FF9' ,
134
+ } ,
135
+ animation : false ,
136
+ regressionLine : {
137
+ algorithm : ( data ) => {
138
+ return [
139
+ [ 8 , 6 ] ,
140
+ [ 16 , 7 ] ,
141
+ [ 24 , 7 ] ,
142
+ ] ;
143
+ } ,
144
+ } ,
145
+ } ) ;
146
+
147
+ scatter . render ( ) ;
148
+ await delay ( 500 ) ;
149
+ const { width } = scatter . chart ;
150
+ const pathGroup = scatter . chart
151
+ . getComponents ( )
152
+ . find ( ( item ) => item . type === 'annotation' )
153
+ . component . cfg . group . cfg . children [ 0 ] . getChildren ( ) ;
154
+ const { path } = pathGroup ?. [ 0 ] ?. cfg ?. attrs ;
155
+ expect ( path . length ) . toBe ( 3 ) ;
156
+ expect ( scatter . chart . getXScale ( ) . scale ( 8 ) * width < path [ 0 ] [ 1 ] ) . toBeTruthy ( ) ;
109
157
} ) ;
110
158
} ) ;
0 commit comments