Skip to content

Adapt contour label clipPath segments for reversed axes #3352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions src/traces/contour/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
.classed('contourlabels', true);

if(showLabels) {
var labelClipPathData = [perimeter];

var labelClipPathData = [];
var labelData = [];

// invalidate the getTextLocation cache in case paths changed
Expand Down Expand Up @@ -287,6 +286,13 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
bounds.middle = (bounds.top + bounds.bottom) / 2;
bounds.center = (bounds.left + bounds.right) / 2;

labelClipPathData.push([
[bounds.left, bounds.top],
[bounds.right, bounds.top],
[bounds.right, bounds.bottom],
[bounds.left, bounds.bottom]
]);

var plotDiagonal = Math.sqrt(xLen * xLen + yLen * yLen);

// the path length to use to scale the number of labels to draw:
Expand Down
Binary file modified test/image/baselines/contour_label-reversed-axes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 31 additions & 9 deletions test/image/mocks/contour_label-reversed-axes.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,39 @@
[2, 1, 2],
[2, 1, 2]
],
"contours": {
"showlabels": true
}
"contours": {"showlabels": true}
},
{
"type": "contour",
"z": [
[1, 2, 1],
[2, 1, 2],
[2, 1, 2]
],
"contours": {"showlabels": true},
"xaxis": "x2",
"yaxis": "y2"
},
{
"type": "contour",
"z": [
[1, 2, 1],
[2, 1, 2],
[2, 1, 2]
],
"contours": {"showlabels": true},
"xaxis": "x3",
"yaxis": "y3"
}
],
"layout": {
"yaxis": {
"autorange": "reversed"
},
"xaxis": {
"autorange": "reversed"
}
"grid": {"rows": 2, "columns": 2, "pattern": "independent"},

"xaxis": {"autorange": "reversed"},
"yaxis": {"autorange": "reversed"},

"xaxis2": {"autorange": "reversed"},

"yaxis3": {"autorange": "reversed"}
}
}