Skip to content

Commit c99b6c2

Browse files
authored
Merge pull request #5506 from plotly/parcoords_text_shadow
Parcoords: Use paper background color for text shadow for better dark mode
2 parents cfa7720 + 409e319 commit c99b6c2

20 files changed

+101
-13
lines changed

src/lib/svg_text_utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,16 @@ function alignHTMLWith(_base, container, options) {
755755
};
756756
}
757757

758+
exports.makeTextShadow = function(offset, color) {
759+
var x = offset + 'px ';
760+
var y = offset + 'px ';
761+
var b = '1px ';
762+
return x + y + b + color + ', ' +
763+
'-' + x + '-' + y + b + color + ', ' +
764+
x + '-' + y + b + color + ', ' +
765+
'-' + x + y + b + color;
766+
};
767+
758768
/*
759769
* Editable title
760770
* @param {d3.selection} context: the element being edited. Normally text,

src/traces/parcats/parcats.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,7 @@ function performPlot(parcatsModels, graphDiv, layout, svg) {
238238
})
239239
.attr('alignment-baseline', 'middle')
240240

241-
.style('text-shadow',
242-
paperColor + ' -1px 1px 2px, ' +
243-
paperColor + ' 1px 1px 2px, ' +
244-
paperColor + ' 1px -1px 2px, ' +
245-
paperColor + ' -1px -1px 2px')
241+
.style('text-shadow', svgTextUtils.makeTextShadow(1, paperColor))
246242
.style('fill', 'rgb(0, 0, 0)')
247243
.attr('x',
248244
function(d) {

src/traces/parcoords/axisbrush.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ function attachDragBehavior(selection) {
354354

355355
function startAsc(a, b) { return a[0] - b[0]; }
356356

357-
function renderAxisBrush(axisBrush) {
357+
function renderAxisBrush(axisBrush, paperColor) {
358358
var background = axisBrush.selectAll('.background').data(repeat);
359359

360360
background.enter()
@@ -378,7 +378,7 @@ function renderAxisBrush(axisBrush) {
378378
.classed('highlight-shadow', true)
379379
.attr('x', -c.bar.width / 2)
380380
.attr('stroke-width', c.bar.width + c.bar.strokeWidth)
381-
.attr('stroke', c.bar.strokeColor)
381+
.attr('stroke', paperColor)
382382
.attr('opacity', c.bar.strokeOpacity)
383383
.attr('stroke-linecap', 'butt');
384384

@@ -402,15 +402,15 @@ function renderAxisBrush(axisBrush) {
402402
.call(styleHighlight);
403403
}
404404

405-
function ensureAxisBrush(axisOverlays) {
405+
function ensureAxisBrush(axisOverlays, paperColor) {
406406
var axisBrush = axisOverlays.selectAll('.' + c.cn.axisBrush)
407407
.data(repeat, keyFun);
408408

409409
axisBrush.enter()
410410
.append('g')
411411
.classed(c.cn.axisBrush, true);
412412

413-
renderAxisBrush(axisBrush);
413+
renderAxisBrush(axisBrush, paperColor);
414414
}
415415

416416
function getBrushExtent(brush) {

src/traces/parcoords/constants.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module.exports = {
2020
snapDuration: 150, // tween duration in ms for brush snap for ordinal axes
2121
snapRatio: 0.25, // ratio of bar extension relative to the distance between two adjacent ordinal values
2222
snapClose: 0.01, // fraction of inter-value distance to snap to the closer one, even if you're not over it
23-
strokeColor: 'white', // Color of the filter bar side lines
2423
strokeOpacity: 1, // Filter bar side stroke opacity
2524
strokeWidth: 1, // Filter bar side stroke width in pixels
2625
handleHeight: 8, // Height of the filter bar vertical resize areas on top and bottom

src/traces/parcoords/parcoords.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ module.exports = function parcoords(gd, cdModule, layout, callbacks) {
433433
var fullLayout = gd._fullLayout;
434434
var svg = fullLayout._toppaper;
435435
var glContainer = fullLayout._glcontainer;
436+
var paperColor = gd._fullLayout.paper_bgcolor;
436437

437438
calcAllTicks(cdModule);
438439

@@ -451,6 +452,7 @@ module.exports = function parcoords(gd, cdModule, layout, callbacks) {
451452
.each(function(d) {
452453
// FIXME: figure out how to handle multiple instances
453454
d.viewModel = vm[0];
455+
d.viewModel.paperColor = paperColor;
454456
d.model = d.viewModel ? d.viewModel.model : null;
455457
});
456458

@@ -647,7 +649,7 @@ module.exports = function parcoords(gd, cdModule, layout, callbacks) {
647649
.attr('stroke-width', '1px');
648650

649651
axis.selectAll('text')
650-
.style('text-shadow', '1px 1px 1px #fff, -1px -1px 1px #fff, 1px -1px 1px #fff, -1px 1px 1px #fff')
652+
.style('text-shadow', svgTextUtils.makeTextShadow(1, paperColor))
651653
.style('cursor', 'default');
652654

653655
var axisHeading = axisOverlays.selectAll('.' + c.cn.axisHeading)
@@ -749,5 +751,5 @@ module.exports = function parcoords(gd, cdModule, layout, callbacks) {
749751
.text(function(d) { return extremeText(d, false); })
750752
.each(function(d) { Drawing.font(d3.select(this), d.model.rangeFont); });
751753

752-
brush.ensureAxisBrush(axisOverlays);
754+
brush.ensureAxisBrush(axisOverlays, paperColor);
753755
};

src/traces/sankey/render.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var keyFun = gup.keyFun;
1515
var repeat = gup.repeat;
1616
var unwrap = gup.unwrap;
1717
var interpolateNumber = require('d3-interpolate').interpolateNumber;
18+
var svgTextUtils = require('../../lib/svg_text_utils');
1819

1920
var Registry = require('../../registry');
2021

@@ -1024,7 +1025,7 @@ module.exports = function(gd, svg, calcData, layout, callbacks) {
10241025

10251026
nodeLabel
10261027
.style('text-shadow', function(d) {
1027-
return d.horizontal ? '-1px 1px 1px #fff, 1px 1px 1px #fff, 1px -1px 1px #fff, -1px -1px 1px #fff' : 'none';
1028+
return d.horizontal ? svgTextUtils.makeTextShadow(1, '#fff') : 'none';
10281029
})
10291030
.each(function(d) {Drawing.font(nodeLabel, d.textFont);});
10301031

Loading
-219 Bytes
Loading
-227 Bytes
Loading
-227 Bytes
Loading

0 commit comments

Comments
 (0)