MCPcopy
hub / github.com/gonum/plot / Plot

Method Plot

plotter/field.go:88–161  ·  view source on GitHub ↗

Plot implements the Plot method of the plot.Plotter interface.

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

Source from the content-addressed store, hash-verified

86
87// Plot implements the Plot method of the plot.Plotter interface.
88func (f *Field) Plot(c draw.Canvas, plt *plot.Plot) {
89 c.Push()
90 defer c.Pop()
91 c.SetLineStyle(f.LineStyle)
92
93 trX, trY := plt.Transforms(&c)
94
95 cols, rows := f.FieldXY.Dims()
96 for i := range cols {
97 var right, left float64
98 switch i {
99 case 0:
100 if cols == 1 {
101 right = 0.5
102 } else {
103 right = (f.FieldXY.X(1) - f.FieldXY.X(0)) / 2
104 }
105 left = -right
106 case cols - 1:
107 right = (f.FieldXY.X(cols-1) - f.FieldXY.X(cols-2)) / 2
108 left = -right
109 default:
110 right = (f.FieldXY.X(i+1) - f.FieldXY.X(i)) / 2
111 left = -(f.FieldXY.X(i) - f.FieldXY.X(i-1)) / 2
112 }
113
114 for j := range rows {
115 var up, down float64
116 switch j {
117 case 0:
118 if rows == 1 {
119 up = 0.5
120 } else {
121 up = (f.FieldXY.Y(1) - f.FieldXY.Y(0)) / 2
122 }
123 down = -up
124 case rows - 1:
125 up = (f.FieldXY.Y(rows-1) - f.FieldXY.Y(rows-2)) / 2
126 down = -up
127 default:
128 up = (f.FieldXY.Y(j+1) - f.FieldXY.Y(j)) / 2
129 down = -(f.FieldXY.Y(j) - f.FieldXY.Y(j-1)) / 2
130 }
131
132 x, y := trX(f.FieldXY.X(i)+left), trY(f.FieldXY.Y(j)+down)
133 dx, dy := trX(f.FieldXY.X(i)+right), trY(f.FieldXY.Y(j)+up)
134
135 if !c.Contains(vg.Point{X: x, Y: y}) || !c.Contains(vg.Point{X: dx, Y: dy}) {
136 continue
137 }
138
139 c.Push()
140 c.Translate(vg.Point{X: (x + dx) / 2, Y: (y + dy) / 2})
141
142 v := f.FieldXY.Vector(i, j)
143 s := math.Hypot(v.X, v.Y) / (2 * f.max)
144 // Do not scale when the vector is zero, otherwise the
145 // user cannot render special-case glyphs for that case.

Callers

nothing calls this directly

Calls 14

drawVectorFunction · 0.85
SetLineStyleMethod · 0.80
TransformsMethod · 0.80
ContainsMethod · 0.80
PushMethod · 0.65
PopMethod · 0.65
DimsMethod · 0.65
XMethod · 0.65
YMethod · 0.65
TranslateMethod · 0.65
VectorMethod · 0.65
RotateMethod · 0.65

Tested by

no test coverage detected