1
+ var Plotly = require ( '@lib/index' ) ;
1
2
var Plots = require ( '@src/plots/plots' ) ;
2
3
var Lib = require ( '@src/lib' ) ;
3
4
@@ -6,6 +7,10 @@ var getLegendData = require('@src/components/legend/get_legend_data');
6
7
var helpers = require ( '@src/components/legend/helpers' ) ;
7
8
var anchorUtils = require ( '@src/components/legend/anchor_utils' ) ;
8
9
10
+ var d3 = require ( 'd3' ) ;
11
+ var createGraphDiv = require ( '../assets/create_graph_div' ) ;
12
+ var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
13
+
9
14
10
15
describe ( 'legend defaults' , function ( ) {
11
16
'use strict' ;
@@ -498,3 +503,40 @@ describe('legend anchor utils:', function() {
498
503
} ) ;
499
504
} ) ;
500
505
} ) ;
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