Skip to content

Commit 895b962

Browse files
committed
plot: handle headroom for top-legend
1 parent 89f8c6d commit 895b962

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

legend.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (l *Legend) Draw(c draw.Canvas) {
108108

109109
descent := sty.FontExtents().Descent
110110
enth := l.entryHeight()
111-
y := c.Max.Y - enth
111+
y := c.Max.Y - enth - descent
112112
if !l.Top {
113113
y = c.Min.Y + (enth+l.Padding)*(vg.Length(len(l.entries))-1)
114114
}
@@ -173,12 +173,8 @@ func (l *Legend) Rectangle(c draw.Canvas) vg.Rectangle {
173173
// entryHeight returns the height of the tallest legend
174174
// entry text.
175175
func (l *Legend) entryHeight() (height vg.Length) {
176-
var (
177-
ext = l.TextStyle.FontExtents()
178-
desc = ext.Height - ext.Ascent // descent + linegap
179-
)
180176
for _, e := range l.entries {
181-
if h := l.TextStyle.Rectangle(e.text).Max.Y + desc; h > height {
177+
if h := l.TextStyle.Rectangle(e.text).Max.Y; h > height {
182178
height = h
183179
}
184180
}

0 commit comments

Comments
 (0)