Skip to content

Commit 200733a

Browse files
committed
revisit rangeslider & selections stroke and fill style
1 parent 6111dc0 commit 200733a

File tree

3 files changed

+15
-36
lines changed

3 files changed

+15
-36
lines changed

src/components/rangeslider/draw.js

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

3-
var tinycolor = require('tinycolor2');
43
var d3 = require('@plotly/d3');
54

65
var Registry = require('../../registry');
@@ -396,24 +395,14 @@ function drawBg(rangeSlider, gd, axisOpts, opts) {
396395
var offsetShift = -opts._offsetShift;
397396
var lw = Drawing.crispRound(gd, opts.borderwidth);
398397

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-
407398
bg.attr({
408399
width: opts._width + borderCorrect,
409400
height: opts._height + borderCorrect,
410401
transform: strTranslate(offsetShift, offsetShift),
411-
fill: fillRGB,
412-
'fill-opacity': fillAlpha,
413-
stroke: strokeRGB,
414-
'stroke-opacity': strokeAlpha,
415402
'stroke-width': lw
416-
});
403+
})
404+
.call(Color.stroke, opts.bordercolor)
405+
.call(Color.fill, opts.bgcolor);
417406
}
418407

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

src/components/selections/select.js

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

3-
var tinycolor = require('tinycolor2');
43
var polybool = require('polybooljs');
54
var pointInPolygon = require('point-in-polygon/nested'); // could we use contains lib/polygon instead?
65

@@ -114,33 +113,24 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
114113
fullLayout.newselection;
115114

116115
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);
120116

121117
var strokeC = newStyle.line.color || (
122118
isCartesian ?
123119
Color.contrast(gd._fullLayout.plot_bgcolor) :
124120
'#7f7f7f' // non-cartesian subplot
125121
);
126122

127-
var strokeColor = tinycolor(strokeC);
128-
var strokeAlpha = strokeColor.getAlpha();
129-
var strokeRGB = Color.tinyRGB(strokeColor);
130-
131123
outlines.enter()
132124
.append('path')
133125
.attr('class', 'select-outline select-outline-' + plotinfo.id)
134126
.style({
135127
opacity: isDrawMode ? newStyle.opacity / 2 : 1,
136-
fill: fillRGB,
137-
'fill-opacity': fillAlpha,
138-
stroke: strokeRGB,
139-
'stroke-opacity': strokeAlpha,
140128
'stroke-dasharray': dashStyle(newStyle.line.dash, newStyle.line.width),
141129
'stroke-width': newStyle.line.width + 'px',
142130
'shape-rendering': 'crispEdges'
143131
})
132+
.call(Color.stroke, strokeC)
133+
.call(Color.fill, fillC)
144134
.attr('fill-rule', 'evenodd')
145135
.classed('cursor-move', isDrawMode ? true : false)
146136
.attr('transform', transform)

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('rgb(250, 250, 250)');
79-
expect(bg.getAttribute('stroke')).toBe('rgb(0, 0, 0)');
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('rgb(255, 255, 128)');
95-
expect(bg.getAttribute('stroke')).toBe('rgb(64, 64, 64)');
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('rgb(255, 0, 0)');
370-
expect(bg.getAttribute('stroke')).toBe('rgb(0, 0, 0)');
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('rgb(255, 0, 0)');
380-
expect(bg.getAttribute('stroke')).toBe('rgb(0, 0, 255)');
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('rgb(255, 0, 0)');
390-
expect(bg.getAttribute('stroke')).toBe('rgb(0, 0, 255)');
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)