예제 #1
0
// 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},
	}
}
예제 #2
0
파일: canvas.go 프로젝트: zzn01/plot
// At returns the subcanvas within c that corresponds to the
// tile at column x, row y.
func (ts Tiles) At(c Canvas, x, y int) Canvas {
	tileH := (c.Max.Y - c.Min.Y - ts.PadTop - ts.PadBottom -
		vg.Length(ts.Rows-1)*ts.PadY) / vg.Length(ts.Rows)
	tileW := (c.Max.X - c.Min.X - ts.PadLeft - ts.PadRight -
		vg.Length(ts.Cols-1)*ts.PadX) / vg.Length(ts.Cols)

	ymax := c.Max.Y - ts.PadTop - vg.Length(y)*(ts.PadY+tileH)
	ymin := ymax - tileH
	xmin := c.Min.X + ts.PadLeft + vg.Length(x)*(ts.PadX+tileW)
	xmax := xmin + tileW

	return Canvas{
		Canvas: vg.Canvas(c),
		Rectangle: Rectangle{
			Min: Point{X: xmin, Y: ymin},
			Max: Point{X: xmax, Y: ymax},
		},
	}
}
예제 #3
0
파일: plot.go 프로젝트: zzn01/plot
// 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},
		},
	}
}
예제 #4
0
파일: plot.go 프로젝트: zzn01/plot
// 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},
		},
	}
}