Skip to content

Commit 3ae9c77

Browse files
authored
Merge pull request #6323 from plotly/more-drawing-rgba-colors
Fix exporting transparent colors in `rangeslider` & `selections`
2 parents 578fc34 + a529f1b commit 3ae9c77

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

src/components/rangeslider/draw.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,10 @@ function drawBg(rangeSlider, gd, axisOpts, opts) {
399399
width: opts._width + borderCorrect,
400400
height: opts._height + borderCorrect,
401401
transform: strTranslate(offsetShift, offsetShift),
402-
fill: opts.bgcolor,
403-
stroke: opts.bordercolor,
404402
'stroke-width': lw
405-
});
403+
})
404+
.call(Color.stroke, opts.bordercolor)
405+
.call(Color.fill, opts.bgcolor);
406406
}
407407

408408
function addClipPath(rangeSlider, gd, axisOpts, opts) {

src/components/selections/select.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,25 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
112112
fullLayout.newshape :
113113
fullLayout.newselection;
114114

115+
var fillC = (isDrawMode && !isOpenMode) ? newStyle.fillcolor : 'rgba(0,0,0,0)';
116+
117+
var strokeC = newStyle.line.color || (
118+
isCartesian ?
119+
Color.contrast(gd._fullLayout.plot_bgcolor) :
120+
'#7f7f7f' // non-cartesian subplot
121+
);
122+
115123
outlines.enter()
116124
.append('path')
117125
.attr('class', 'select-outline select-outline-' + plotinfo.id)
118126
.style({
119127
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-
),
126128
'stroke-dasharray': dashStyle(newStyle.line.dash, newStyle.line.width),
127129
'stroke-width': newStyle.line.width + 'px',
128130
'shape-rendering': 'crispEdges'
129131
})
132+
.call(Color.stroke, strokeC)
133+
.call(Color.fill, fillC)
130134
.attr('fill-rule', 'evenodd')
131135
.classed('cursor-move', isDrawMode ? true : false)
132136
.attr('transform', transform)

src/traces/violin/hover.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var Color = require('../../components/color');
34
var Lib = require('../../lib');
45
var Axes = require('../../plots/cartesian/axes');
56
var boxHoverPoints = require('../box/hover');
@@ -75,7 +76,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, opts) {
7576

7677
closeData.push(kdePointData);
7778

78-
violinLineAttrs = {stroke: pointData.color};
79+
violinLineAttrs = {};
7980
violinLineAttrs[pLetter + '1'] = Lib.constrain(paOffset + pOnPath[0], paOffset, paOffset + paLength);
8081
violinLineAttrs[pLetter + '2'] = Lib.constrain(paOffset + pOnPath[1], paOffset, paOffset + paLength);
8182
violinLineAttrs[vLetter + '1'] = violinLineAttrs[vLetter + '2'] = vAxis._offset + vValPx;
@@ -98,7 +99,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, opts) {
9899
.classed('violinline-' + trace.uid, true)
99100
.attr('stroke-width', 1.5);
100101
violinLine.exit().remove();
101-
violinLine.attr(violinLineAttrs);
102+
violinLine.attr(violinLineAttrs).call(Color.stroke, pointData.color);
102103

103104
// same combine logic as box hoverPoints
104105
if(hovermode === 'closest') {

test/jasmine/tests/range_slider_test.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ describe('Visible rangesliders', function() {
7575
expect(+bg.getAttribute('width')).toEqual(expectedWidth);
7676
expect(+bg.getAttribute('height')).toEqual(66);
7777

78-
expect(bg.getAttribute('fill')).toBe('#fafafa');
79-
expect(bg.getAttribute('stroke')).toBe('black');
78+
expect(bg.style.fill).toBe('rgb(250, 250, 250)');
79+
expect(bg.style.stroke).toBe('rgb(0, 0, 0)');
8080
expect(+bg.getAttribute('stroke-width')).toBe(2);
8181

8282
return Plotly.relayout(gd, {
@@ -91,8 +91,8 @@ describe('Visible rangesliders', function() {
9191

9292
expect(+bg.getAttribute('height')).toEqual(32);
9393

94-
expect(bg.getAttribute('fill')).toBe('#ffff80');
95-
expect(bg.getAttribute('stroke')).toBe('#404040');
94+
expect(bg.style.fill).toBe('rgb(255, 255, 128)');
95+
expect(bg.style.stroke).toBe('rgb(64, 64, 64)');
9696
expect(+bg.getAttribute('stroke-width')).toBe(1);
9797
})
9898
.then(done, done.fail);
@@ -366,8 +366,8 @@ describe('Visible rangesliders', function() {
366366
expect(+maskMin.getAttribute('width')).toEqual(maskMinWidth);
367367
expect(+maskMax.getAttribute('width')).toEqual(maskMaxWidth);
368368

369-
expect(bg.getAttribute('fill')).toBe('red');
370-
expect(bg.getAttribute('stroke')).toBe('black');
369+
expect(bg.style.fill).toBe('rgb(255, 0, 0)');
370+
expect(bg.style.stroke).toBe('rgb(0, 0, 0)');
371371
expect(bg.getAttribute('stroke-width')).toBe('2');
372372

373373
return Plotly.relayout(gd, 'xaxis.rangeslider.bordercolor', 'blue');
@@ -376,8 +376,8 @@ describe('Visible rangesliders', function() {
376376
expect(+maskMin.getAttribute('width')).toEqual(maskMinWidth);
377377
expect(+maskMax.getAttribute('width')).toEqual(maskMaxWidth);
378378

379-
expect(bg.getAttribute('fill')).toBe('red');
380-
expect(bg.getAttribute('stroke')).toBe('blue');
379+
expect(bg.style.fill).toBe('rgb(255, 0, 0)');
380+
expect(bg.style.stroke).toBe('rgb(0, 0, 255)');
381381
expect(bg.getAttribute('stroke-width')).toBe('2');
382382

383383
return Plotly.relayout(gd, 'xaxis.rangeslider.borderwidth', 3);
@@ -386,8 +386,8 @@ describe('Visible rangesliders', function() {
386386
expect(+maskMin.getAttribute('width')).toEqual(maskMinWidth);
387387
expect(+maskMax.getAttribute('width')).toEqual(maskMaxWidth);
388388

389-
expect(bg.getAttribute('fill')).toBe('red');
390-
expect(bg.getAttribute('stroke')).toBe('blue');
389+
expect(bg.style.fill).toBe('rgb(255, 0, 0)');
390+
expect(bg.style.stroke).toBe('rgb(0, 0, 255)');
391391
expect(bg.getAttribute('stroke-width')).toBe('3');
392392
})
393393
.then(done, done.fail);

0 commit comments

Comments
 (0)