Skip to content

Commit

Permalink
plot: Make Align honor tile margins
Browse files Browse the repository at this point in the history
  • Loading branch information
ctessum committed Jun 12, 2018
1 parent f671bfc commit 2459b16
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions align.go
Expand Up @@ -63,12 +63,12 @@ func Align(plots [][]*Plot, t draw.Tiles, dc draw.Canvas) [][]draw.Canvas {
for _, s := range xSpacing {
xTotalSpace += s.n + s.p
}
xTotalSpace += float64(t.PadX) * float64(len(xSpacing)-1)
xTotalSpace += float64(t.PadX)*float64(len(xSpacing)-1) + float64(t.PadLeft+t.PadRight)
var yTotalSpace float64
for _, s := range ySpacing {
yTotalSpace += s.n + s.p
}
yTotalSpace += float64(t.PadY) * float64(len(ySpacing)-1)
yTotalSpace += float64(t.PadY)*float64(len(ySpacing)-1) + float64(t.PadTop+t.PadBottom)

avgWidth := vg.Length((float64(dc.Max.X-dc.Min.X) - xTotalSpace) / float64(t.Cols))
avgHeight := vg.Length((float64(dc.Max.Y-dc.Min.Y) - yTotalSpace) / float64(t.Rows))
Expand Down
12 changes: 8 additions & 4 deletions align_test.go
Expand Up @@ -62,10 +62,14 @@ func ExampleAlign() {
dc := draw.New(img)

t := draw.Tiles{
Rows: rows,
Cols: cols,
PadX: vg.Millimeter,
PadY: vg.Millimeter,
Rows: rows,
Cols: cols,
PadX: vg.Millimeter,
PadY: vg.Millimeter,
PadTop: vg.Points(2),
PadBottom: vg.Points(2),
PadLeft: vg.Points(2),
PadRight: vg.Points(2),
}

canvases := Align(plots, t, dc)
Expand Down
Binary file modified testdata/align_golden.png
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 2459b16

Please sign in to comment.