@@ -71,7 +71,6 @@ legend.supplyLayoutDefaults = function(layoutIn, layoutOut, fullData) {
71
71
coerce ( 'borderwidth' ) ;
72
72
Lib . coerceFont ( coerce , 'font' , layoutOut . font ) ;
73
73
74
- coerce ( 'type' ) ;
75
74
coerce ( 'traceorder' , defaultOrder ) ;
76
75
if ( isGrouped ( layoutOut . legend ) ) coerce ( 'tracegroupgap' ) ;
77
76
@@ -462,6 +461,14 @@ legend.draw = function(td) {
462
461
. attr ( 'class' , 'scrollbox' ) ;
463
462
scrollBox . exit ( ) . remove ( ) ;
464
463
464
+ var scrollBar = legendsvg . selectAll ( 'rect.scrollbar' )
465
+ . data ( [ 0 ] ) ;
466
+ scrollBar . enter ( ) . append ( 'rect' )
467
+ . attr ( 'class' , 'scrollbar' )
468
+ . attr ( 'rx' , 20 )
469
+ . attr ( 'ry' , 2 )
470
+ . call ( Color . fill , '#808BA4' ) ;
471
+
465
472
var groups = scrollBox . selectAll ( 'g.groups' )
466
473
. data ( legendData ) ;
467
474
groups . enter ( ) . append ( 'g' )
@@ -679,22 +686,39 @@ legend.repositionLegend = function(td, traces){
679
686
lx = Math . round ( lx ) ;
680
687
ly = Math . round ( ly ) ;
681
688
682
- // Add scroll functionality
689
+
683
690
var legendsvg = fullLayout . _infolayer . selectAll ( 'svg.legend' ) ,
684
691
scrollBox = fullLayout . _infolayer . selectAll ( 'svg.legend .scrollbox' ) ,
685
- plotHeight = fullLayout . height - fullLayout . margin . t - fullLayout . margin . b ,
686
- scrollheight = Math . min ( plotHeight , legendheight ) ;
692
+ scrollBar = fullLayout . _infolayer . selectAll ( 'svg.legend .scrollbar' ) ,
693
+ bg = fullLayout . _infolayer . selectAll ( 'svg.legend .bg' ) ;
694
+
695
+ var plotHeight = fullLayout . height - fullLayout . margin . t - fullLayout . margin . b ,
696
+ scrollheight = Math . min ( plotHeight - ly , legendheight ) ,
697
+ scrollPosition = scrollBox . attr ( 'viewBox' ) ? scrollBox . attr ( 'viewBox' ) . split ( ' ' ) [ 1 ] : 0 ;
687
698
688
- scrollBox . attr ( 'viewBox' , '0 0 ' + legendwidth + ' ' + scrollheight ) ;
689
699
legendsvg . node ( ) . addEventListener ( 'wheel' , scrollHandler ) ;
700
+ legendsvg . call ( Drawing . setRect , lx , ly , legendwidth , scrollheight ) ;
701
+
702
+ bg . style ( { width : legendwidth , height : scrollheight } ) ;
703
+
704
+ scrollBox . attr ( 'viewBox' , '0 ' + scrollPosition + ' ' + legendwidth + ' ' + scrollheight ) ;
705
+
706
+ if ( td . firstRender ) scrollBar . call ( Drawing . setRect , legendwidth - 6 , 10 , 4 , 20 ) ;
690
707
691
708
function scrollHandler ( e ) {
692
709
e . preventDefault ( ) ;
693
710
694
- var scroll = scrollBox . attr ( 'viewBox' ) . split ( ' ' ) ;
695
- scroll [ 1 ] = constrain ( 0 , Math . max ( legendheight - scrollheight , 0 ) , + scroll [ 1 ] + e . deltaY ) ;
711
+ // Scale movement to simulate native scroll performance
712
+ var scrollDiff = e . deltaY / 25 ,
713
+ viewBox = scrollBox . attr ( 'viewBox' ) . split ( ' ' ) ;
714
+
715
+ var scrollBoxY = constrain ( 0 , Math . max ( legendheight - scrollheight , 0 ) , + viewBox [ 1 ] + scrollDiff ) ,
716
+ scrollBarY = scrollBoxY / legendheight * ( scrollheight ) + 10 ;
696
717
697
- scrollBox . attr ( 'viewBox' , scroll . join ( ' ' ) ) ;
718
+ viewBox [ 1 ] = scrollBoxY ;
719
+
720
+ scrollBox . attr ( 'viewBox' , viewBox . join ( ' ' ) ) ;
721
+ scrollBar . call ( Drawing . setRect , legendwidth - 6 , scrollBarY , 4 , 20 ) ;
698
722
}
699
723
700
724
function constrain ( min , max , c ) {
@@ -707,11 +731,6 @@ legend.repositionLegend = function(td, traces){
707
731
}
708
732
}
709
733
710
- fullLayout . _infolayer . selectAll ( 'svg.legend' )
711
- . call ( Drawing . setRect , lx , ly , legendwidth , scrollheight ) ;
712
- fullLayout . _infolayer . selectAll ( 'svg.legend .bg' )
713
- . style ( { width : legendwidth , height : scrollheight } ) ;
714
-
715
734
// lastly check if the margin auto-expand has changed
716
735
Plots . autoMargin ( td , 'legend' , {
717
736
x : opts . x ,
0 commit comments