1+ var Plotly = require ( '@lib/index' ) ;
12var Plots = require ( '@src/plots/plots' ) ;
23var Lib = require ( '@src/lib' ) ;
34
@@ -6,6 +7,10 @@ var getLegendData = require('@src/components/legend/get_legend_data');
67var helpers = require ( '@src/components/legend/helpers' ) ;
78var anchorUtils = require ( '@src/components/legend/anchor_utils' ) ;
89
10+ var d3 = require ( 'd3' ) ;
11+ var createGraphDiv = require ( '../assets/create_graph_div' ) ;
12+ var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
13+
914
1015describe ( 'legend defaults' , function ( ) {
1116 'use strict' ;
@@ -498,3 +503,40 @@ describe('legend anchor utils:', function() {
498503 } ) ;
499504 } ) ;
500505} ) ;
506+
507+ describe ( 'legend relayout update' , function ( ) {
508+ 'use strict' ;
509+
510+ afterEach ( destroyGraphDiv ) ;
511+
512+ it ( 'should update border styling' , function ( done ) {
513+ var mock = require ( '@mocks/0.json' ) ,
514+ mockCopy = Lib . extendDeep ( { } , mock ) ,
515+ gd = createGraphDiv ( ) ;
516+
517+ function assertLegendStyle ( bgColor , borderColor , borderWidth ) {
518+ var node = d3 . select ( 'g.legend' ) . select ( 'rect' ) ;
519+
520+ expect ( node . style ( 'fill' ) ) . toEqual ( bgColor ) ;
521+ expect ( node . style ( 'stroke' ) ) . toEqual ( borderColor ) ;
522+ expect ( node . style ( 'stroke-width' ) ) . toEqual ( borderWidth + 'px' ) ;
523+ }
524+
525+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( function ( ) {
526+ assertLegendStyle ( 'rgb(255, 255, 255)' , 'rgb(0, 0, 0)' , 1 ) ;
527+
528+ return Plotly . relayout ( gd , {
529+ 'legend.bordercolor' : 'red' ,
530+ 'legend.bgcolor' : 'blue'
531+ } ) ;
532+ } ) . then ( function ( ) {
533+ assertLegendStyle ( 'rgb(0, 0, 255)' , 'rgb(255, 0, 0)' , 1 ) ;
534+
535+ return Plotly . relayout ( gd , 'legend.borderwidth' , 10 ) ;
536+ } ) . then ( function ( ) {
537+ assertLegendStyle ( 'rgb(0, 0, 255)' , 'rgb(255, 0, 0)' , 10 ) ;
538+
539+ done ( ) ;
540+ } ) ;
541+ } ) ;
542+ } ) ;
0 commit comments