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

plot: fix handling of font descents #642

Merged
merged 3 commits into from Nov 3, 2020
Merged

plot: fix handling of font descents #642

merged 3 commits into from Nov 3, 2020

Conversation

kortschak
Copy link
Member

Please take a look.

Fixes #294

@codecov-io
Copy link

codecov-io commented Nov 2, 2020

Codecov Report

Merging #642 into master will decrease coverage by 1.24%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #642      +/-   ##
==========================================
- Coverage   71.52%   70.28%   -1.25%     
==========================================
  Files          55       55              
  Lines        5492     4620     -872     
==========================================
- Hits         3928     3247     -681     
+ Misses       1390     1203     -187     
+ Partials      174      170       -4     
Impacted Files Coverage Δ
cmpimg/checkplot.go 0.00% <0.00%> (ø)
vg/draw/text.go 0.00% <0.00%> (ø)
axis.go 83.39% <100.00%> (+0.54%) ⬆️
legend.go 94.11% <100.00%> (-0.62%) ⬇️
plot.go 67.21% <100.00%> (-0.40%) ⬇️
vg/font_syscall.go 33.33% <0.00%> (-16.67%) ⬇️
plotter/plotter.go 63.82% <0.00%> (-7.60%) ⬇️
vg/vg.go 40.00% <0.00%> (-5.46%) ⬇️
plotter/labels.go 76.47% <0.00%> (-4.93%) ⬇️
vg/vgsvg/vgsvg.go 60.00% <0.00%> (-4.20%) ⬇️
... and 50 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cad3ccd...0694c3f. Read the comment docs.

sbinet
sbinet previously approved these changes Nov 2, 2020
Copy link
Member

@sbinet sbinet left a comment

Choose a reason for hiding this comment

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

LGTM.

perhaps, if not too much trouble, separate the commits into 2:

  • rewiring of the -regen flag infrastructure
  • fixing the fonts' descent handling

(it's ok to leave them both into the same PR)

y += a.Label.Height(a.Label.Text)
y += a.Label.Padding
}

marks := a.Tick.Marker.Ticks(a.Min, a.Max)
ticklabelheight := tickLabelHeight(a.Tick.Label, marks)
descent := a.Tick.Label.Font.Extents().Descent
Copy link
Member

Choose a reason for hiding this comment

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

couldn't we move this up at line 263 and drop the line 265?
descent should be a constant for a given font.Font, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

L265 is for the label and L273 is for the tick label.

@@ -372,12 +374,13 @@ func (a verticalAxis) draw(c draw.Canvas) {
}

major := false
descent := a.Tick.Label.Font.Extents().Descent
Copy link
Member

Choose a reason for hiding this comment

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

ditto: perhaps move that up at ~line 355 and drop the one at line 366 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Same reason.

plot_test.go Outdated
got := r.Actions
c := vgimg.PngCanvas{Canvas: vgimg.New(5*vg.Centimeter, 5*vg.Centimeter)}
l.Draw(draw.New(c))
b := bytes.NewBuffer([]byte{})
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
b := bytes.NewBuffer([]byte{})
b := new(bytes.Buffer)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@kortschak
Copy link
Member Author

PTAL

Copy link
Member

@sbinet sbinet left a comment

Choose a reason for hiding this comment

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

Thanks.

@kortschak kortschak merged commit a51a196 into master Nov 3, 2020
@kortschak kortschak deleted the font/descent branch November 3, 2020 08:20
@kortschak
Copy link
Member Author

This is probably worth a patch release. WDTY?

@sbinet
Copy link
Member

sbinet commented Nov 3, 2020

Yes, I was about to suggest that as well.

@kortschak
Copy link
Member Author

I'll do that tomorrow.

@sbinet
Copy link
Member

sbinet commented Nov 5, 2020

interestingly, after updating my reference files on a Linux machine, tests failed on the Darwin machine (from Github Actions) but was ok on Windows:

go-hep/hep#817

@kortschak
Copy link
Member Author

Font handling differences?

@sbinet
Copy link
Member

sbinet commented Nov 5, 2020

could be, though I am using the embedded LiberationSans-Regular fonts:

@sbinet
Copy link
Member

sbinet commented Nov 5, 2020

the delta is available here:

the diff there:

the new file here:
img

it seems there's only one pixel difference, not involving fonts, actually...

sbinet added a commit to sbinet-hep/hep that referenced this pull request Nov 5, 2020
there's a 1-pixel difference on darwin w/ the linux generated reference
plot.
see:
 gonum/plot#642 (comment)

drop the image check on darwin for that particular test.

Updates go-hep#818.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Padding below X axis?
3 participants