summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-09-06 12:36:52 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-09-06 12:36:52 -0700
commite88695ff72606d1556ff0e6e1423d3b6a5a1e9d8 (patch)
tree8c05a02b7adbca1146ac8ed309b7cf622018f7f4
parentc0a429457ab9fae5e6995777b869b111ef32be74 (diff)
downloadsubsurface-e88695ff72606d1556ff0e6e1423d3b6a5a1e9d8.tar.gz
Do cylinder pressure plot first, then depth, then text notes
Text notes need to be last, so that they don't get stepped on by the other graph elements. Also, separate the depth text plot out into a function of its own. Tidier that way. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--profile.c60
1 files changed, 37 insertions, 23 deletions
diff --git a/profile.c b/profile.c
index 52dc82beb..f10e856c2 100644
--- a/profile.c
+++ b/profile.c
@@ -108,14 +108,43 @@ static int next_minmax(struct dive *dive, int index, int minmax)
/* Scale to 0,0 -> maxx,maxy */
#define SCALE(x,y) (x)*maxx/scalex+topx,(y)*maxy/scaley+topy
-static void plot_profile(struct dive *dive, cairo_t *cr,
+static void plot_depth_text(struct dive *dive, cairo_t *cr,
+ double topx, double topy, double maxx, double maxy)
+{
+ double scalex, scaley;
+ int maxtime, maxdepth;
+ int i;
+
+ /* Get plot scaling limits */
+ maxtime = round_seconds_up(dive->duration.seconds);
+ maxdepth = round_feet_up(to_feet(dive->maxdepth));
+
+ scalex = maxtime;
+ scaley = maxdepth;
+
+ cairo_set_font_size(cr, 14);
+ cairo_set_source_rgb(cr, 1, 0.2, 0.2);
+ i = 0;
+ while ((i = next_minmax(dive, i, 1)) != 0) {
+ 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);
+ i = next_minmax(dive, i, 0);
+ if (!i)
+ break;
+ }
+}
+
+static void plot_depth_profile(struct dive *dive, cairo_t *cr,
double topx, double topy, double maxx, double maxy)
{
double scalex, scaley;
int begins, sec, depth;
int i, samples;
struct sample *sample;
- int maxtime, maxdepth, mindepth;
+ int maxtime, maxdepth;
samples = dive->samples;
if (!samples)
@@ -171,24 +200,6 @@ static void plot_profile(struct dive *dive, cairo_t *cr,
cairo_fill_preserve(cr);
cairo_set_source_rgba(cr, 1, 0.2, 0.2, 0.80);
cairo_stroke(cr);
-
- scalex = maxtime;
- scaley = maxdepth;
-
- maxdepth = mindepth = 0;
- maxtime = 0;
- cairo_set_font_size(cr, 14);
- cairo_set_source_rgb(cr, 1, 0.2, 0.2);
- i = 0;
- while ((i = next_minmax(dive, i, 1)) != 0) {
- sample = dive->sample+i;
- sec = sample->time.seconds;
- depth = to_feet(sample->depth);
- plot_text(cr, SCALE(sec, depth), "%d ft", depth);
- i = next_minmax(dive, i, 0);
- if (!i)
- break;
- }
}
static int get_cylinder_pressure_range(struct dive *dive, double *scalex, double *scaley)
@@ -262,11 +273,14 @@ static void plot(cairo_t *cr, int w, int h, struct dive *dive)
maxx = (w - 2*topx);
maxy = (h - 2*topy);
+ /* Cylinder pressure plot */
+ plot_cylinder_pressure(dive, cr, topx, topy, maxx, maxy);
+
/* Depth profile */
- plot_profile(dive, cr, topx, topy, maxx, maxy);
+ plot_depth_profile(dive, cr, topx, topy, maxx, maxy);
- /* Cylinder pressure plot? */
- plot_cylinder_pressure(dive, cr, topx, topy, maxx, maxy);
+ /* Text on top of all graphs.. */
+ plot_depth_text(dive, cr, topx, topy, maxx, maxy);
/* Bounding box last */
scalex = scaley = 1.0;