Skip to content

Commit 6111dc0

Browse files
committed
handle transparent colors in selections
1 parent e00cde4 commit 6111dc0

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/components/selections/select.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var tinycolor = require('tinycolor2');
34
var polybool = require('polybooljs');
45
var pointInPolygon = require('point-in-polygon/nested'); // could we use contains lib/polygon instead?
56

@@ -112,17 +113,30 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
112113
fullLayout.newshape :
113114
fullLayout.newselection;
114115

116+
var fillC = (isDrawMode && !isOpenMode) ? newStyle.fillcolor : 'rgba(0,0,0,0)';
117+
var fillColor = tinycolor(fillC);
118+
var fillAlpha = fillColor.getAlpha();
119+
var fillRGB = Color.tinyRGB(fillColor);
120+
121+
var strokeC = newStyle.line.color || (
122+
isCartesian ?
123+
Color.contrast(gd._fullLayout.plot_bgcolor) :
124+
'#7f7f7f' // non-cartesian subplot
125+
);
126+
127+
var strokeColor = tinycolor(strokeC);
128+
var strokeAlpha = strokeColor.getAlpha();
129+
var strokeRGB = Color.tinyRGB(strokeColor);
130+
115131
outlines.enter()
116132
.append('path')
117133
.attr('class', 'select-outline select-outline-' + plotinfo.id)
118134
.style({
119135
opacity: isDrawMode ? newStyle.opacity / 2 : 1,
120-
fill: (isDrawMode && !isOpenMode) ? newStyle.fillcolor : 'none',
121-
stroke: newStyle.line.color || (
122-
isCartesian ?
123-
Color.contrast(gd._fullLayout.plot_bgcolor) :
124-
'#7f7f7f' // non-cartesian subplot
125-
),
136+
fill: fillRGB,
137+
'fill-opacity': fillAlpha,
138+
stroke: strokeRGB,
139+
'stroke-opacity': strokeAlpha,
126140
'stroke-dasharray': dashStyle(newStyle.line.dash, newStyle.line.width),
127141
'stroke-width': newStyle.line.width + 'px',
128142
'shape-rendering': 'crispEdges'

0 commit comments

Comments
 (0)