MCPcopy Index your code
hub / github.com/gonum/plot / Plot

Method Plot

plotter/line.go:64–139  ·  view source on GitHub ↗

Plot draws the Line, implementing the plot.Plotter interface.

(c draw.Canvas, plt *plot.Plot)

Source from the content-addressed store, hash-verified

62
63// Plot draws the Line, implementing the plot.Plotter interface.
64func (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]

Callers

nothing calls this directly

Calls 10

MoveMethod · 0.95
LineMethod · 0.95
CloseMethod · 0.95
TransformsMethod · 0.80
ClipPolygonXYMethod · 0.80
ClipLinesXYMethod · 0.80
SetLineStyleMethod · 0.80
SetColorMethod · 0.65
FillMethod · 0.65
StrokeMethod · 0.65

Tested by

no test coverage detected