@@ -41,10 +41,16 @@ export default class ChartAdapterStore {
41
41
bottomIndex : 0 ,
42
42
} ;
43
43
touchValues : {
44
+ deltaYTotal ?: number ;
44
45
x ?: number ;
45
46
y ?: number ;
46
47
yOnTouchEnd ?: number ;
47
- } = { } ;
48
+ } = {
49
+ deltaYTotal : 0 ,
50
+ x : 0 ,
51
+ y : 0 ,
52
+ yOnTouchEnd : 0 ,
53
+ } ;
48
54
49
55
isOverFlutterCharts = false ;
50
56
enableVerticalScrollTimer ?: ReturnType < typeof setTimeout > ;
@@ -247,28 +253,33 @@ export default class ChartAdapterStore {
247
253
) {
248
254
const { pageX, pageY } = e . changedTouches [ 0 ] ;
249
255
if ( [ 'touchstart' , 'touchend' ] . includes ( e . type ) ) {
250
- this . touchValues = e . type === 'touchstart' ? { x : pageX , y : pageY } : { yOnTouchEnd : pageY } ;
256
+ this . touchValues =
257
+ e . type === 'touchstart'
258
+ ? { x : pageX , y : pageY }
259
+ : { yOnTouchEnd : pageY , deltaYTotal : this . touchValues . deltaYTotal } ;
251
260
} else if ( e . type === 'touchmove' ) {
252
261
const nonScrollableAreaWidth = chartNode . offsetWidth - this . mainStore . chart . yAxisWidth ;
253
262
const { left } = chartNode . getBoundingClientRect ( ) ;
254
263
255
264
if ( this . touchValues . x && this . touchValues . y ) {
256
265
const deltaX = Math . abs ( pageX - this . touchValues . x ) ;
257
266
const deltaY = Math . abs ( pageY - this . touchValues . y ) ;
267
+ this . touchValues . deltaYTotal = ( this . touchValues . deltaYTotal ?? 0 ) + ( this . touchValues . y - pageY ) ;
258
268
const isVerticalScroll = deltaY > deltaX ;
259
269
const x = pageX - left ;
260
270
if ( x < nonScrollableAreaWidth && isVerticalScroll && ! this . scrollChartParentOnTouchTimer ) {
261
271
this . touchValues . yOnTouchEnd = undefined ;
262
272
this . scrollChartParentOnTouchTimer = setTimeout ( ( ) => {
263
273
this . scrollableChartParent ?. scrollBy ( {
264
- top : pageY - Number ( this . touchValues . yOnTouchEnd ?? this . touchValues . y ) ,
274
+ top : this . touchValues . deltaYTotal ,
265
275
behavior : 'smooth' ,
266
276
} ) ;
267
277
this . scrollChartParentOnTouchTimer = undefined ;
278
+ this . touchValues = { ...this . touchValues , deltaYTotal : 0 } ;
268
279
} , 100 ) ;
269
280
}
270
281
}
271
- this . touchValues = { x : pageX , y : pageY } ;
282
+ this . touchValues = { ... this . touchValues , x : pageX , y : pageY } ;
272
283
}
273
284
}
274
285
}
0 commit comments