Skip to content

Commit 58bb631

Browse files
author
Michael Potter
committed
modify hover default to change opacity rather than set everything to grey
1 parent 52583d2 commit 58bb631

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

src/traces/sankey/attributes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ var attrs = module.exports = overrideAll({
200200
arrayOk: true,
201201
description: [
202202
'Sets the `link` hover color. It can be a single value, or an array for specifying hover colors for',
203-
'each `link`. If `link.hovercolor` is omitted, then by default, links will become solid grey when',
204-
'hovered over.'
203+
'each `link`. If `link.hovercolor` is omitted, then by default, links will become slightly more',
204+
'opaque when hovered over.'
205205
].join(' ')
206206
},
207207
customdata: {

src/traces/sankey/defaults.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,31 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
6363
handleHoverLabelDefaults(linkIn, linkOut, coerceLink, hoverlabelDefault);
6464
coerceLink('hovertemplate');
6565

66-
var defaultLinkColor = tinycolor(layout.paper_bgcolor).getLuminance() < 0.333 ?
67-
'rgba(255, 255, 255, 0.6)' :
68-
'rgba(0, 0, 0, 0.2)';
66+
var darkBG = tinycolor(layout.paper_bgcolor).getLuminance() < 0.333;
67+
var defaultLinkColor = darkBG ? 'rgba(255, 255, 255, 0.6)' : 'rgba(0, 0, 0, 0.2)';
68+
var linkColor = coerceLink('color', defaultLinkColor);
69+
70+
function makeDefaultHoverColor(_linkColor) {
71+
var tc = tinycolor(_linkColor);
72+
if (!tc.isValid()) {
73+
// hopefully the user-specified color is valid, but if not that can be caught elsewhere
74+
return _linkColor;
75+
}
76+
var alpha = tc.getAlpha();
77+
if (alpha <= 0.8) {
78+
tc.setAlpha(alpha + 0.2);
79+
}
80+
else {
81+
tc = darkBG ? tc.brighten() : tc.darken();
82+
}
83+
return tc.toRgbString();
84+
}
6985

70-
var defaultHoverColor = tinycolor(layout.paper_bgcolor).getLuminance() < 0.333 ?
71-
'rgba(128, 128, 128, 1.0)' :
72-
'rgba(128, 128, 128, 1.0)';
86+
coerceLink('hovercolor', Array.isArray(linkColor) ?
87+
linkColor.map(makeDefaultHoverColor) :
88+
makeDefaultHoverColor(linkColor)
89+
);
7390

74-
coerceLink('color', Lib.repeat(defaultLinkColor, linkOut.value.length));
75-
coerceLink('hovercolor', Lib.repeat(defaultHoverColor, linkOut.value.length));
7691
coerceLink('customdata');
7792

7893
handleArrayContainerDefaults(linkIn, linkOut, {

test/jasmine/tests/sankey_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ describe('sankey tests', function() {
10871087
.filter(function(obj) {
10881088
return obj.link.label === 'stream 1';
10891089
})[0].forEach(function(l) {
1090-
expect(l.style.fillOpacity).toEqual('1');
1090+
expect(l.style.fillOpacity).toEqual('0.4');
10911091
});
10921092
}).then(function() {
10931093
mouseEvent('mouseout', 200, 250);

test/plot-schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44150,7 +44150,7 @@
4415044150
"editType": "calc",
4415144151
"hovercolor": {
4415244152
"arrayOk": true,
44153-
"description": "Sets the `link` hover color. It can be a single value, or an array for specifying hover colors for each `link`. If `link.hovercolor` is omitted, then by default, links will become solid grey when hovered over.",
44153+
"description": "Sets the `link` hover color. It can be a single value, or an array for specifying hover colors for each `link`. If `link.hovercolor` is omitted, then by default, links will become slightly more opaque when hovered over.",
4415444154
"editType": "calc",
4415544155
"valType": "color"
4415644156
},

0 commit comments

Comments
 (0)