Beispiel #1
0
// WriterTo returns an io.WriterTo that will write the plot as
// the specified image format.
//
// Supported formats are:
//
//  eps, jpg|jpeg, pdf, png, svg, and tif|tiff.
func (p *Plot) WriterTo(w, h vg.Length, format string) (io.WriterTo, error) {
	c, err := draw.NewFormattedCanvas(w, h, format)
	if err != nil {
		return nil, err
	}
	p.Draw(draw.New(c))
	return c, nil
}
Beispiel #2
0
func main() {
	const (
		p     = 1 * vg.Centimeter
		nrows = 4
		ncols = 5
	)
	for _, f := range formats {
		c, err := draw.NewFormattedCanvas(10*ncols*vg.Centimeter,
			10*nrows*vg.Centimeter, f)
		if err != nil {
			log.Fatal(err)
		}
		dc := draw.New(c)
		tiles := draw.Tiles{
			Rows: nrows, Cols: ncols,
			PadTop: p, PadBottom: p,
			PadRight: p, PadLeft: p,
			PadX: p, PadY: p,
		}
		ii := 0
		for j := 0; j < nrows; j++ {
			for i := 0; i < ncols; i++ {
				if ii < len(examples) {
					ex := examples[ii]
					ex.p.Draw(tiles.At(dc, i, j))
					if err != nil {
						log.Fatalf("failed to draw tile for  %s.%s: %v", ex.name, f, err)
					}
					ii++
				}
			}
		}
		w, err := os.Create("examples." + f)
		if err != nil {
			log.Fatal(err)
		}
		_, err = c.WriteTo(w)
		if err != nil {
			log.Fatal(err)
		}
	}
}