// Crop returns a new Canvas corresponding to the receiver // area with the given number of inches added to the minimum // and maximum x and y values of the Canvas's Rectangle. func (c Canvas) Crop(minx, miny, maxx, maxy vg.Length) Canvas { minpt := Point{ X: c.Min.X + minx, Y: c.Min.Y + miny, } maxpt := Point{ X: c.Max.X + maxx, Y: c.Max.Y + maxy, } return Canvas{ Canvas: vg.Canvas(c), Rectangle: Rectangle{Min: minpt, Max: maxpt}, } }
// padY returns a draw.Canvas that is padded vertically // so that glyphs will no be clipped. func padY(p *Plot, c draw.Canvas) draw.Canvas { glyphs := p.GlyphBoxes(p) b := bottomMost(&c, glyphs) yAxis := verticalAxis{p.Y} glyphs = append(glyphs, yAxis.GlyphBoxes(p)...) t := topMost(&c, glyphs) miny := c.Min.Y - b.Min.Y maxy := c.Max.Y - (t.Min.Y + t.Size().Y) by := vg.Length(b.Y) ty := vg.Length(t.Y) n := (by*maxy - ty*miny) / (by - ty) m := ((by-1)*maxy - ty*miny + miny) / (by - ty) return draw.Canvas{ Canvas: vg.Canvas(c), Rectangle: draw.Rectangle{ Min: draw.Point{Y: n, X: c.Min.X}, Max: draw.Point{Y: m, X: c.Max.X}, }, } }
// padX returns a draw.Canvas that is padded horizontally // so that glyphs will no be clipped. func padX(p *Plot, c draw.Canvas) draw.Canvas { glyphs := p.GlyphBoxes(p) l := leftMost(&c, glyphs) xAxis := horizontalAxis{p.X} glyphs = append(glyphs, xAxis.GlyphBoxes(p)...) r := rightMost(&c, glyphs) minx := c.Min.X - l.Min.X maxx := c.Max.X - (r.Min.X + r.Size().X) lx := vg.Length(l.X) rx := vg.Length(r.X) n := (lx*maxx - rx*minx) / (lx - rx) m := ((lx-1)*maxx - rx*minx + minx) / (lx - rx) return draw.Canvas{ Canvas: vg.Canvas(c), Rectangle: draw.Rectangle{ Min: draw.Point{X: n, Y: c.Min.Y}, Max: draw.Point{X: m, Y: c.Max.Y}, }, } }