Generates the Gnuplot script. @param basepath The base path to use. @param datafiles The names of the data files that need to be plotted, in the order in which they ought to be plotted. It is assumed that the ith file will correspond to the ith entry in datapoints. Can be null if th
(final String basepath,
final String[] datafiles)
| 264 | * Can be {@code null} if there's no data to plot. |
| 265 | */ |
| 266 | private void writeGnuplotScript(final String basepath, |
| 267 | final String[] datafiles) throws IOException { |
| 268 | final String script_path = basepath + ".gnuplot"; |
| 269 | final PrintWriter gp = new PrintWriter(script_path); |
| 270 | try { |
| 271 | // XXX don't hardcode all those settings. At least not like that. |
| 272 | gp.append("set term png small size ") |
| 273 | // Why the fuck didn't they also add methods for numbers? |
| 274 | .append(Short.toString(width)).append(",") |
| 275 | .append(Short.toString(height)); |
| 276 | final String smooth = params.remove("smooth"); |
| 277 | final String fgcolor = params.remove("fgcolor"); |
| 278 | final String style = params.remove("style"); |
| 279 | String bgcolor = params.remove("bgcolor"); |
| 280 | if (fgcolor != null && bgcolor == null) { |
| 281 | // We can't specify a fgcolor without specifying a bgcolor. |
| 282 | bgcolor = "xFFFFFF"; // So use a default. |
| 283 | } |
| 284 | if (bgcolor != null) { |
| 285 | if (fgcolor != null && "transparent".equals(bgcolor)) { |
| 286 | // In case we need to specify a fgcolor but we wanted a transparent |
| 287 | // background, we also need to pass a bgcolor otherwise the first |
| 288 | // hex color will be mistakenly taken as a bgcolor by Gnuplot. |
| 289 | bgcolor = "transparent xFFFFFF"; |
| 290 | } |
| 291 | gp.append(' ').append(bgcolor); |
| 292 | } |
| 293 | if (fgcolor != null) { |
| 294 | gp.append(' ').append(fgcolor); |
| 295 | } |
| 296 | |
| 297 | gp.append("\n" |
| 298 | + "set xdata time\n" |
| 299 | + "set timefmt \"%s\"\n" |
| 300 | + "if (GPVAL_VERSION < 4.6) set xtics rotate; else set xtics rotate right\n" |
| 301 | + "set output \"").append(basepath + ".png").append("\"\n" |
| 302 | + "set xrange [\"") |
| 303 | .append(String.valueOf((start_time & UNSIGNED) + utc_offset)) |
| 304 | .append("\":\"") |
| 305 | .append(String.valueOf((end_time & UNSIGNED) + utc_offset)) |
| 306 | .append("\"]\n"); |
| 307 | if (!params.containsKey("format x")) { |
| 308 | gp.append("set format x \"").append(xFormat()).append("\"\n"); |
| 309 | } |
| 310 | final int nseries = datapoints.size(); |
| 311 | if (nseries > 0) { |
| 312 | gp.write("set grid\n" |
| 313 | + "set style data "); |
| 314 | gp.append(style != null? style : "linespoint").append("\n"); |
| 315 | if (!params.containsKey("key")) { |
| 316 | gp.write("set key right box\n"); |
| 317 | } |
| 318 | } else { |
| 319 | gp.write("unset key\n"); |
| 320 | if (params == null || !params.containsKey("label")) { |
| 321 | gp.write("set label \"No data\" at graph 0.5,0.9 center\n"); |
| 322 | } |
| 323 | } |
no test coverage detected