Example #1
0
// Plot implements the plot.Plotter interface.
func (g *Grid) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)

	if g.Vertical.Color == nil {
		goto horiz
	}
	for _, tk := range plt.X.Tick.Marker(plt.X.Min, plt.X.Max) {
		if tk.IsMinor() {
			continue
		}
		x := trX(tk.Value)
		da.StrokeLine2(g.Vertical, x, da.Min.Y, x, da.Min.Y+da.Size.Y)
	}

horiz:
	if g.Horizontal.Color == nil {
		return
	}
	for _, tk := range plt.Y.Tick.Marker(plt.Y.Min, plt.Y.Max) {
		if tk.IsMinor() {
			continue
		}
		y := trY(tk.Value)
		da.StrokeLine2(g.Horizontal, da.Min.X, y, da.Min.X+da.Size.X, y)
	}
}
Example #2
0
// Plot implements the plot.Plotter interface.
func (b *BarChart) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)

	for i, ht := range b.Values {
		x := b.XMin + float64(i)
		xmin := trX(float64(x))
		if !da.ContainsX(xmin) {
			continue
		}
		xmin = xmin - b.Width/2 + b.Offset
		xmax := xmin + b.Width
		bottom := b.stackedOn.BarHeight(i)
		ymin := trY(bottom)
		ymax := trY(bottom + ht)

		pts := []plot.Point{
			{xmin, ymin},
			{xmin, ymax},
			{xmax, ymax},
			{xmax, ymin},
		}
		poly := da.ClipPolygonY(pts)
		da.FillPolygon(b.Color, poly)

		pts = append(pts, plot.Pt(xmin, ymin))
		outline := da.ClipLinesY(pts)
		da.StrokeLines(b.LineStyle, outline...)
	}
}
Example #3
0
func (pt *Dots) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)

	da.SetColor(pt.Color)

	for i := range pt.Y {
		// Transform the data x, y coordinate of this bubble
		// to the corresponding drawing coordinate.
		x := trX(pt.X[i])
		y := trY(pt.Y[i])

		// Get the radius of this bubble.  The radius
		// is specified in drawing units (i.e., its size
		// is given as the final size at which it will
		// be drawn) so it does not need to be transformed.
		rad := vg.Length(2)

		// Fill a circle centered at x,y on the draw area.
		var p vg.Path
		p.Move(x+rad, y)
		p.Arc(x, y, rad, 0, 2*math.Pi)
		p.Close()
		da.Fill(p)
	}
}
Example #4
0
// Plot draws the Line, implementing the plot.Plotter interface.
func (rp *ResponsePlotter) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)

	start := float64(rp.Response.GetStartTime())
	step := float64(rp.Response.GetStepTime())
	absent := rp.Response.IsAbsent

	lines := make([][]plot.Point, 1)
	lines[0] = make([]plot.Point, 0, len(rp.Response.Values))

	/* ikruglov
	 * swithing between lineMode and looping inside
	 * is more branch-prediction friendly i.e. potentially faster */
	switch rp.lineMode {
	case "slope":
		currentLine := 0
		lastAbsent := false
		for i, v := range rp.Response.Values {
			if absent[i] {
				lastAbsent = true
			} else if lastAbsent {
				currentLine++
				lines = append(lines, make([]plot.Point, 1))
				lines[currentLine][0] = plot.Point{X: trX(start + float64(i)*step), Y: trY(v)}
				lastAbsent = false
			} else {
				lines[currentLine] = append(lines[currentLine], plot.Point{X: trX(start + float64(i)*step), Y: trY(v)})
			}
		}

	case "connected":
		for i, v := range rp.Response.Values {
			if absent[i] {
				continue
			}

			lines[0] = append(lines[0], plot.Point{X: trX(start + float64(i)*step), Y: trY(v)})
		}

	case "drawAsInfinite":
		for i, v := range rp.Response.Values {
			if !absent[i] && v > 0 {
				infiniteLine := []plot.Point{
					plot.Point{X: trX(start + float64(i)*step), Y: da.Y(1)},
					plot.Point{X: trX(start + float64(i)*step), Y: da.Y(0)},
				}
				lines = append(lines, infiniteLine)
			}
		}

	//case "staircase": // TODO
	default:
		panic("Unimplemented " + rp.lineMode)
	}

	da.StrokeLines(rp.LineStyle, lines...)
}
Example #5
0
// Plot draws the Line, implementing the plot.Plotter
// interface.
func (pts *Line) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)
	ps := make([]plot.Point, len(pts.XYs))
	for i, p := range pts.XYs {
		ps[i].X = trX(p.X)
		ps[i].Y = trY(p.Y)
	}
	da.StrokeLines(pts.LineStyle, da.ClipLinesXY(ps)...)
}
Example #6
0
// Plot implements the Plotter interface, drawing a line
// that connects each point in the Line.
func (f *Function) Plot(da plot.DrawArea, p *plot.Plot) {
	trX, trY := p.Transforms(&da)

	d := (p.X.Max - p.X.Min) / float64(f.Samples-1)
	line := make([]plot.Point, f.Samples)
	for i := range line {
		x := p.X.Min + float64(i)*d
		line[i].X = trX(x)
		line[i].Y = trY(f.F(x))
	}
	da.StrokeLines(f.LineStyle, da.ClipLinesXY(line)...)
}
Example #7
0
// Plot implements the Plotter interface, drawing labels.
func (l *Labels) Plot(da plot.DrawArea, p *plot.Plot) {
	trX, trY := p.Transforms(&da)
	for i, label := range l.Labels {
		x := trX(l.XYs[i].X)
		y := trY(l.XYs[i].Y)
		if !da.Contains(plot.Pt(x, y)) {
			continue
		}
		x += l.XOffset
		y += l.YOffset
		da.FillText(l.TextStyle, x, y, l.XAlign, l.YAlign, label)
	}
}
Example #8
0
// Plot implements the Plotter interface, drawing labels.
func (e *YErrorBars) Plot(da plot.DrawArea, p *plot.Plot) {
	trX, trY := p.Transforms(&da)
	for i, err := range e.YErrors {
		x := trX(e.XYs[i].X)
		ylow := trY(e.XYs[i].Y - math.Abs(err.Low))
		yhigh := trY(e.XYs[i].Y + math.Abs(err.High))

		bar := da.ClipLinesY([]plot.Point{{x, ylow}, {x, yhigh}})
		da.StrokeLines(e.LineStyle, bar...)
		e.drawCap(&da, x, ylow)
		e.drawCap(&da, x, yhigh)
	}
}
Example #9
0
// Plot implements the Plotter interface, drawing labels.
func (e *XErrorBars) Plot(da plot.DrawArea, p *plot.Plot) {
	trX, trY := p.Transforms(&da)
	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 := da.ClipLinesX([]plot.Point{{xlow, y}, {xhigh, y}})
		da.StrokeLines(e.LineStyle, bar...)
		e.drawCap(&da, xlow, y)
		e.drawCap(&da, xhigh, y)
	}
}
Example #10
0
// Plot implements the plot.Plotter interface.
func (cg *ColorGrid) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)
	for i, d := range cg.XYZs {
		if i%cg.Ny != cg.Ny-1 && i < cg.Nx*cg.Ny-cg.Ny {
			pts := []plot.Point{
				{trX(d.X), trY(d.Y)},
				{trX(cg.XYZs[i+cg.Ny].X), trY(cg.XYZs[i+cg.Ny].Y)},
				{trX(cg.XYZs[i+cg.Ny+1].X), trY(cg.XYZs[i+cg.Ny+1].Y)},
				{trX(cg.XYZs[i+1].X), trY(cg.XYZs[i+1].Y)},
			}
			da.FillPolygon(color.Gray{uint8((d.Z - cg.MinZ) / math.Abs(cg.MaxZ-cg.MinZ) * 255.0)}, pts)
		}
	}
}
Example #11
0
func (s *SparkLines) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)

	w := vg.Length(1)

	da.SetLineWidth(w)

	_, _, ymin, ymax := s.DataRange()

	for _, d := range s.XYs {
		perc := float64(d.Y-ymin) / float64(ymax-ymin)
		c := BrightColorGradient.GetInterpolatedColorFor((perc*-1+1)*0.5 + 0.6)
		da.SetColor(c)

		// Transform the data x, y coordinate of this bubble
		// to the corresponding drawing coordinate.
		x := trX(d.X)
		y := trY(d.Y * 0.9)

		//rad := vg.Length(10)
		var p vg.Path
		p.Move(x-w, y)
		p.Line(x-w, 0)
		//p.Close()
		da.Stroke(p)

		//da.StrokeLine2(*sty, x, 0, x, y)
	}
}
Example #12
0
func (b *QuartPlot) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)
	x := trX(b.Location)
	if !da.ContainsX(x) {
		return
	}

	med := plot.Pt(x, trY(b.Median))
	q1 := trY(b.Quartile1)
	q3 := trY(b.Quartile3)
	aLow := trY(b.AdjLow)
	aHigh := trY(b.AdjHigh)

	da.StrokeLine2(b.WhiskerStyle, x, aHigh, x, q3)
	da.DrawGlyph(b.MedianStyle, med)
	da.StrokeLine2(b.WhiskerStyle, x, aLow, x, q1)

	ostyle := b.MedianStyle
	ostyle.Radius = b.MedianStyle.Radius / 2
	for _, out := range b.Outside {
		y := trY(b.Value(out))
		da.DrawGlyph(ostyle, plot.Pt(x, y))
	}
}
Example #13
0
// Plot implements the Plotter interface, drawing a line
// that connects each point in the Line.
func (h *Histogram) Plot(da plot.DrawArea, p *plot.Plot) {
	trX, trY := p.Transforms(&da)

	for _, bin := range h.Bins {
		pts := []plot.Point{
			{trX(bin.Min), trY(0)},
			{trX(bin.Max), trY(0)},
			{trX(bin.Max), trY(bin.Weight)},
			{trX(bin.Min), trY(bin.Weight)},
		}
		if h.FillColor != nil {
			da.FillPolygon(h.FillColor, da.ClipPolygonXY(pts))
		}
		pts = append(pts, plot.Pt(trX(bin.Min), trY(0)))
		da.StrokeLines(h.LineStyle, da.ClipLinesXY(pts)...)
	}
}
Example #14
0
func (pts *VerticalLine) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, _ := plt.Transforms(&da)
	ps := make([]plot.Point, 2)
	ps[0].X = trX(pts.X)
	ps[1].X = ps[0].X

	ps[0].Y = da.Min.Y
	ps[1].Y = da.Max().Y

	da.StrokeLines(pts.LineStyle, da.ClipLinesXY(ps)...)
}
Example #15
0
func (pts *HorizontalLine) Plot(da plot.DrawArea, plt *plot.Plot) {
	_, trY := plt.Transforms(&da)
	ps := make([]plot.Point, 2)

	ps[0].X = da.Min.X
	ps[1].X = da.Max().X

	ps[0].Y = trY(pts.Y)
	ps[1].Y = ps[0].Y

	da.StrokeLines(pts.LineStyle, da.ClipLinesXY(ps)...)
}
Example #16
0
func (g GlyphBoxes) Plot(da plot.DrawArea, plt *plot.Plot) {
	for _, b := range plt.GlyphBoxes(plt) {
		x := da.X(b.X) + b.Rect.Min.X
		y := da.Y(b.Y) + b.Rect.Min.Y
		da.StrokeLines(g.LineStyle, []plot.Point{
			{x, y},
			{x + b.Rect.Size.X, y},
			{x + b.Rect.Size.X, y + b.Rect.Size.Y},
			{x, y + b.Rect.Size.Y},
			{x, y},
		})
	}
}
Example #17
0
// Plot draws the Line, implementing the plot.Plotter
// interface.
func (pts *Line) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)
	ps := make([]plot.Point, len(pts.XYs))

	for i, p := range pts.XYs {
		ps[i].X = trX(p.X)
		ps[i].Y = trY(p.Y)
	}

	if pts.ShadeColor != nil && len(ps) > 0 {
		da.SetColor(*pts.ShadeColor)
		minY := trY(plt.Y.Min)
		var pa vg.Path
		pa.Move(ps[0].X, minY)
		for i := range pts.XYs {
			pa.Line(ps[i].X, ps[i].Y)
		}
		pa.Line(ps[len(pts.XYs)-1].X, minY)
		pa.Close()
		da.Fill(pa)
	}

	da.StrokeLines(pts.LineStyle, da.ClipLinesXY(ps)...)
}
Example #18
0
// Plot implements the Plot method of the plot.Plotter interface.
func (bs *Bubbles) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)

	da.SetColor(bs.Color)

	for _, d := range bs.XYZs {
		x := trX(d.X)
		y := trY(d.Y)
		if !da.Contains(plot.Point{x, y}) {
			continue
		}

		rad := bs.radius(d.Z)

		// draw a circle centered at x, y
		var p vg.Path
		p.Move(x+rad, y)
		p.Arc(x, y, rad, 0, 2*math.Pi)
		p.Close()
		da.Fill(p)
	}
}
Example #19
0
func (b HorizQuartPlot) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)
	y := trY(b.Location)
	if !da.ContainsY(y) {
		return
	}
	y += b.Offset

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

	da.StrokeLine2(b.WhiskerStyle, aHigh, y, q3, y)
	if da.ContainsX(med.X) {
		da.DrawGlyphNoClip(b.MedianStyle, med)
	}
	da.StrokeLine2(b.WhiskerStyle, aLow, y, q1, y)

	ostyle := b.MedianStyle
	ostyle.Radius = b.MedianStyle.Radius / 2
	for _, out := range b.Outside {
		x := trX(b.Value(out))
		if da.ContainsX(x) {
			da.DrawGlyphNoClip(ostyle, plot.Pt(x, y))
		}
	}
}
Example #20
0
// drawCap draws the cap if it is not clipped.
func (e *XErrorBars) drawCap(da *plot.DrawArea, x, y vg.Length) {
	if !da.Contains(plot.Point{x, y}) {
		return
	}
	da.StrokeLine2(e.LineStyle, x, y-e.CapWidth/2, x, y+e.CapWidth/2)
}
Example #21
0
// drawCap draws the cap if it is not clipped.
func (e *YErrorBars) drawCap(da *plot.DrawArea, x, y vg.Length) {
	if !da.Contains(plot.Pt(x, y)) {
		return
	}
	da.StrokeLine2(e.LineStyle, x-e.CapWidth/2, y, x+e.CapWidth/2, y)
}
Example #22
0
// Thumbnail the thumbnail for the Line,
// implementing the plot.Thumbnailer interface.
func (pts *Line) Thumbnail(da *plot.DrawArea) {
	y := da.Center().Y
	da.StrokeLine2(pts.LineStyle, da.Min.X, y, da.Max().X, y)
}
Example #23
0
func (b *BarChart) Thumbnail(da *plot.DrawArea) {
	pts := []plot.Point{
		{da.Min.X, da.Min.Y},
		{da.Min.X, da.Max().Y},
		{da.Max().X, da.Max().Y},
		{da.Max().X, da.Min.Y},
	}
	poly := da.ClipPolygonY(pts)
	da.FillPolygon(b.Color, poly)

	pts = append(pts, plot.Pt(da.Min.X, da.Min.Y))
	outline := da.ClipLinesY(pts)
	da.StrokeLines(b.LineStyle, outline...)
}
Example #24
0
// Thumbnail the thumbnail for the Line,
// implementing the plot.Thumbnailer interface.
func (pts *Line) Thumbnail(da *plot.DrawArea) {
	if pts.ShadeColor != nil {
		points := []plot.Point{
			{da.Min.X, da.Min.Y},
			{da.Min.X, da.Max().Y},
			{da.Max().X, da.Max().Y},
			{da.Max().X, da.Min.Y},
		}
		poly := da.ClipPolygonY(points)
		da.FillPolygon(*pts.ShadeColor, poly)

		points = append(points, plot.Pt(da.Min.X, da.Min.Y))
	} else {
		y := da.Center().Y
		da.StrokeLine2(pts.LineStyle, da.Min.X, y, da.Max().X, y)
	}
}
Example #25
0
// Thumbnail the thumbnail for the Scatter,
// implementing the plot.Thumbnailer interface.
func (pts *Scatter) Thumbnail(da *plot.DrawArea) {
	da.DrawGlyph(pts.GlyphStyle, da.Center())
}
Example #26
0
// Plot draws the Scatter, implementing the plot.Plotter
// interface.
func (pts *Scatter) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)
	for _, p := range pts.XYs {
		da.DrawGlyph(pts.GlyphStyle, plot.Pt(trX(p.X), trY(p.Y)))
	}
}
Example #27
0
func (b *BoxPlot) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)
	x := trX(b.Location)
	if !da.ContainsX(x) {
		return
	}

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

	box := da.ClipLinesY([]plot.Point{
		{x - b.Width/2, q1},
		{x - b.Width/2, q3},
		{x + b.Width/2, q3},
		{x + b.Width/2, q1},
		{x - b.Width/2 - b.BoxStyle.Width/2, q1},
	})
	da.StrokeLines(b.BoxStyle, box...)

	medLine := da.ClipLinesY([]plot.Point{
		{x - b.Width/2, med},
		{x + b.Width/2, med},
	})
	da.StrokeLines(b.MedianStyle, medLine...)

	cap := b.CapWidth / 2
	whisks := da.ClipLinesY([]plot.Point{{x, q3}, {x, aHigh}},
		[]plot.Point{{x - cap, aHigh}, {x + cap, aHigh}},
		[]plot.Point{{x, q1}, {x, aLow}},
		[]plot.Point{{x - cap, aLow}, {x + cap, aLow}})
	da.StrokeLines(b.WhiskerStyle, whisks...)

	for _, out := range b.Outside {
		y := trY(b.Value(out))
		da.DrawGlyph(b.GlyphStyle, plot.Point{x, y})
	}
}
Example #28
0
func (b HorizBoxPlot) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)
	y := trY(b.Location)
	if !da.ContainsY(y) {
		return
	}

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

	box := da.ClipLinesX([]plot.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},
	})
	da.StrokeLines(b.BoxStyle, box...)

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

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

	for _, out := range b.Outside {
		x := trX(b.Value(out))
		da.DrawGlyph(b.GlyphStyle, plot.Point{x, y})
	}
}
Example #29
0
// Thumbnail draws a line in the given style down the
// center of a DrawArea as a thumbnail representation
// of the LineStyle of the function.
func (f Function) Thumbnail(da *plot.DrawArea) {
	y := da.Center().Y
	da.StrokeLine2(f.LineStyle, da.Min.X, y, da.Max().X, y)
}
Example #30
0
func (l *LineThumbnailer) Thumbnail(da *plot.DrawArea) {
	y := da.Center().Y
	da.StrokeLine2(l.LineStyle, da.Min.X, y, da.Max().X, y)
}