Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/components/rangeslider/draw.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var tinycolor = require('tinycolor2');
var d3 = require('@plotly/d3');

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

var fillColor = tinycolor(opts.bgcolor);
var fillAlpha = fillColor.getAlpha();
var fillRGB = Color.tinyRGB(fillColor);

var strokeColor = tinycolor(opts.bordercolor);
var strokeAlpha = strokeColor.getAlpha();
var strokeRGB = Color.tinyRGB(strokeColor);

bg.attr({
width: opts._width + borderCorrect,
height: opts._height + borderCorrect,
transform: strTranslate(offsetShift, offsetShift),
fill: opts.bgcolor,
stroke: opts.bordercolor,
fill: fillRGB,
'fill-opacity': fillAlpha,
stroke: strokeRGB,
'stroke-opacity': strokeAlpha,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌴 better to reuse Color.stroke and Color.fill here and in selections/select.js - and that would also help address the presumably unintentional use of attr here whereas elsewhere we use style for these.

To be specific, you can either:

bg.attr({...})
.call(Color.stroke, opts.bordercolor)
.call(Color.fill, opts.bgcolor);

or:

bg.attr({...});
Color.stroke(bg, opts.bordercolor);
Color.fill(bg, opts.bgcolor);

'stroke-width': lw
});
}
Expand Down
26 changes: 20 additions & 6 deletions src/components/selections/select.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

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

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

var fillC = (isDrawMode && !isOpenMode) ? newStyle.fillcolor : 'rgba(0,0,0,0)';
var fillColor = tinycolor(fillC);
var fillAlpha = fillColor.getAlpha();
var fillRGB = Color.tinyRGB(fillColor);

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

var strokeColor = tinycolor(strokeC);
var strokeAlpha = strokeColor.getAlpha();
var strokeRGB = Color.tinyRGB(strokeColor);

outlines.enter()
.append('path')
.attr('class', 'select-outline select-outline-' + plotinfo.id)
.style({
opacity: isDrawMode ? newStyle.opacity / 2 : 1,
fill: (isDrawMode && !isOpenMode) ? newStyle.fillcolor : 'none',
stroke: newStyle.line.color || (
isCartesian ?
Color.contrast(gd._fullLayout.plot_bgcolor) :
'#7f7f7f' // non-cartesian subplot
),
fill: fillRGB,
'fill-opacity': fillAlpha,
stroke: strokeRGB,
'stroke-opacity': strokeAlpha,
'stroke-dasharray': dashStyle(newStyle.line.dash, newStyle.line.width),
'stroke-width': newStyle.line.width + 'px',
'shape-rendering': 'crispEdges'
Expand Down
13 changes: 12 additions & 1 deletion src/traces/violin/hover.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';

var tinycolor = require('tinycolor2');

var Color = require('../../components/color');
var Lib = require('../../lib');
var Axes = require('../../plots/cartesian/axes');
var boxHoverPoints = require('../box/hover');
Expand Down Expand Up @@ -75,7 +78,15 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, opts) {

closeData.push(kdePointData);

violinLineAttrs = {stroke: pointData.color};
var strokeC = pointData.color;
var strokeColor = tinycolor(strokeC);
var strokeAlpha = strokeColor.getAlpha();
var strokeRGB = Color.tinyRGB(strokeColor);

violinLineAttrs = {
stroke: strokeRGB,
'stroke-opacity': strokeAlpha
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one would take a little more work to convert to Color.stroke - basically stashing strokeC so it can be used below next to the call

violinLine.attr(violinLineAttrs);

But I still think it'd be a good idea, and again there's the attr/style switch. In principle both work but we should really be consistent, as there can be different behavior in relation to extra CSS on the page.

violinLineAttrs[pLetter + '1'] = Lib.constrain(paOffset + pOnPath[0], paOffset, paOffset + paLength);
violinLineAttrs[pLetter + '2'] = Lib.constrain(paOffset + pOnPath[1], paOffset, paOffset + paLength);
violinLineAttrs[vLetter + '1'] = violinLineAttrs[vLetter + '2'] = vAxis._offset + vValPx;
Expand Down
20 changes: 10 additions & 10 deletions test/jasmine/tests/range_slider_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ describe('Visible rangesliders', function() {
expect(+bg.getAttribute('width')).toEqual(expectedWidth);
expect(+bg.getAttribute('height')).toEqual(66);

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

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

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

expect(bg.getAttribute('fill')).toBe('#ffff80');
expect(bg.getAttribute('stroke')).toBe('#404040');
expect(bg.getAttribute('fill')).toBe('rgb(255, 255, 128)');
expect(bg.getAttribute('stroke')).toBe('rgb(64, 64, 64)');
expect(+bg.getAttribute('stroke-width')).toBe(1);
})
.then(done, done.fail);
Expand Down Expand Up @@ -366,8 +366,8 @@ describe('Visible rangesliders', function() {
expect(+maskMin.getAttribute('width')).toEqual(maskMinWidth);
expect(+maskMax.getAttribute('width')).toEqual(maskMaxWidth);

expect(bg.getAttribute('fill')).toBe('red');
expect(bg.getAttribute('stroke')).toBe('black');
expect(bg.getAttribute('fill')).toBe('rgb(255, 0, 0)');
expect(bg.getAttribute('stroke')).toBe('rgb(0, 0, 0)');
expect(bg.getAttribute('stroke-width')).toBe('2');

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

expect(bg.getAttribute('fill')).toBe('red');
expect(bg.getAttribute('stroke')).toBe('blue');
expect(bg.getAttribute('fill')).toBe('rgb(255, 0, 0)');
expect(bg.getAttribute('stroke')).toBe('rgb(0, 0, 255)');
expect(bg.getAttribute('stroke-width')).toBe('2');

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

expect(bg.getAttribute('fill')).toBe('red');
expect(bg.getAttribute('stroke')).toBe('blue');
expect(bg.getAttribute('fill')).toBe('rgb(255, 0, 0)');
expect(bg.getAttribute('stroke')).toBe('rgb(0, 0, 255)');
expect(bg.getAttribute('stroke-width')).toBe('3');
})
.then(done, done.fail);
Expand Down