@@ -8,7 +8,7 @@ import { start as dragEventStart, move as dragEventMove, end as dragEventEnd } f
88
99const _min = Math . min ;
1010const _max = Math . max ;
11- const MIN_SCROLL_BAR_SIZE = 2 ;
11+ const MIN_SCROLL_BAR_SIZE = 10 ;
1212
1313export const ScrollBar = function ( renderer , group ) {
1414 this . _translator = new Translator2D ( { } , { } , { } ) ;
@@ -221,16 +221,48 @@ ScrollBar.prototype = {
221221 const that = this ;
222222 const visibleArea = that . _translator . getCanvasVisibleArea ( ) ;
223223
224- x1 = _max ( x1 , visibleArea . min ) ;
225- x1 = _min ( x1 , visibleArea . max ) ;
224+ const min = visibleArea . min ;
225+ const max = visibleArea . max ;
226226
227- x2 = _min ( x2 , visibleArea . max ) ;
228- x2 = _max ( x2 , visibleArea . min ) ;
227+ if ( max <= min ) {
228+ return ;
229+ }
230+
231+ if ( x1 > x2 ) {
232+ [ x1 , x2 ] = [ x2 , x1 ] ;
233+ }
234+
235+ x1 = Math . max ( x1 , min ) ;
236+ x2 = Math . min ( x2 , max ) ;
237+
238+ if ( x2 - x1 < MIN_SCROLL_BAR_SIZE ) {
239+ if ( max - min < MIN_SCROLL_BAR_SIZE ) {
240+ x1 = min ;
241+ x2 = max ;
242+ } else {
243+ const center = ( x1 + x2 ) / 2 ;
244+
245+ x1 = center - MIN_SCROLL_BAR_SIZE / 2 ;
246+ x2 = center + MIN_SCROLL_BAR_SIZE / 2 ;
247+
248+ if ( x1 < min ) {
249+ x1 = min ;
250+ x2 = min + MIN_SCROLL_BAR_SIZE ;
251+ } else if ( x2 > max ) {
252+ x2 = max ;
253+ x1 = max - MIN_SCROLL_BAR_SIZE ;
254+ }
255+ }
256+ }
257+
258+ x1 = Math . max ( x1 , min ) ;
259+ x2 = Math . min ( x2 , max ) ;
260+
261+ const height = Math . max ( x2 - x1 , 0 ) ;
229262
230- const height = Math . abs ( x2 - x1 ) ;
231263 that . _scroll . attr ( {
232264 y : x1 ,
233- height : height < MIN_SCROLL_BAR_SIZE ? MIN_SCROLL_BAR_SIZE : height
265+ height,
234266 } ) ;
235267 }
236268} ;
0 commit comments