예제 #1
0
파일: barchart.go 프로젝트: skiesel/plot
// Plot implements the plot.Plotter interface.
func (b *BarChart) Plot(c draw.Canvas, plt *plot.Plot) {
	trCat, trVal := plt.Transforms(&c)
	if b.Horizontal {
		trCat, trVal = trVal, trCat
	}

	for i, ht := range b.Values {
		catVal := b.XMin + float64(i)
		catMin := trCat(float64(catVal))
		if !b.Horizontal {
			if !c.ContainsX(catMin) {
				continue
			}
		} else {
			if !c.ContainsY(catMin) {
				continue
			}
		}
		catMin = catMin - b.Width/2 + b.Offset
		catMax := catMin + b.Width
		bottom := b.stackedOn.BarHeight(i)
		valMin := trVal(bottom)
		valMax := trVal(bottom + ht)

		var pts []draw.Point
		var poly []draw.Point
		if !b.Horizontal {
			pts = []draw.Point{
				{catMin, valMin},
				{catMin, valMax},
				{catMax, valMax},
				{catMax, valMin},
			}
			poly = c.ClipPolygonY(pts)
		} else {
			pts = []draw.Point{
				{valMin, catMin},
				{valMin, catMax},
				{valMax, catMax},
				{valMax, catMin},
			}
			poly = c.ClipPolygonX(pts)
		}
		c.FillPolygon(b.Color, poly)

		var outline [][]draw.Point
		if !b.Horizontal {
			pts = append(pts, draw.Point{X: catMin, Y: valMin})
			outline = c.ClipLinesY(pts)
		} else {
			pts = append(pts, draw.Point{X: valMin, Y: catMin})
			outline = c.ClipLinesX(pts)
		}
		c.StrokeLines(b.LineStyle, outline...)
	}
}
예제 #2
0
파일: errbars.go 프로젝트: skiesel/plot
// Plot implements the Plotter interface, drawing labels.
func (e *XErrorBars) Plot(c draw.Canvas, p *plot.Plot) {
	trX, trY := p.Transforms(&c)
	for i, err := range e.XErrors {
		y := trY(e.XYs[i].Y)
		xlow := trX(e.XYs[i].X - math.Abs(err.Low))
		xhigh := trX(e.XYs[i].X + math.Abs(err.High))

		bar := c.ClipLinesX([]draw.Point{{xlow, y}, {xhigh, y}})
		c.StrokeLines(e.LineStyle, bar...)
		e.drawCap(&c, xlow, y)
		e.drawCap(&c, xhigh, y)
	}
}
예제 #3
0
파일: boxplot.go 프로젝트: skiesel/plot
func (b horizBoxPlot) Plot(c draw.Canvas, plt *plot.Plot) {
	trX, trY := plt.Transforms(&c)
	y := trY(b.Location)
	if !c.ContainsY(y) {
		return
	}
	y += b.Offset

	med := trX(b.Median)
	q1 := trX(b.Quartile1)
	q3 := trX(b.Quartile3)
	aLow := trX(b.AdjLow)
	aHigh := trX(b.AdjHigh)

	box := c.ClipLinesX([]draw.Point{
		{q1, y - b.Width/2},
		{q3, y - b.Width/2},
		{q3, y + b.Width/2},
		{q1, y + b.Width/2},
		{q1, y - b.Width/2 - b.BoxStyle.Width/2},
	})
	c.StrokeLines(b.BoxStyle, box...)

	medLine := c.ClipLinesX([]draw.Point{
		{med, y - b.Width/2},
		{med, y + b.Width/2},
	})
	c.StrokeLines(b.MedianStyle, medLine...)

	cap := b.CapWidth / 2
	whisks := c.ClipLinesX([]draw.Point{{q3, y}, {aHigh, y}},
		[]draw.Point{{aHigh, y - cap}, {aHigh, y + cap}},
		[]draw.Point{{q1, y}, {aLow, y}},
		[]draw.Point{{aLow, y - cap}, {aLow, y + cap}})
	c.StrokeLines(b.WhiskerStyle, whisks...)

	for _, out := range b.Outside {
		x := trX(b.Value(out))
		if c.ContainsX(x) {
			c.DrawGlyphNoClip(b.GlyphStyle, draw.Point{X: x, Y: y})
		}
	}
}