Skip to content

Commit a51a196

Browse files
committed
plot: fix handling of font descents
1 parent cf58149 commit a51a196

89 files changed

Lines changed: 694 additions & 689 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

axis.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,20 +262,21 @@ func (a horizontalAxis) draw(c draw.Canvas) {
262262
x -= a.Label.Font.Width(a.Label.Text) / 2
263263
}
264264
if a.Label.Text != "" {
265-
y -= a.Label.Font.Extents().Descent
266-
c.FillText(a.Label.TextStyle, vg.Point{X: x, Y: y}, a.Label.Text)
265+
descent := a.Label.Font.Extents().Descent
266+
c.FillText(a.Label.TextStyle, vg.Point{X: x, Y: y - descent}, a.Label.Text)
267267
y += a.Label.Height(a.Label.Text)
268268
y += a.Label.Padding
269269
}
270270

271271
marks := a.Tick.Marker.Ticks(a.Min, a.Max)
272272
ticklabelheight := tickLabelHeight(a.Tick.Label, marks)
273+
descent := a.Tick.Label.Font.Extents().Descent
273274
for _, t := range marks {
274275
x := c.X(a.Norm(t.Value))
275276
if !c.ContainsX(x) || t.IsMinor() {
276277
continue
277278
}
278-
c.FillText(a.Tick.Label, vg.Point{X: x, Y: y + ticklabelheight}, t.Label)
279+
c.FillText(a.Tick.Label, vg.Point{X: x, Y: y + ticklabelheight - descent}, t.Label)
279280
}
280281

281282
if len(marks) > 0 {
@@ -362,8 +363,9 @@ func (a verticalAxis) draw(c draw.Canvas) {
362363
y = c.Max.Y
363364
y -= a.Label.Font.Width(a.Label.Text) / 2
364365
}
365-
c.FillText(sty, vg.Point{X: x, Y: y}, a.Label.Text)
366-
x += -a.Label.Font.Extents().Descent
366+
descent := a.Label.Font.Extents().Descent
367+
c.FillText(sty, vg.Point{X: x + descent, Y: y}, a.Label.Text)
368+
x -= descent
367369
x += a.Label.Padding
368370
}
369371
marks := a.Tick.Marker.Ticks(a.Min, a.Max)
@@ -372,12 +374,13 @@ func (a verticalAxis) draw(c draw.Canvas) {
372374
}
373375

374376
major := false
377+
descent := a.Tick.Label.Font.Extents().Descent
375378
for _, t := range marks {
376379
y := c.Y(a.Norm(t.Value))
377380
if !c.ContainsY(y) || t.IsMinor() {
378381
continue
379382
}
380-
c.FillText(a.Tick.Label, vg.Point{X: x, Y: y}, t.Label)
383+
c.FillText(a.Tick.Label, vg.Point{X: x, Y: y - descent}, t.Label)
381384
major = true
382385
}
383386
if major {

legend.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ func (l *Legend) Draw(c draw.Canvas) {
105105
textx += l.XOffs
106106
iconx += l.XOffs
107107

108-
enth := l.entryHeight()
108+
descent := sty.Font.Extents().Descent
109+
enth := l.entryHeight() + descent
109110
y := c.Max.Y - enth
110111
if !l.Top {
111112
y = c.Min.Y + (enth+l.Padding)*(vg.Length(len(l.entries))-1)
@@ -124,7 +125,7 @@ func (l *Legend) Draw(c draw.Canvas) {
124125
panic("plot: invalid vertical offset for the legend's entries")
125126
}
126127
yoff := vg.Length(l.YPosition-draw.PosBottom) / 2
127-
yoff *= -sty.Font.Extents().Descent
128+
yoff -= descent
128129

129130
for _, e := range l.entries {
130131
for _, t := range e.thumbs {
10.1 KB
109 Bytes
77 Bytes

plot.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ func (p *Plot) Draw(c draw.Canvas) {
152152
c.Fill(c.Rectangle.Path())
153153
}
154154
if p.Title.Text != "" {
155-
c.FillText(p.Title.TextStyle, vg.Point{X: c.Center().X, Y: c.Max.Y}, p.Title.Text)
155+
descent := p.Title.TextStyle.Font.Extents().Descent
156+
c.FillText(p.Title.TextStyle, vg.Point{X: c.Center().X, Y: c.Max.Y - descent}, p.Title.Text)
156157
_, h, d := p.Title.Handler.Box(p.Title.Text, p.Title.Font)
157158
c.Max.Y -= h + d
158159
c.Max.Y -= p.Title.Padding
529 Bytes
90 Bytes
-231 Bytes
257 Bytes

0 commit comments

Comments
 (0)