plotVectorized plots the heatmap using vector-based drawing.
(c draw.Canvas, plt *plot.Plot)
| 147 | |
| 148 | // plotVectorized plots the heatmap using vector-based drawing. |
| 149 | func (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 |