Skip to content

Commit e2db213

Browse files
committed
rangeselector: add 'activecolor' attribute
- making the color of the active / hovered button configurable - by default, the 'activecolor' is set using Color.constrast - fix test cases accordingly
1 parent 3cb5144 commit e2db213

File tree

6 files changed

+14
-6
lines changed

6 files changed

+14
-6
lines changed

src/components/rangeselector/attributes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ module.exports = {
8181
role: 'style',
8282
description: 'Sets the background color of the range selector buttons.'
8383
},
84+
activecolor: {
85+
valType: 'color',
86+
role: 'style',
87+
description: 'Sets the background color of the active range selector button.'
88+
},
8489
bordercolor: {
8590
valType: 'color',
8691
dflt: colorAttrs.defaultLine,

src/components/rangeselector/constants.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121
rx: 3,
2222
ry: 3,
2323

24-
// color given to active and hovered buttons
25-
activeColor: '#d3d3d3'
24+
// light fraction used to compute the 'activecolor' default
25+
lightAmount: 25,
26+
darkAmount: 10
2627
};

src/components/rangeselector/defaults.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'use strict';
1010

1111
var Lib = require('../../lib');
12+
var Color = require('../color');
1213

1314
var attributes = require('./attributes');
1415
var buttonAttrs = require('./button_attributes');
@@ -38,7 +39,8 @@ module.exports = function rangeSelectorDefaults(containerIn, containerOut, layou
3839

3940
Lib.coerceFont(coerce, 'font', layout.font);
4041

41-
coerce('bgcolor');
42+
var bgColor = coerce('bgcolor');
43+
coerce('activecolor', Color.contrast(bgColor, constants.lightAmount, constants.darkAmount));
4244
coerce('bordercolor');
4345
coerce('borderwidth');
4446
};

src/components/rangeselector/draw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function drawButtonRect(button, selectorLayout, d) {
142142

143143
function getFillColor(selectorLayout, d) {
144144
return (d.isActive || d.isHovered) ?
145-
constants.activeColor :
145+
selectorLayout.activecolor :
146146
selectorLayout.bgcolor;
147147
}
148148

test/image/mocks/range_selector_style.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@
10251025
"y": 0.2,
10261026
"yanchor": "bottom",
10271027
"bgcolor": "#d3d3d3",
1028+
"activecolor": "#d3d3d3",
10281029
"borderwidth": 2,
10291030
"bordercolor": "#ff7f0e"
10301031
},

test/jasmine/tests/range_selector_test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var RangeSelector = require('@src/components/rangeselector');
22
var getUpdateObject = require('@src/components/rangeselector/get_update_object');
3-
var constants = require('@src/components/rangeselector/constants');
43

54
var d3 = require('d3');
65
var Plotly = require('@lib');
@@ -482,7 +481,7 @@ describe('range selector interactions:', function() {
482481
var pos = getRectCenter(button.node());
483482

484483
var fillColor = Color.rgb(gd._fullLayout.xaxis.rangeselector.bgcolor);
485-
var activeColor = Color.rgb(constants.activeColor);
484+
var activeColor = 'rgb(212, 212, 212)';
486485

487486
expect(button.style('fill')).toEqual(fillColor);
488487

0 commit comments

Comments
 (0)