Skip to content
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

Contour label extra pad and correct minus sign #4540

Merged
merged 8 commits into from
Mar 14, 2020
51 changes: 27 additions & 24 deletions src/traces/contour/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,21 +394,21 @@ exports.labelFormatter = function(gd, cd0) {
var trace = cd0.trace;
var contours = trace.contours;

var formatAxis = {
type: 'linear',
_id: 'ycontour',
showexponent: 'all',
exponentformat: 'B'
};

if(contours.labelformat) {
return fullLayout._d3locale.numberFormat(contours.labelformat);
formatAxis.tickformat = contours.labelformat;
setConvert(formatAxis, fullLayout);
} else {
var formatAxis;
var cOpts = Colorscale.extractOpts(trace);
if(cOpts && cOpts.colorbar && cOpts.colorbar._axis) {
formatAxis = cOpts.colorbar._axis;
} else {
formatAxis = {
type: 'linear',
_id: 'ycontour',
showexponent: 'all',
exponentformat: 'B'
};

if(contours.type === 'constraint') {
var value = contours.value;
if(Array.isArray(value)) {
Expand All @@ -429,10 +429,9 @@ exports.labelFormatter = function(gd, cd0) {
formatAxis._tmin = null;
formatAxis._tmax = null;
}
return function(v) {
return Axes.tickText(formatAxis, v).text;
};
}

return function(v) { return Axes.tickText(formatAxis, v).text; };
};

exports.calcTextOpts = function(level, contourFormat, dummyText, gd) {
Expand Down Expand Up @@ -544,24 +543,28 @@ function locationCost(loc, textOpts, labelData, bounds) {
}

exports.addLabelData = function(loc, textOpts, labelData, labelClipPathData) {
var halfWidth = textOpts.width / 2;
var halfHeight = textOpts.height / 2;
var w = textOpts.width + 4;
var h = Math.max(0, textOpts.height - 4);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks great for all the baselines we test. But I'm still concerned about it in case someone uses a very different font size, particularly shrinking height by a constant if someone were to use a very small font size, perhaps for publication when it's expected the user can zoom in on the PDF or something.

So yeah, I'd still like to make both the +4 and -4 adjustments relative to font size, or if you think there's some ill effect we'd expect from that, at least ensure the -4 isn't too large a fraction of the height.


var x = loc.x;
var y = loc.y;
var theta = loc.theta;

var sin = Math.sin(theta);
var cos = Math.cos(theta);
var dxw = halfWidth * cos;
var dxh = halfHeight * sin;
var dyw = halfWidth * sin;
var dyh = -halfHeight * cos;

var rotateXY = function(dx, dy) {
return [
x + dx * cos - dy * sin,
y + dx * sin + dy * cos
];
};

var bBoxPts = [
[x - dxw - dxh, y - dyw - dyh],
[x + dxw - dxh, y + dyw - dyh],
[x + dxw + dxh, y + dyw + dyh],
[x - dxw + dxh, y - dyw + dyh],
rotateXY(-w / 2, -h / 2),
rotateXY(-w / 2, h / 2),
rotateXY(w / 2, h / 2),
rotateXY(w / 2, -h / 2)
];

labelData.push({
Expand All @@ -571,8 +574,8 @@ exports.addLabelData = function(loc, textOpts, labelData, labelClipPathData) {
dy: textOpts.dy,
theta: theta,
level: textOpts.level,
width: textOpts.width,
height: textOpts.height
width: w,
height: h
});

labelClipPathData.push(bBoxPts);
Expand Down
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_contour.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.
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_edge_cases.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_label-formatting-via-colorbar.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_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.
Binary file modified test/image/baselines/contour_label-reversed-xy.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_label-thousands-suffix.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/contour_lines_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_nolines.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_scatter.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_transposed-irregular.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/heatmap_contour_irregular_bricks.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/heatmap_multicategory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.