summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2013-02-25 03:36:02 -0500
committerSøren Sandmann Pedersen <ssp@redhat.com>2013-02-25 03:36:02 -0500
commit2f1a42fb481b8e44dccbd528cdee24693ca2abab (patch)
treef4a1a9935db969e5d61dd2ad4c3dfb2a40d36150
parentca87394636ad098ed9391a3ec31e29002a474e6f (diff)
Treat single deaths as clustersHEADmaster
-rw-r--r--clusters.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/clusters.c b/clusters.c
index e5ccc69..25cd091 100644
--- a/clusters.c
+++ b/clusters.c
@@ -18,15 +18,15 @@ sample_exp (double lambda)
#define TRUE 1
#define WIDTH 12000
-#define HEIGHT 20
+#define HEIGHT 25
#define N_YEARS 20
#define DEATHS_PER_YEAR 7
#define BG_COLOR 1, 1, 1
-#define CLUSTER_WIDTH 16.0
+#define CLUSTER_WIDTH 20.0
#define CLUSTER_COLOR 0.2, 0.5, 0.3, 0.4
-#define LINE_WIDTH 2.0
-#define LINE_COLOR 0.0, 0.0, 0.0
+#define LINE_WIDTH 1.0
+#define LINE_COLOR 0, 0, 0
#define DEATH_WIDTH 1.0
#define DEATH_COLOR 0.0, 0.0, 0.0
#define DEATH_HEIGHT (CLUSTER_WIDTH / HEIGHT)
@@ -78,38 +78,37 @@ main ()
cairo_set_source_rgb (cr, BG_COLOR);
cairo_paint (cr);
-
- cairo_move_to (cr, 0.0, y);
- in_cluster = 0;
- for (i = 1; i < n_deaths; ++i)
+ cairo_save (cr);
+ cairo_move_to (cr, (deaths[0] / N_YEARS) * WIDTH, y);
+
+ for (i = 1; i < n_deaths + 1; ++i)
{
double d0 = deaths[i - 1];
- double d1 = deaths[i];
+ double d1 = i < n_deaths? deaths[i] : 0.0;
double x1 = (d1 / N_YEARS) * WIDTH;
- if (!in_cluster && d1 - d0 <= 1.0 / DEATHS_PER_YEAR)
- {
- cluster_x0 = (d0 / N_YEARS) * WIDTH;
- in_cluster = 1;
- }
- if (in_cluster && d1 - d0 > 1.0 / DEATHS_PER_YEAR)
+ if (d1 - d0 > 1.0 / DEATHS_PER_YEAR || i == n_deaths)
{
double x1 = (d0 / N_YEARS) * WIDTH;
-
- cairo_save (cr);
- cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
- cairo_move_to (cr, cluster_x0, y);
- cairo_line_to (cr, x1, y);
+ double x2 = (d1 / N_YEARS) * WIDTH;
+
+ /* 0 length lines don't get square caps because
+ * cairo would have to invent an orientation for
+ * them. So add 0.002 to make sure the line has
+ * a length.
+ */
+ cairo_line_to (cr, x1 + 0.002, y);
cairo_set_line_width (cr, CLUSTER_WIDTH);
cairo_set_source_rgba (cr, CLUSTER_COLOR);
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
cairo_stroke (cr);
- cairo_restore (cr);
-
- in_cluster = 0;
+ cairo_move_to (cr, x2 - 0.002, y);
}
}
-
+
+ cairo_restore (cr);
+
for (i = 1; i < n_deaths; ++i)
{
double d0 = deaths[i - 1];