@@ -16,6 +16,8 @@ var createGraphDiv = require('../assets/create_graph_div');
16
16
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
17
17
var assertPlotSize = require ( '../assets/custom_assertions' ) . assertPlotSize ;
18
18
19
+ var Drawing = require ( '@src/components/drawing' ) ;
20
+
19
21
describe ( 'legend defaults' , function ( ) {
20
22
'use strict' ;
21
23
@@ -665,6 +667,43 @@ describe('legend relayout update', function() {
665
667
. catch ( failTest )
666
668
. then ( done ) ;
667
669
} ) ;
670
+
671
+ describe ( 'should update legend valign' , function ( ) {
672
+ var mock = require ( '@mocks/legend_valign_top.json' ) ;
673
+ var gd ;
674
+
675
+ beforeEach ( function ( ) {
676
+ gd = createGraphDiv ( ) ;
677
+ } ) ;
678
+ afterEach ( destroyGraphDiv ) ;
679
+
680
+ function markerOffsetY ( ) {
681
+ var translate = Drawing . getTranslate ( d3 . select ( '.legend .traces .layers' ) ) ;
682
+ return translate . y ;
683
+ }
684
+
685
+ it ( 'it should translate markers' , function ( done ) {
686
+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
687
+
688
+ var top , middle , bottom ;
689
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout )
690
+ . then ( function ( ) {
691
+ top = markerOffsetY ( ) ;
692
+ return Plotly . relayout ( gd , 'legend.valign' , 'middle' ) ;
693
+ } )
694
+ . then ( function ( ) {
695
+ middle = markerOffsetY ( ) ;
696
+ expect ( middle ) . toBeGreaterThan ( top ) ;
697
+ return Plotly . relayout ( gd , 'legend.valign' , 'bottom' ) ;
698
+ } )
699
+ . then ( function ( ) {
700
+ bottom = markerOffsetY ( ) ;
701
+ expect ( bottom ) . toBeGreaterThan ( middle ) ;
702
+ } )
703
+ . catch ( failTest )
704
+ . then ( done ) ;
705
+ } ) ;
706
+ } ) ;
668
707
} ) ;
669
708
670
709
describe ( 'legend orientation change:' , function ( ) {
0 commit comments