Skip to content

Commit

Permalink
better centering of legend items with fill
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcjohnson committed Aug 9, 2018
1 parent 597a845 commit 7f0db7c
Show file tree
Hide file tree
Showing 19 changed files with 16 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/components/legend/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,23 @@ module.exports = function style(s, gd) {
}
}

// with fill and no markers or text, move the line and fill up a bit
// so it's more centered
var markersOrText = subTypes.hasMarkers(trace) || subTypes.hasText(trace);
var anyFill = showFill || showGradientFill;
var anyLine = showLine || showGradientLine;
var pathStart = (markersOrText || !anyFill) ? 'M5,0' :
// with a line leave it slightly below center, to leave room for the
// line thickness and because the line is usually more prominent
anyLine ? 'M5,-2' : 'M5,-3';

var this3 = d3.select(this);

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

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

function fillGradient(s) {
Expand Down
Binary file modified test/image/baselines/15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/airfoil.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/cheater.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/cheater_constraints.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/cheater_fully_filled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/cheater_smooth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/connectgaps_2d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/contour_constraints.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/contour_heatmap_coloring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/contour_legend.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/error_bar_layers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/range_slider.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/range_slider_initial_expanded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/range_slider_initial_valid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/yaxis-over-yaxis2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion test/image/mocks/colorscale_opacity.json
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@
},
"height": 450,
"width": 1100,
"autosize": true
"autosize": true,
"showlegend": false

This comment has been minimized.

Copy link
@etpinard

etpinard Aug 10, 2018

Contributor

Ok. So we need to add this as now more than one trace on this graph is allowed to have a legend item, correct?

This comment has been minimized.

Copy link
@etpinard

etpinard Aug 10, 2018

Contributor

.... which could be interpreted as a breaking change. What is your rationale here?

This comment has been minimized.

Copy link
@alexcjohnson

alexcjohnson Aug 15, 2018

Author Collaborator

Thanks, don't really need to break this. Better showlegend logic in 1d05081

}
}
3 changes: 2 additions & 1 deletion test/image/mocks/contour_scatter.json
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@
"line": {
"color": "black"
},
"type": "scatter"
"type": "scatter",
"showlegend": false
}
]
}

0 comments on commit 7f0db7c

Please sign in to comment.