Plot draws the Line, implementing the plot.Plotter interface.
(c draw.Canvas, plt *plot.Plot)
| 62 | |
| 63 | // Plot draws the Line, implementing the plot.Plotter interface. |
| 64 | func (pts *Line) Plot(c draw.Canvas, plt *plot.Plot) { |
| 65 | trX, trY := plt.Transforms(&c) |
| 66 | ps := make([]vg.Point, len(pts.XYs)) |
| 67 | |
| 68 | for i, p := range pts.XYs { |
| 69 | ps[i].X = trX(p.X) |
| 70 | ps[i].Y = trY(p.Y) |
| 71 | } |
| 72 | |
| 73 | if pts.FillColor != nil && len(ps) > 0 { |
| 74 | minY := trY(plt.Y.Min) |
| 75 | fillPoly := []vg.Point{{X: ps[0].X, Y: minY}} |
| 76 | switch pts.StepStyle { |
| 77 | case PreStep: |
| 78 | fillPoly = append(fillPoly, ps[1:]...) |
| 79 | case PostStep: |
| 80 | fillPoly = append(fillPoly, ps[:len(ps)-1]...) |
| 81 | default: |
| 82 | fillPoly = append(fillPoly, ps...) |
| 83 | } |
| 84 | fillPoly = append(fillPoly, vg.Point{X: ps[len(ps)-1].X, Y: minY}) |
| 85 | fillPoly = c.ClipPolygonXY(fillPoly) |
| 86 | if len(fillPoly) > 0 { |
| 87 | c.SetColor(pts.FillColor) |
| 88 | var pa vg.Path |
| 89 | prev := fillPoly[0] |
| 90 | pa.Move(prev) |
| 91 | for _, pt := range fillPoly[1:] { |
| 92 | switch pts.StepStyle { |
| 93 | case NoStep: |
| 94 | pa.Line(pt) |
| 95 | case PreStep: |
| 96 | pa.Line(vg.Point{X: prev.X, Y: pt.Y}) |
| 97 | pa.Line(pt) |
| 98 | case MidStep: |
| 99 | pa.Line(vg.Point{X: (prev.X + pt.X) / 2, Y: prev.Y}) |
| 100 | pa.Line(vg.Point{X: (prev.X + pt.X) / 2, Y: pt.Y}) |
| 101 | pa.Line(pt) |
| 102 | case PostStep: |
| 103 | pa.Line(vg.Point{X: pt.X, Y: prev.Y}) |
| 104 | pa.Line(pt) |
| 105 | } |
| 106 | prev = pt |
| 107 | } |
| 108 | pa.Close() |
| 109 | c.Fill(pa) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | lines := c.ClipLinesXY(ps) |
| 114 | if pts.LineStyle.Width != 0 && len(lines) != 0 { |
| 115 | c.SetLineStyle(pts.LineStyle) |
| 116 | for _, l := range lines { |
| 117 | if len(l) == 0 { |
| 118 | continue |
| 119 | } |
| 120 | var p vg.Path |
| 121 | prev := l[0] |
nothing calls this directly
no test coverage detected