padX returns a draw.Canvas that is padded horizontally so that glyphs will no be clipped.
(p *Plot, c draw.Canvas)
| 255 | // padX returns a draw.Canvas that is padded horizontally |
| 256 | // so that glyphs will no be clipped. |
| 257 | func padX(p *Plot, c draw.Canvas) draw.Canvas { |
| 258 | glyphs := p.GlyphBoxes(p) |
| 259 | l := leftMost(&c, glyphs) |
| 260 | xAxis := horizontalAxis{p.X} |
| 261 | glyphs = append(glyphs, xAxis.GlyphBoxes(p)...) |
| 262 | r := rightMost(&c, glyphs) |
| 263 | |
| 264 | minx := c.Min.X - l.Min.X |
| 265 | maxx := c.Max.X - (r.Min.X + r.Size().X) |
| 266 | lx := vg.Length(l.X) |
| 267 | rx := vg.Length(r.X) |
| 268 | n := (lx*maxx - rx*minx) / (lx - rx) |
| 269 | m := ((lx-1)*maxx - rx*minx + minx) / (lx - rx) |
| 270 | return draw.Canvas{ |
| 271 | Canvas: vg.Canvas(c), |
| 272 | Rectangle: vg.Rectangle{ |
| 273 | Min: vg.Point{X: n, Y: c.Min.Y}, |
| 274 | Max: vg.Point{X: m, Y: c.Max.Y}, |
| 275 | }, |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | // rightMost returns the right-most GlyphBox. |
| 280 | func rightMost(c *draw.Canvas, boxes []GlyphBox) GlyphBox { |
no test coverage detected