Skip to content

Commit 7f0db7c

Browse files
committed
better centering of legend items with fill
1 parent 597a845 commit 7f0db7c

19 files changed

+16
-4
lines changed

src/components/legend/style.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,23 @@ module.exports = function style(s, gd) {
8383
}
8484
}
8585

86+
// with fill and no markers or text, move the line and fill up a bit
87+
// so it's more centered
88+
var markersOrText = subTypes.hasMarkers(trace) || subTypes.hasText(trace);
89+
var anyFill = showFill || showGradientFill;
90+
var anyLine = showLine || showGradientLine;
91+
var pathStart = (markersOrText || !anyFill) ? 'M5,0' :
92+
// with a line leave it slightly below center, to leave room for the
93+
// line thickness and because the line is usually more prominent
94+
anyLine ? 'M5,-2' : 'M5,-3';
95+
8696
var this3 = d3.select(this);
8797

8898
var fill = this3.select('.legendfill').selectAll('path')
8999
.data(showFill || showGradientFill ? [d] : []);
90100
fill.enter().append('path').classed('js-fill', true);
91101
fill.exit().remove();
92-
fill.attr('d', 'M5,0h30v6h-30z')
102+
fill.attr('d', pathStart + 'h30v6h-30z')
93103
.call(showFill ? Drawing.fillGroupStyle : fillGradient);
94104

95105
var line = this3.select('.legendlines').selectAll('path')
@@ -103,7 +113,7 @@ module.exports = function style(s, gd) {
103113
// though there *is* no vertical variation in this case.
104114
// so add an invisibly small angle to the line
105115
// This issue (and workaround) exist across (Mac) Chrome, FF, and Safari
106-
line.attr('d', showGradientLine ? 'M5,0l30,0.0001' : 'M5,0h30')
116+
line.attr('d', pathStart + (showGradientLine ? 'l30,0.0001' : 'h30'))
107117
.call(showLine ? Drawing.lineGroupStyle : lineGradient);
108118

109119
function fillGradient(s) {

test/image/baselines/15.png

16 Bytes
Loading

test/image/baselines/5.png

-26 Bytes
Loading

test/image/baselines/airfoil.png

1.71 KB
Loading

test/image/baselines/cheater.png

-25 Bytes
Loading
-84 Bytes
Loading
-8 Bytes
Loading
-22 Bytes
Loading
-294 Bytes
Loading
42 Bytes
Loading
-30 Bytes
Loading
22 Bytes
Loading
-13 Bytes
Loading

test/image/baselines/range_slider.png

-17 Bytes
Loading
Loading
Loading
8 Bytes
Loading

test/image/mocks/colorscale_opacity.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@
567567
},
568568
"height": 450,
569569
"width": 1100,
570-
"autosize": true
570+
"autosize": true,
571+
"showlegend": false
571572
}
572573
}

test/image/mocks/contour_scatter.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@
341341
"line": {
342342
"color": "black"
343343
},
344-
"type": "scatter"
344+
"type": "scatter",
345+
"showlegend": false
345346
}
346347
]
347348
}

0 commit comments

Comments
 (0)