| 16 | ) |
| 17 | |
| 18 | func ExampleAlign() { |
| 19 | const rows, cols = 4, 3 |
| 20 | plots := make([][]*plot.Plot, rows) |
| 21 | for j := range rows { |
| 22 | plots[j] = make([]*plot.Plot, cols) |
| 23 | for i := range cols { |
| 24 | if i == 0 && j == 2 { |
| 25 | // This shows what happens when there are nil plots. |
| 26 | continue |
| 27 | } |
| 28 | |
| 29 | p := plot.New() |
| 30 | |
| 31 | if j == 0 && i == 2 { |
| 32 | // This shows what happens when the axis padding |
| 33 | // is different among plots. |
| 34 | p.X.Padding, p.Y.Padding = 0, 0 |
| 35 | } |
| 36 | |
| 37 | if j == 1 && i == 1 { |
| 38 | // To test the Align function, we make the axis labels |
| 39 | // on one of the plots stick out. |
| 40 | p.Y.Max = 1e9 |
| 41 | p.X.Max = 1e9 |
| 42 | p.X.Tick.Label.Rotation = math.Pi / 2 |
| 43 | p.X.Tick.Label.XAlign = draw.XRight |
| 44 | p.X.Tick.Label.YAlign = draw.YCenter |
| 45 | p.X.Tick.Label.Font.Size = 8 |
| 46 | p.Y.Tick.Label.Font.Size = 8 |
| 47 | } else { |
| 48 | p.Y.Max = 1e9 |
| 49 | p.X.Max = 1e9 |
| 50 | p.X.Tick.Label.Font.Size = 1 |
| 51 | p.Y.Tick.Label.Font.Size = 1 |
| 52 | } |
| 53 | |
| 54 | plots[j][i] = p |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | img := vgimg.New(vg.Points(150), vg.Points(175)) |
| 59 | dc := draw.New(img) |
| 60 | |
| 61 | t := draw.Tiles{ |
| 62 | Rows: rows, |
| 63 | Cols: cols, |
| 64 | PadX: vg.Millimeter, |
| 65 | PadY: vg.Millimeter, |
| 66 | PadTop: vg.Points(2), |
| 67 | PadBottom: vg.Points(2), |
| 68 | PadLeft: vg.Points(2), |
| 69 | PadRight: vg.Points(2), |
| 70 | } |
| 71 | |
| 72 | canvases := plot.Align(plots, t, dc) |
| 73 | for j := range rows { |
| 74 | for i := range cols { |
| 75 | if plots[j][i] != nil { |