@@ -10,6 +10,7 @@ var anchorUtils = require('@src/components/legend/anchor_utils');
10
10
var d3 = require ( 'd3' ) ;
11
11
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
12
12
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
13
+ var customMatchers = require ( '../assets/custom_matchers' ) ;
13
14
14
15
15
16
describe ( 'legend defaults' , function ( ) {
@@ -563,3 +564,59 @@ describe('legend orientation change:', function() {
563
564
} ) ;
564
565
} ) ;
565
566
} ) ;
567
+
568
+ describe ( 'legend restyle update' , function ( ) {
569
+ 'use strict' ;
570
+
571
+ beforeAll ( function ( ) {
572
+ jasmine . addMatchers ( customMatchers ) ;
573
+ } ) ;
574
+
575
+ afterEach ( destroyGraphDiv ) ;
576
+
577
+ it ( 'should update trace toggle background rectangle' , function ( done ) {
578
+ var mock = require ( '@mocks/0.json' ) ,
579
+ mockCopy = Lib . extendDeep ( { } , mock ) ,
580
+ gd = createGraphDiv ( ) ;
581
+
582
+ mockCopy . data [ 0 ] . visible = false ;
583
+ mockCopy . data [ 0 ] . showlegend = false ;
584
+ mockCopy . data [ 1 ] . visible = false ;
585
+ mockCopy . data [ 1 ] . showlegend = false ;
586
+
587
+ function countLegendItems ( ) {
588
+ return d3 . select ( gd ) . selectAll ( 'rect.legendtoggle' ) . size ( ) ;
589
+ }
590
+
591
+ function assertTraceToggleRect ( ) {
592
+ var nodes = d3 . selectAll ( 'rect.legendtoggle' ) ;
593
+
594
+ nodes . each ( function ( ) {
595
+ var node = d3 . select ( this ) ;
596
+
597
+ expect ( node . attr ( 'x' ) ) . toEqual ( '0' ) ;
598
+ expect ( node . attr ( 'y' ) ) . toEqual ( '-9.5' ) ;
599
+ expect ( node . attr ( 'height' ) ) . toEqual ( '19' ) ;
600
+
601
+ var w = + node . attr ( 'width' ) ;
602
+ expect ( Math . abs ( w - 160 ) ) . toBeLessThan ( 10 ) ;
603
+ } ) ;
604
+ }
605
+
606
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( function ( ) {
607
+ expect ( countLegendItems ( ) ) . toEqual ( 1 ) ;
608
+ assertTraceToggleRect ( ) ;
609
+
610
+ return Plotly . restyle ( gd , 'visible' , [ true , false , false ] ) ;
611
+ } ) . then ( function ( ) {
612
+ expect ( countLegendItems ( ) ) . toEqual ( 0 ) ;
613
+
614
+ return Plotly . restyle ( gd , 'showlegend' , [ true , false , false ] ) ;
615
+ } ) . then ( function ( ) {
616
+ expect ( countLegendItems ( ) ) . toEqual ( 1 ) ;
617
+ assertTraceToggleRect ( ) ;
618
+
619
+ done ( ) ;
620
+ } ) ;
621
+ } ) ;
622
+ } ) ;
0 commit comments