return MAX(90, ROUND_UP(feet+5, 15));
}
-static void plot_text(cairo_t *cr, double x, double y, const char *fmt, ...)
+typedef struct {
+ double r,g,b;
+ enum {CENTER,LEFT} allign;
+} text_render_options_t;
+
+static void plot_text(cairo_t *cr, text_render_options_t *tro,
+ double x, double y, const char *fmt, ...)
{
cairo_text_extents_t extents;
char buffer[80];
cairo_text_extents(cr, buffer, &extents);
- x -= extents.width/2 + extents.x_bearing;
+ if (tro->allign == CENTER)
+ x -= extents.width/2 + extents.x_bearing;
y += extents.height * 1.2;
cairo_move_to(cr, x, y);
cairo_stroke(cr);
cairo_move_to(cr, x, y);
- cairo_set_source_rgb(cr, 1, 0, 0);
+ cairo_set_source_rgb(cr, tro->r, tro->g, tro->b);
cairo_show_text(cr, buffer);
}
cairo_set_source_rgb(cr, 1, 0.2, 0.2);
i = 0;
while ((i = next_minmax(dive, i, 1)) != 0) {
+ text_render_options_t tro = {1.0, 0.2, 0.2, CENTER};
struct sample *sample = dive->sample+i;
int sec = sample->time.seconds;
int depth = to_feet(sample->depth);
- plot_text(cr, SCALE(sec, depth), "%d ft", depth);
+ plot_text(cr, &tro, SCALE(sec, depth), "%d ft", depth);
i = next_minmax(dive, i, 0);
if (!i)
break;
cairo_stroke(cr);
}
-static int get_cylinder_pressure_range(struct dive *dive, double *scalex, double *scaley)
+/* gets both the actual start and end pressure as well as the scaling factors */
+static int get_cylinder_pressure_range(struct dive *dive, double *scalex, double *scaley,
+ double *startp, double *endp)
{
int i;
double min, max;
+ double bar;
*scalex = round_seconds_up(dive->duration.seconds);
max = 0;
min = 5000;
+ if (startp)
+ *startp = *endp = 0.0;
+
for (i = 0; i < dive->samples; i++) {
struct sample *sample = dive->sample + i;
- double bar;
/* FIXME! We only track cylinder 0 right now */
if (sample->cylinderindex)
if (!sample->cylinderpressure.mbar)
continue;
bar = sample->cylinderpressure.mbar;
+ if (bar != 0.0 && startp && *startp == 0.0)
+ *startp = bar;
if (bar < min)
min = bar;
if (bar > max)
max = bar;
}
+ if (endp)
+ *endp = bar;
if (!max)
return 0;
*scaley = max * 1.5;
int i, sec = -1;
double scalex, scaley;
- if (!get_cylinder_pressure_range(dive, &scalex, &scaley))
+ if (!get_cylinder_pressure_range(dive, &scalex, &scaley, NULL, NULL))
return;
cairo_set_source_rgba(cr, 0.2, 1.0, 0.2, 0.80);
cairo_stroke(cr);
}
+
+static void plot_cylinder_pressure_text(struct dive *dive, cairo_t *cr,
+ double topx, double topy, double maxx, double maxy)
+{
+ double scalex, scaley;
+ double startp,endp;
+
+ cairo_set_font_size(cr, 10);
+
+ if (get_cylinder_pressure_range(dive, &scalex, &scaley,
+ &startp, &endp)) {
+ text_render_options_t tro = {0.2, 1.0, 0.2, LEFT};
+ plot_text(cr, &tro, SCALE(0, startp), "%3.0f bar", startp/1000.0);
+ plot_text(cr, &tro, SCALE(dive->duration.seconds, endp),
+ "%3.0f bar", endp/1000.0);
+ }
+}
+
static void plot(cairo_t *cr, int w, int h, struct dive *dive)
{
double topx, topy, maxx, maxy;
/* Text on top of all graphs.. */
plot_depth_text(dive, cr, topx, topy, maxx, maxy);
+ plot_cylinder_pressure_text(dive, cr, topx, topy, maxx, maxy);
/* Bounding box last */
scalex = scaley = 1.0;