作者:jen
项目:plotinu
// 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)
}
}
作者:jen
项目:plotinu
// 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...)
}
}
作者:knodo
项目:kmode
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)
}
}
作者:markocela
项目:carbonap
// 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...)
}
作者:jackieli
项目:go-plotinu
// 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)...)
}
作者:jen
项目:plotinu
// 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)...)
}
作者:venlion
项目:plotinu
// 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)
}
}
作者:jen
项目:plotinu
// 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)
}
}
作者:akonneke
项目:scicom
// 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)
}
}
}
作者:raf
项目:go-sparklin
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)
}
}
作者:venlion
项目:plotinu
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))
}
}
作者:jen
项目:plotinu
// 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)...)
}
}
作者:ematp
项目:analyze
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)...)
}
作者:ons
项目:analyze
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)...)
}
作者:aquara
项目:plotinu
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},
})
}
}
作者:jen
项目:plotinu
// 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)...)
}
作者:jackieli
项目:go-plotinu
// 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)
}
}
作者:jen
项目:plotinu
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))
}
}
}
作者:jackieli
项目:go-plotinu
// 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)
}
作者:jen
项目:plotinu
// 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)
}