Plot implements the Plot method of the plot.Plotter interface.
(c draw.Canvas, plt *plot.Plot)
| 125 | |
| 126 | // Plot implements the Plot method of the plot.Plotter interface. |
| 127 | func (h *Contour) Plot(c draw.Canvas, plt *plot.Plot) { |
| 128 | if h.Min > h.Max { |
| 129 | panic("contour: invalid Z range: min greater than max") |
| 130 | } |
| 131 | |
| 132 | if naive { |
| 133 | h.naivePlot(c, plt) |
| 134 | return |
| 135 | } |
| 136 | |
| 137 | var pal []color.Color |
| 138 | if h.Palette != nil { |
| 139 | pal = h.Palette.Colors() |
| 140 | } |
| 141 | |
| 142 | trX, trY := plt.Transforms(&c) |
| 143 | |
| 144 | // Collate contour paths and draw them. |
| 145 | // |
| 146 | // The alternative naive approach is to draw each line segment as |
| 147 | // conrec returns it. The integrated path approach allows graphical |
| 148 | // optimisations and is necessary for contour fill shading. |
| 149 | cp := contourPaths(h.GridXYZ, h.Levels, trX, trY) |
| 150 | |
| 151 | // ps is a palette scaling factor to scale the palette uniformly |
| 152 | // across the given levels. This enables a discordance between the |
| 153 | // number of colours and the number of levels. Sorting is not |
| 154 | // necessary since contourPaths sorts the levels as a side effect. |
| 155 | ps := float64(len(pal)-1) / (h.Levels[len(h.Levels)-1] - h.Levels[0]) |
| 156 | if len(h.Levels) == 1 { |
| 157 | ps = 0 |
| 158 | } |
| 159 | |
| 160 | for i, z := range h.Levels { |
| 161 | if math.IsNaN(z) { |
| 162 | continue |
| 163 | } |
| 164 | for _, pa := range cp[z] { |
| 165 | if isLoop(pa) { |
| 166 | pa.Close() |
| 167 | } |
| 168 | |
| 169 | style := h.LineStyles[i%len(h.LineStyles)] |
| 170 | var col color.Color |
| 171 | switch { |
| 172 | case z < h.Min: |
| 173 | col = h.Underflow |
| 174 | case z > h.Max: |
| 175 | col = h.Overflow |
| 176 | case len(pal) == 0: |
| 177 | col = style.Color |
| 178 | default: |
| 179 | col = pal[int((z-h.Levels[0])*ps+0.5)] // Apply palette scaling. |
| 180 | } |
| 181 | if col != nil && style.Width != 0 { |
| 182 | c.SetLineStyle(style) |
| 183 | c.SetColor(col) |
| 184 | c.Stroke(pa) |
nothing calls this directly
no test coverage detected