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

Conversation

etpinard
Copy link
Contributor

my attempt to fix #4415

Best to review this PR by comparing the baseline changes in each commit. The changes induces in the first commit a32f76f should be uncontroversial. I'm not 100% sure about the results in commit 30bee29 though: most baselines look at lot better to me, but some appear to have a little too much padding e.g. cheater_contour, contour_label-formatting-via-colorbar, contour_lines_coloring, heatmap_multicategory.

@plotly/plotly_js please let me know what you think.

... to get some formatting additions like the correct minus sign
... that is add 2 px around labels text clip out of contour lines below.

    This becomes especially useful when for negative contour labels,
    to differentiate between the minus sign and the contour line
},

// number of px around labels text clip out of contour lines below
LABEL_LINE_CLIP_PAD: 2
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please try 3px horizontal padding here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

2 px looks like plenty to me, but I might argue for making it a fraction of the font size (or text height) so that it scales with the text.

var halfWidth = textOpts.width / 2;
var halfHeight = textOpts.height / 2;
var halfWidth = textOpts.width / 2 + LABEL_LINE_CLIP_PAD;
var halfHeight = textOpts.height / 2 + LABEL_LINE_CLIP_PAD;
Copy link
Contributor

Choose a reason for hiding this comment

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

After viewing the baseline changes, I think we may not need to add vertical padding to the height.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree, let's not add vertical padding. In fact if there was a way to make it even a tighter fit vertically than it currently is on master, I'd be all for it. Probably not though, assuming that comes from a bounding box... but the goal is to avoid clipping neighboring contour lines as much as possible, since that can cause confusion about which line is actually being labeled.

@etpinard
Copy link
Contributor Author

Thanks for adding commits @archmoj and taking over this PR !!

Looks like your solution uses a constant padding and does not attempt to implement @alexcjohnson's

but I might argue for making it a fraction of the font size (or text height) so that it scales with the text

idea, so I'll let @alexcjohnson confirm that the updated baselines look 👌

@archmoj archmoj requested a review from alexcjohnson March 10, 2020 18:25
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.

@archmoj
Copy link
Contributor

archmoj commented Mar 14, 2020

@alexcjohnson this PR should be ready for another review.
before vs after
Also to note: it would be nice to have it in a minor release.

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

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

💃 Love the new contour font size mock 😍

@archmoj archmoj added this to the v1.53.0 milestone Mar 14, 2020
@archmoj archmoj merged commit fc6486d into master Mar 14, 2020
@archmoj archmoj deleted the contour-label-extra-pad-and-correct-minus-sign branch March 14, 2020 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Contour negative valued layer is not visible
3 participants