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

Method Plot

plotter/polygon.go:54–90  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

52// Plot draws the polygon, implementing the plot.Plotter
53// interface.
54func (pts *Polygon) Plot(c draw.Canvas, plt *plot.Plot) {
55 trX, trY := plt.Transforms(&c)
56 ps := make([][]vg.Point, len(pts.XYs))
57
58 for i, ring := range pts.XYs {
59 ps[i] = make([]vg.Point, len(ring))
60 for j, p := range ring {
61 ps[i][j].X = trX(p.X)
62 ps[i][j].Y = trY(p.Y)
63 }
64 ps[i] = c.ClipPolygonXY(ps[i])
65 }
66 if pts.Color != nil && len(ps) > 0 {
67 c.SetColor(pts.Color)
68 // allocate enough space for at least 4 path components per ring.
69 // 3 is the minimum but 4 is more common.
70 pa := make(vg.Path, 0, 4*len(ps))
71 for _, ring := range ps {
72 if len(ring) == 0 {
73 continue
74 }
75 pa.Move(ring[0])
76 for _, p := range ring[1:] {
77 pa.Line(p)
78 }
79 pa.Close()
80 }
81 c.Fill(pa)
82 }
83
84 for _, ring := range ps {
85 if len(ring) > 0 && ring[len(ring)-1] != ring[0] {
86 ring = append(ring, ring[0])
87 }
88 c.StrokeLines(pts.LineStyle, c.ClipLinesXY(ring)...)
89 }
90}
91
92// DataRange returns the minimum and maximum
93// x and y values, implementing the plot.DataRanger

Callers

nothing calls this directly

Calls 9

TransformsMethod · 0.80
ClipPolygonXYMethod · 0.80
MoveMethod · 0.80
LineMethod · 0.80
CloseMethod · 0.80
StrokeLinesMethod · 0.80
ClipLinesXYMethod · 0.80
SetColorMethod · 0.65
FillMethod · 0.65

Tested by

no test coverage detected