NewHeatMap creates as new heat map plotter for the given data, using the provided palette. If g has Min and Max methods that return a float, those returned values are used to set the respective HeatMap fields. If the returned HeatMap is used when Min is greater than Max, the Plot method will panic.
(g GridXYZ, p palette.Palette)
| 70 | // fields. If the returned HeatMap is used when Min is greater than Max, |
| 71 | // the Plot method will panic. |
| 72 | func NewHeatMap(g GridXYZ, p palette.Palette) *HeatMap { |
| 73 | var min, max float64 |
| 74 | type minMaxer interface { |
| 75 | Min() float64 |
| 76 | Max() float64 |
| 77 | } |
| 78 | switch g := g.(type) { |
| 79 | case minMaxer: |
| 80 | min, max = g.Min(), g.Max() |
| 81 | default: |
| 82 | min, max = math.Inf(1), math.Inf(-1) |
| 83 | c, r := g.Dims() |
| 84 | for i := range c { |
| 85 | for j := range r { |
| 86 | v := g.Z(i, j) |
| 87 | if math.IsNaN(v) { |
| 88 | continue |
| 89 | } |
| 90 | min = math.Min(min, v) |
| 91 | max = math.Max(max, v) |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return &HeatMap{ |
| 97 | GridXYZ: g, |
| 98 | Palette: p, |
| 99 | Min: min, |
| 100 | Max: max, |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // Plot implements the Plot method of the plot.Plotter interface. |
| 105 | func (h *HeatMap) Plot(c draw.Canvas, plt *plot.Plot) { |