diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2012-11-01 10:04:12 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-11-01 10:04:12 -0700 |
commit | 1b606ae2260395471890616f8b9dcb16e997fa3d (patch) | |
tree | 1a674959df73ed1ed5d274e04cd61d4722fdc8a3 | |
parent | 072b4f743c19566ad55bb4b30e0844082cccfbd1 (diff) | |
download | subsurface-1b606ae2260395471890616f8b9dcb16e997fa3d.tar.gz |
First stab at plotting a pO2 graph
So far this is done unconditionally. This already starts some of the
infrastructure for other gases, but so far only O2 is handled.
We also need a pressure scale on the right to make this useful - or we
need to do peek / trough pressure prints like we do for temperature and
depth.
Finally, I think I want to move the plot further down, maybe make the
whole plot area taller if we are plotting partial gas pressures as well.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | color.h | 7 | ||||
-rw-r--r-- | display-gtk.h | 6 | ||||
-rw-r--r-- | profile.c | 44 |
3 files changed, 55 insertions, 2 deletions
@@ -9,6 +9,7 @@ #define FUNGREEN1 { 0.0, 0.4, 0.2, 1 } #define KILLARNEY1 { 0.2, 0.4, 0.2, 1 } #define APPLE1 { 0.2, 0.6, 0.2, 1 } +#define APPLE1_MED_TRANS { 0.2, 0.6, 0.2, 0.5 } #define LIMENADE1 { 0.4, 0.8, 0.0, 1 } #define ATLANTIS1 { 0.4, 0.8, 0.2, 1 } #define ATLANTIS2 { 0.6, 0.8, 0.2, 1 } @@ -38,12 +39,14 @@ // Blues #define GOVERNORBAY2 { 0.2, 0.2, 0.7, 1 } #define GOVERNORBAY1_MED_TRANS { 0.2, 0.2, 0.8, 0.5 } +#define ROYALBLUE2 { 0.2, 0.2, 0.9, 1 } #define ROYALBLUE2_LOW_TRANS { 0.2, 0.2, 0.9, 0.75 } -// Yellows +// Yellows / BROWNS #define SPRINGWOOD1 { 0.95, 0.95, 0.9, 1 } #define BROOM1_LOWER_TRANS { 1.0, 1.0, 0.1, 0.9 } - +#define PEANUT { 0.5, 0.2, 0.1, 1.0 } +#define PEANUT_MED_TRANS { 0.5, 0.2, 0.1, 0.5 } // Magentas #define MEDIUMREDVIOLET1_HIGHER_TRANS { 0.7, 0.2, 0.7, 0.1 } diff --git a/display-gtk.h b/display-gtk.h index f4961b301..879a02b4c 100644 --- a/display-gtk.h +++ b/display-gtk.h @@ -21,6 +21,12 @@ typedef struct { gboolean otu; } visible_cols_t; +typedef struct { + gboolean po2; + gboolean pn2; + gboolean phe; +} enabled_graphs_t; + typedef enum { PREF_BOOL, PREF_STRING @@ -43,6 +43,7 @@ struct plot_info { /* Depth info */ int depth; int smoothed; + double po2; velocity_t velocity; struct plot_data *min[3]; struct plot_data *max[3]; @@ -68,6 +69,9 @@ typedef enum { /* Velocity colors. Order is still important, ref VELOCITY_COLORS_START_IDX. */ VELO_STABLE, VELO_SLOW, VELO_MODERATE, VELO_FAST, VELO_CRAZY, + /* gas colors */ + PO2, PN2, PHE, + /* Other colors */ TEXT_BACKGROUND, ALERT_BG, ALERT_FG, EVENTS, SAMPLE_DEEP, SAMPLE_SHALLOW, SMOOTHED, MINUTE, TIME_GRID, TIME_TEXT, DEPTH_GRID, MEAN_DEPTH, DEPTH_TOP, @@ -99,6 +103,10 @@ static const color_t profile_color[] = { [VELO_FAST] = {{PIRATEGOLD1, BLACK1_LOW_TRANS}}, [VELO_CRAZY] = {{RED1, BLACK1_LOW_TRANS}}, + [PO2] = {{APPLE1, APPLE1_MED_TRANS}}, + [PN2] = {{ROYALBLUE2, ROYALBLUE2_LOW_TRANS}}, + [PHE] = {{PEANUT, PEANUT_MED_TRANS}}, + [TEXT_BACKGROUND] = {{CONCRETE1_LOWER_TRANS, WHITE1}}, [ALERT_BG] = {{BROOM1_LOWER_TRANS, BLACK1_LOW_TRANS}}, [ALERT_FG] = {{BLACK1_LOW_TRANS, BLACK1_LOW_TRANS}}, @@ -482,6 +490,27 @@ static void plot_depth_scale(struct graphics_context *gc, struct plot_info *pi) } } +static void plot_po2_profile(struct graphics_context *gc, struct plot_info *pi) +{ + int i; + struct plot_data *entry; + + gc->leftx = 0; + gc->rightx = get_maxtime(pi); + /* let's hope no one gets close to the top of that graph... */ + gc->topy = 3.0; gc->bottomy = 0.0; + + set_source_rgba(gc, PO2); + + entry = pi->entry; + move_to(gc, entry->sec, entry->po2); + for (i = 1; i < pi->nr; i++) { + entry++; + line_to(gc, entry->sec, entry->po2); + } + cairo_stroke(gc->cr); +} + static void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi) { int i, incr; @@ -1257,6 +1286,7 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str lastdepth = -1; for (i = 0; i < nr_samples; i++) { int depth; + double fo2, pressure; int delay = 0; struct sample *sample = dive_sample+i; @@ -1297,6 +1327,10 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str depth = entry->depth = sample->depth.mm; entry->cylinderindex = sample->cylinderindex; SENSOR_PRESSURE(entry) = sample->cylinderpressure.mbar; + pressure = (depth + 10000) / 10000.0 * 1.01325; + fo2 = dive->cylinder[sample->cylinderindex].gasmix.o2.permille / 1000.0; + entry->po2 = fo2 * pressure; + entry->temperature = sample->temperature.mkelvin; if (depth || lastdepth) @@ -1367,10 +1401,17 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str pi->entry[i].same_cylinder = 1; pi->entry[i].cylinderindex = pi->entry[i-1].cylinderindex; INTERPOLATED_PRESSURE(pi->entry + i) = GET_PRESSURE(pi->entry + i - 1); + pi->entry[i].po2 = pi->entry[i-1].po2; pi->entry[i+1].sec = sec + 40; pi->entry[i+1].same_cylinder = 1; pi->entry[i+1].cylinderindex = pi->entry[i-1].cylinderindex; INTERPOLATED_PRESSURE(pi->entry + i + 1) = GET_PRESSURE(pi->entry + i - 1); + pi->entry[i+1].po2 = pi->entry[i-1].po2; + /* make sure the first two pi entries have a sane po2 */ + if (pi->entry[1].po2 < 0.01) + pi->entry[1].po2 = pi->entry[2].po2; + if (pi->entry[0].po2 < 0.01) + pi->entry[0].po2 = pi->entry[1].po2; /* the number of actual entries - some computers have lots of * depth 0 samples at the end of a dive, we want to make sure * we have exactly one of them at the end */ @@ -1486,6 +1527,9 @@ void plot(struct graphics_context *gc, cairo_rectangle_t *drawing_area, struct d cairo_close_path(gc->cr); cairo_stroke(gc->cr); +// if (graphs_enabled.po2) + plot_po2_profile(gc, pi); + /* now shift the translation back by half the margin; * this way we can draw the vertical scales on both sides */ cairo_translate(gc->cr, -drawing_area->x / 2.0, 0); |