Skip to content

Commit

Permalink
Changed plot axis padding to correctly handle rotated tick labels
Browse files Browse the repository at this point in the history
  • Loading branch information
ctessum authored and sbinet committed Feb 13, 2017
1 parent 0a603a9 commit e6157b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions axis.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ type horizontalAxis struct {

// size returns the height of the axis.
func (a *horizontalAxis) size() (h vg.Length) {
if a.Label.Text != "" {
if a.Label.Text != "" { // We assume that the label isn't rotated.
h -= a.Label.Font.Extents().Descent
h += a.Label.Height(a.Label.Text)
}
Expand Down Expand Up @@ -258,13 +258,9 @@ func (a *horizontalAxis) GlyphBoxes(*Plot) (boxes []GlyphBox) {
if t.IsMinor() {
continue
}
w := a.Tick.Label.Width(t.Label)
box := GlyphBox{
X: a.Norm(t.Value),
Rectangle: vg.Rectangle{
Min: vg.Point{X: -w / 2},
Max: vg.Point{X: w / 2},
},
X: a.Norm(t.Value),
Rectangle: a.Tick.Label.Rectangle(t.Label),
}
boxes = append(boxes, box)
}
Expand All @@ -278,7 +274,7 @@ type verticalAxis struct {

// size returns the width of the axis.
func (a *verticalAxis) size() (w vg.Length) {
if a.Label.Text != "" {
if a.Label.Text != "" { // We assume that the label isn't rotated.
w -= a.Label.Font.Extents().Descent
w += a.Label.Height(a.Label.Text)
}
Expand Down Expand Up @@ -343,13 +339,9 @@ func (a *verticalAxis) GlyphBoxes(*Plot) (boxes []GlyphBox) {
if t.IsMinor() {
continue
}
h := a.Tick.Label.Height(t.Label)
box := GlyphBox{
Y: a.Norm(t.Value),
Rectangle: vg.Rectangle{
Min: vg.Point{Y: -h / 2},
Max: vg.Point{Y: h / 2},
},
Y: a.Norm(t.Value),
Rectangle: a.Tick.Label.Rectangle(t.Label),
}
boxes = append(boxes, box)
}
Expand Down
Binary file modified plotter/testdata/rotation_golden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e6157b7

Please sign in to comment.