Skip to content

Commit 23569cd

Browse files
committed
handle transparent colors in rangeslider
1 parent 3bab776 commit 23569cd

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/components/rangeslider/draw.js

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

3+
var tinycolor = require('tinycolor2');
34
var d3 = require('@plotly/d3');
45

56
var Registry = require('../../registry');
@@ -395,12 +396,22 @@ function drawBg(rangeSlider, gd, axisOpts, opts) {
395396
var offsetShift = -opts._offsetShift;
396397
var lw = Drawing.crispRound(gd, opts.borderwidth);
397398

399+
var fillColor = tinycolor(opts.bgcolor);
400+
var fillAlpha = fillColor.getAlpha();
401+
var fillRGB = Color.tinyRGB(fillColor);
402+
403+
var strokeColor = tinycolor(opts.bordercolor);
404+
var strokeAlpha = strokeColor.getAlpha();
405+
var strokeRGB = Color.tinyRGB(strokeColor);
406+
398407
bg.attr({
399408
width: opts._width + borderCorrect,
400409
height: opts._height + borderCorrect,
401410
transform: strTranslate(offsetShift, offsetShift),
402-
fill: opts.bgcolor,
403-
stroke: opts.bordercolor,
411+
fill: fillRGB,
412+
'fill-opacity': fillAlpha,
413+
stroke: strokeRGB,
414+
'stroke-opacity': strokeAlpha,
404415
'stroke-width': lw
405416
});
406417
}

test/jasmine/tests/range_slider_test.js

Lines changed: 10 additions & 10 deletions
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.getAttribute('fill')).toBe('rgb(250, 250, 250)');
79+
expect(bg.getAttribute('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.getAttribute('fill')).toBe('rgb(255, 255, 128)');
95+
expect(bg.getAttribute('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.getAttribute('fill')).toBe('rgb(255, 0, 0)');
370+
expect(bg.getAttribute('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.getAttribute('fill')).toBe('rgb(255, 0, 0)');
380+
expect(bg.getAttribute('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.getAttribute('fill')).toBe('rgb(255, 0, 0)');
390+
expect(bg.getAttribute('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)