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

Method plotVectorized

plotter/heat.go:149–231  ·  view source on GitHub ↗

plotVectorized plots the heatmap using vector-based drawing.

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

Source from the content-addressed store, hash-verified

147
148// plotVectorized plots the heatmap using vector-based drawing.
149func (h *HeatMap) plotVectorized(c draw.Canvas, plt *plot.Plot) {
150 if h.Min > h.Max {
151 panic("contour: invalid Z range: min greater than max")
152 }
153 pal := h.Palette.Colors()
154 if len(pal) == 0 {
155 panic("heatmap: empty palette")
156 }
157 // ps scales the palette uniformly across the data range.
158 ps := float64(len(pal)-1) / (h.Max - h.Min)
159
160 trX, trY := plt.Transforms(&c)
161
162 var pa vg.Path
163 cols, rows := h.GridXYZ.Dims()
164 for i := range cols {
165 var right, left float64
166 switch i {
167 case 0:
168 if cols == 1 {
169 right = 0.5
170 } else {
171 right = (h.GridXYZ.X(1) - h.GridXYZ.X(0)) / 2
172 }
173 left = -right
174 case cols - 1:
175 right = (h.GridXYZ.X(cols-1) - h.GridXYZ.X(cols-2)) / 2
176 left = -right
177 default:
178 right = (h.GridXYZ.X(i+1) - h.GridXYZ.X(i)) / 2
179 left = -(h.GridXYZ.X(i) - h.GridXYZ.X(i-1)) / 2
180 }
181
182 for j := range rows {
183 var up, down float64
184 switch j {
185 case 0:
186 if rows == 1 {
187 up = 0.5
188 } else {
189 up = (h.GridXYZ.Y(1) - h.GridXYZ.Y(0)) / 2
190 }
191 down = -up
192 case rows - 1:
193 up = (h.GridXYZ.Y(rows-1) - h.GridXYZ.Y(rows-2)) / 2
194 down = -up
195 default:
196 up = (h.GridXYZ.Y(j+1) - h.GridXYZ.Y(j)) / 2
197 down = -(h.GridXYZ.Y(j) - h.GridXYZ.Y(j-1)) / 2
198 }
199
200 x, y := trX(h.GridXYZ.X(i)+left), trY(h.GridXYZ.Y(j)+down)
201 dx, dy := trX(h.GridXYZ.X(i)+right), trY(h.GridXYZ.Y(j)+up)
202
203 if !c.Contains(vg.Point{X: x, Y: y}) || !c.Contains(vg.Point{X: dx, Y: dy}) {
204 continue
205 }
206

Callers 1

PlotMethod · 0.95

Calls 12

MoveMethod · 0.95
LineMethod · 0.95
CloseMethod · 0.95
TransformsMethod · 0.80
ContainsMethod · 0.80
ColorsMethod · 0.65
DimsMethod · 0.65
XMethod · 0.65
YMethod · 0.65
ZMethod · 0.65
SetColorMethod · 0.65
FillMethod · 0.65

Tested by

no test coverage detected