1
1
var RangeSelector = require ( '@src/components/rangeselector' ) ;
2
2
var getUpdateObject = require ( '@src/components/rangeselector/get_update_object' ) ;
3
- var constants = require ( '@src/components/rangeselector/constants' ) ;
4
3
5
4
var d3 = require ( 'd3' ) ;
6
5
var Plotly = require ( '@lib' ) ;
@@ -427,6 +426,16 @@ describe('range selector interactions:', function() {
427
426
} ) ;
428
427
}
429
428
429
+ function checkButtonColor ( bgColor , activeColor ) {
430
+ d3 . selectAll ( '.button' ) . each ( function ( d ) {
431
+ var rect = d3 . select ( this ) . select ( 'rect' ) ;
432
+
433
+ expect ( rect . style ( 'fill' ) ) . toEqual (
434
+ d . isActive ? activeColor : bgColor
435
+ ) ;
436
+ } ) ;
437
+ }
438
+
430
439
it ( 'should display the correct nodes' , function ( ) {
431
440
assertNodeCount ( '.rangeselector' , 1 ) ;
432
441
assertNodeCount ( '.button' , mockCopy . layout . xaxis . rangeselector . buttons . length ) ;
@@ -457,6 +466,22 @@ describe('range selector interactions:', function() {
457
466
} ) ;
458
467
} ) ;
459
468
469
+ it ( 'should be able to change its style on `relayout`' , function ( done ) {
470
+ var prefix = 'xaxis.rangeselector.' ;
471
+
472
+ checkButtonColor ( 'rgb(238, 238, 238)' , 'rgb(212, 212, 212)' ) ;
473
+
474
+ Plotly . relayout ( gd , prefix + 'bgcolor' , 'red' ) . then ( function ( ) {
475
+ checkButtonColor ( 'rgb(255, 0, 0)' , 'rgb(255, 128, 128)' ) ;
476
+
477
+ return Plotly . relayout ( gd , prefix + 'activecolor' , 'blue' ) ;
478
+ } ) . then ( function ( ) {
479
+ checkButtonColor ( 'rgb(255, 0, 0)' , 'rgb(0, 0, 255)' ) ;
480
+
481
+ done ( ) ;
482
+ } ) ;
483
+ } ) ;
484
+
460
485
it ( 'should update range and active button when clicked' , function ( ) {
461
486
var range0 = gd . layout . xaxis . range [ 0 ] ;
462
487
var buttons = d3 . selectAll ( '.button' ) . select ( 'rect' ) ;
@@ -482,7 +507,7 @@ describe('range selector interactions:', function() {
482
507
var pos = getRectCenter ( button . node ( ) ) ;
483
508
484
509
var fillColor = Color . rgb ( gd . _fullLayout . xaxis . rangeselector . bgcolor ) ;
485
- var activeColor = Color . rgb ( constants . activeColor ) ;
510
+ var activeColor = ' rgb(212, 212, 212)' ;
486
511
487
512
expect ( button . style ( 'fill' ) ) . toEqual ( fillColor ) ;
488
513
0 commit comments