plot places a plot at the specified location with the specified dimemsions usinng the specified settings, using the specified data
(x, y, w, h int, settings plotset, d []rawdata)
| 158 | // plot places a plot at the specified location with the specified dimemsions |
| 159 | // usinng the specified settings, using the specified data |
| 160 | func plot(x, y, w, h int, settings plotset, d []rawdata) { |
| 161 | nd := len(d) |
| 162 | if nd < 2 { |
| 163 | fmt.Fprintf(os.Stderr, "%d is not enough points to plot\n", len(d)) |
| 164 | return |
| 165 | } |
| 166 | // Compute the minima and maxima |
| 167 | maxx, minx := d[0].x, d[0].x |
| 168 | maxy, miny := d[0].y, d[0].y |
| 169 | for _, v := range d { |
| 170 | |
| 171 | if v.x > maxx { |
| 172 | maxx = v.x |
| 173 | } |
| 174 | if v.y > maxy { |
| 175 | maxy = v.y |
| 176 | } |
| 177 | if v.x < minx { |
| 178 | minx = v.x |
| 179 | } |
| 180 | if v.y < miny { |
| 181 | miny = v.y |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | if settings.size["ymin"] != smallint { |
| 186 | miny = float64(settings.size["ymin"]) |
| 187 | } |
| 188 | if settings.size["ymax"] != smallint { |
| 189 | maxy = float64(settings.size["ymax"]) |
| 190 | } |
| 191 | // Prepare for a area or line chart by allocating |
| 192 | // polygon coordinates; for the hrizon plot, you need two extra coordinates |
| 193 | // for the extrema. |
| 194 | needpoly := settings.opt["area"] || settings.opt["connect"] |
| 195 | var xpoly, ypoly []int |
| 196 | if needpoly { |
| 197 | xpoly = make([]int, nd+2) |
| 198 | ypoly = make([]int, nd+2) |
| 199 | // preload the extrema of the polygon, |
| 200 | // the bottom left and bottom right of the plot's rectangle |
| 201 | xpoly[0] = x |
| 202 | ypoly[0] = y + h |
| 203 | xpoly[nd+1] = x + w |
| 204 | ypoly[nd+1] = y + h |
| 205 | } |
| 206 | // Draw the plot's bounding rectangle |
| 207 | if settings.opt["showbg"] && !settings.opt["sameplot"] { |
| 208 | canvas.Rect(x, y, w, h, "fill:"+settings.attr["bgcolor"]) |
| 209 | } |
| 210 | // Loop through the data, drawing items as specified |
| 211 | spacer := 10 |
| 212 | canvas.Gstyle(fmt.Sprintf(globalfmt, |
| 213 | settings.attr["font"], settings.size["fontsize"], settings.size["linesize"])) |
| 214 | |
| 215 | for i, v := range d { |
| 216 | xp := int(fmap(v.x, minx, maxx, float64(x), float64(x+w))) |
| 217 | yp := int(fmap(v.y, miny, maxy, float64(y), float64(y-h))) |
no test coverage detected
searching dependent graphs…