+typedef enum { STABLE, SLOW, MODERATE, FAST, CRAZY } velocity_t;
+/* Plot info with smoothing, velocity indication
+ * and one-, two- and three-minute minimums and maximums */
+struct plot_info {
+ int nr;
+ int maxtime;
+ int meandepth, maxdepth;
+ int minpressure, maxpressure;
+ int endpressure; /* start pressure better be max pressure */
+ int mintemp, maxtemp;
+ struct plot_data {
+ unsigned int same_cylinder:1;
+ int sec;
+ int pressure, temperature;
+ /* Depth info */
+ int val;
+ int smoothed;
+ velocity_t velocity;
+ struct plot_data *min[3];
+ struct plot_data *max[3];
+ int avg[3];
+ } entry[];
+};
+
+/* convert velocity to colors */
+typedef struct { double r, g, b; } rgb_t;
+static const rgb_t rgb[] = {
+ [STABLE] = {0.0, 0.4, 0.0},
+ [SLOW] = {0.4, 0.8, 0.0},
+ [MODERATE] = {0.8, 0.8, 0.0},
+ [FAST] = {0.8, 0.5, 0.0},
+ [CRAZY] = {1.0, 0.0, 0.0},
+};
+
+#define plot_info_size(nr) (sizeof(struct plot_info) + (nr)*sizeof(struct plot_data))
+
+/* Scale to 0,0 -> maxx,maxy */
+#define SCALEX(gc,x) (((x)-gc->leftx)/(gc->rightx-gc->leftx)*gc->maxx)
+#define SCALEY(gc,y) (((y)-gc->topy)/(gc->bottomy-gc->topy)*gc->maxy)
+#define SCALE(gc,x,y) SCALEX(gc,x),SCALEY(gc,y)
+
+static void move_to(struct graphics_context *gc, double x, double y)
+{
+ cairo_move_to(gc->cr, SCALE(gc, x, y));
+}
+
+static void line_to(struct graphics_context *gc, double x, double y)
+{
+ cairo_line_to(gc->cr, SCALE(gc, x, y));
+}
+
+static void set_source_rgba(struct graphics_context *gc, double r, double g, double b, double a)
+{
+ /*
+ * For printers, we still honor 'a', but ignore colors
+ * for now. Black is white and white is black
+ */
+ if (gc->printer) {
+ double sum = r+g+b;
+ if (sum > 0.8)
+ r = g = b = 0;
+ else
+ r = g = b = 1;
+ }
+ cairo_set_source_rgba(gc->cr, r, g, b, a);
+}
+
+void set_source_rgb(struct graphics_context *gc, double r, double g, double b)
+{
+ set_source_rgba(gc, r, g, b, 1);
+}
+