@@ -41,10 +41,12 @@ export default class ChartAdapterStore {
41
41
bottomIndex : 0 ,
42
42
} ;
43
43
touchValues : {
44
+ deltaXTotal ?: number ;
44
45
deltaYTotal ?: number ;
45
46
x ?: number ;
46
47
y ?: number ;
47
48
} = {
49
+ deltaXTotal : 0 ,
48
50
deltaYTotal : 0 ,
49
51
x : 0 ,
50
52
y : 0 ,
@@ -256,15 +258,22 @@ export default class ChartAdapterStore {
256
258
const { left } = chartNode . getBoundingClientRect ( ) ;
257
259
258
260
if ( this . touchValues . x && this . touchValues . y ) {
259
- const deltaX = Math . abs ( pageX - this . touchValues . x ) ;
260
- const deltaY = Math . abs ( pageY - this . touchValues . y ) ;
261
+ this . touchValues . deltaXTotal = ( this . touchValues . deltaXTotal ?? 0 ) + ( this . touchValues . x - pageX ) ;
261
262
this . touchValues . deltaYTotal = ( this . touchValues . deltaYTotal ?? 0 ) + ( this . touchValues . y - pageY ) ;
263
+ const deltaX =
264
+ e . type === 'touchend'
265
+ ? Math . abs ( this . touchValues . deltaXTotal )
266
+ : Math . abs ( pageX - this . touchValues . x ) ;
267
+ const deltaY =
268
+ e . type === 'touchend'
269
+ ? Math . abs ( this . touchValues . deltaYTotal )
270
+ : Math . abs ( pageY - this . touchValues . y ) ;
262
271
const isVerticalScroll = deltaY > deltaX ;
263
272
const x = pageX - left ;
264
273
const isForcedScrollArea = x < nonScrollableAreaWidth ;
265
274
const shouldForceMaxScroll =
266
275
Math . abs ( Number ( this . touchValues . deltaYTotal ) ) > 10 && e . type === 'touchend' ;
267
- if ( isForcedScrollArea ) {
276
+ if ( isForcedScrollArea && isVerticalScroll ) {
268
277
if ( shouldForceMaxScroll ) {
269
278
clearTimeout ( this . scrollChartParentOnTouchTimer ) ;
270
279
this . scrollableChartParent ?. scrollTo ( {
@@ -275,15 +284,15 @@ export default class ChartAdapterStore {
275
284
behavior : 'smooth' ,
276
285
} ) ;
277
286
this . scrollChartParentOnTouchTimer = undefined ;
278
- this . touchValues = { ...this . touchValues , deltaYTotal : 0 } ;
279
- } else if ( isVerticalScroll && ! this . scrollChartParentOnTouchTimer ) {
287
+ this . touchValues = { ...this . touchValues , deltaYTotal : 0 , deltaXTotal : 0 } ;
288
+ } else if ( ! this . scrollChartParentOnTouchTimer ) {
280
289
this . scrollChartParentOnTouchTimer = setTimeout ( ( ) => {
281
290
this . scrollableChartParent ?. scrollBy ( {
282
291
top : this . touchValues . deltaYTotal ,
283
292
behavior : 'smooth' ,
284
293
} ) ;
285
294
this . scrollChartParentOnTouchTimer = undefined ;
286
- this . touchValues = { ...this . touchValues , deltaYTotal : 0 } ;
295
+ this . touchValues = { ...this . touchValues , deltaYTotal : 0 , deltaXTotal : 0 } ;
287
296
} , 100 ) ;
288
297
}
289
298
}
@@ -292,7 +301,9 @@ export default class ChartAdapterStore {
292
301
}
293
302
if ( [ 'touchstart' , 'touchend' ] . includes ( e . type ) ) {
294
303
this . touchValues =
295
- e . type === 'touchstart' ? { x : pageX , y : pageY } : { deltaYTotal : this . touchValues . deltaYTotal } ;
304
+ e . type === 'touchstart'
305
+ ? { x : pageX , y : pageY }
306
+ : { deltaYTotal : this . touchValues . deltaYTotal , deltaXTotal : this . touchValues . deltaXTotal } ;
296
307
}
297
308
}
298
309
}
0 commit comments