Skip to content

Commit f3789e6

Browse files
committed
Fallback to arrow color with opacity
1 parent 2e214c7 commit f3789e6

1 file changed

Lines changed: 18 additions & 25 deletions

File tree

src/traces/quiver/style.js

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var d3 = require('@plotly/d3');
44
var Lib = require('../../lib');
55

66
var Drawing = require('../../components/drawing');
7-
var Color = require('../../components/color');
87
var Colorscale = require('../../components/colorscale');
98
var DESELECTDIM = require('../../constants/interactions').DESELECTDIM;
109

@@ -64,32 +63,25 @@ function styleOnSelect(gd, cd, sel) {
6463

6564
sel.selectAll('path.js-line').each(function(d) {
6665
var path = d3.select(this);
66+
var dim = !d.selected;
6767

68-
if(d.selected) {
69-
var sw = selectedLine.width !== undefined ? selectedLine.width : markerLine.width;
70-
if(selectedLine.color) {
71-
Drawing.lineGroupStyle(path, sw, selectedLine.color, markerLine.dash);
72-
} else if(hasColorscale) {
73-
Drawing.lineGroupStyle(path, sw, lineColor, markerLine.dash);
74-
colorscaleStroke(path, trace);
75-
path.style('stroke-opacity', 1);
76-
} else {
77-
Drawing.lineGroupStyle(path, sw, lineColor, markerLine.dash);
78-
}
68+
var explicitColor = dim ? unselectedLine.color : selectedLine.color;
69+
var lineWidth = dim ?
70+
(unselectedLine.width !== undefined ? unselectedLine.width : markerLine.width) :
71+
(selectedLine.width !== undefined ? selectedLine.width : markerLine.width);
72+
73+
if(explicitColor) {
74+
Drawing.lineGroupStyle(path, lineWidth, explicitColor, markerLine.dash);
75+
path.style('stroke-opacity', 1);
7976
} else {
80-
var uc = unselectedLine.color;
81-
var uw = unselectedLine.width !== undefined ? unselectedLine.width : markerLine.width;
82-
if(uc) {
83-
Drawing.lineGroupStyle(path, uw, uc, markerLine.dash);
84-
} else if(hasColorscale) {
85-
// keep colorscale color but dim via opacity
86-
Drawing.lineGroupStyle(path, uw, lineColor, markerLine.dash);
87-
colorscaleStroke(path, trace);
88-
path.style('stroke-opacity', DESELECTDIM);
89-
} else {
90-
var dimColor = lineColor ? Color.addOpacity(lineColor, DESELECTDIM) : undefined;
91-
Drawing.lineGroupStyle(path, uw, dimColor, markerLine.dash);
92-
}
77+
// Fall back to the arrow's own color (scalar marker.color, a
78+
// marker.color array, or the colorscale). When marker.color is an
79+
// array, lineColor is undefined and we cannot bake opacity into a
80+
// color, so we keep each arrow's color and dim unselected arrows
81+
// via stroke-opacity instead.
82+
Drawing.lineGroupStyle(path, lineWidth, lineColor, markerLine.dash);
83+
if(hasColorscale) colorscaleStroke(path, trace);
84+
path.style('stroke-opacity', dim ? DESELECTDIM : 1);
9385
}
9486
});
9587

@@ -98,6 +90,7 @@ function styleOnSelect(gd, cd, sel) {
9890
var paths = sel.selectAll('path.js-line');
9991
paths.call(Drawing.lineGroupStyle, markerLine.width, lineColor, markerLine.dash);
10092
if(hasColorscale) colorscaleStroke(paths, trace);
93+
paths.style('stroke-opacity', 1);
10194
Drawing.textPointStyle(sel.selectAll('text'), trace, gd);
10295
}
10396
}

0 commit comments

Comments
 (0)