aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2022-12-14 16:54:55 +0100
committerThomas White <taw@physics.org>2022-12-14 16:54:55 +0100
commita6af38df02e736e10f02e7bcfd9fb0bf6f28b42a (patch)
treec1b0eed9dfb12deb02d12b18c79f18d313578a57
parentcfcf9bd5f8f392caa693639303b36ae5c1f92d76 (diff)
GUI: FoM graph, part 5: use in FoM dialog
-rw-r--r--src/crystfelfomgraph.c66
-rw-r--r--src/gui_fom.c22
2 files changed, 46 insertions, 42 deletions
diff --git a/src/crystfelfomgraph.c b/src/crystfelfomgraph.c
index 43ea6560..57a34295 100644
--- a/src/crystfelfomgraph.c
+++ b/src/crystfelfomgraph.c
@@ -123,7 +123,8 @@ static void fom_range(enum fom_type t, double *min, double *max)
static void draw_x_axis(cairo_t *cr, double *tics, int n_tics,
- double x1, double x2, double ox, double w, double axsp)
+ double x1, double x2, double ox, double w, double h,
+ double axsp)
{
int i;
@@ -143,7 +144,7 @@ static void draw_x_axis(cairo_t *cr, double *tics, int n_tics,
x = ox + (w-ox) * (1e10/tics[i]-x1)/(x2-x1);
- cairo_move_to(cr, x, axsp);
+ cairo_move_to(cr, x, h);
cairo_line_to(cr, x, axsp-5.0);
cairo_set_line_width(cr, 1.0);
cairo_stroke(cr);
@@ -199,7 +200,7 @@ static void draw_y_axis(cairo_t *cr, double h, double oy,
cairo_save(cr);
cairo_text_extents(cr, name, &ext);
- cairo_move_to(cr, -ext.height-3.0, oy+(h-oy+ext.x_advance)/2.0);
+ cairo_move_to(cr, -ext.height-30.0, oy+(h-oy+ext.x_advance)/2.0);
cairo_scale(cr, 1.0, -1.0);
cairo_rotate(cr, M_PI_2);
cairo_show_text(cr, name);
@@ -217,11 +218,16 @@ static gint draw_sig(GtkWidget *window, cairo_t *cr, CrystFELFoMGraph *fg)
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
cairo_paint(cr);
+ if ( fg->n_foms == 0 ) {
+ cairo_restore(cr);
+ return FALSE;
+ }
+
double border = 10.0;
double w = fg->visible_width;
double h = fg->visible_height;
double axsp = 20.0; /* Vertical space for x-axis labels */
- double yaxsp = 30.0; /* Horizontal space for y-axis labels */
+ double yaxsp = 50.0; /* Horizontal space for y-axis labels */
double x1 = fg->shell_centers[0];
double x2 = fg->shell_centers[fg->n_shells-1];
@@ -254,23 +260,41 @@ static gint draw_sig(GtkWidget *window, cairo_t *cr, CrystFELFoMGraph *fg)
double tics[] = {20.0, 15.0, 10.0, 5.0, 4.0, 3.0, 2.5, 2.0, 1.7, 1.5,
1.4, 1.3, 1.2, 1.1, 1.0};
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
- draw_x_axis(cr, tics, 15, x1, x2, ox, w, axsp);
-
- //for ( j=0; j<fg->n_foms; j++ ) {
- // int i;
- // double col[3];
- // cairo_new_path(cr);
- // cairo_move_to(cr, aw*fg->shell_centers[0]/mx,
- // ah*fg->fom_values[j][0]/my);
- // for ( i=1; i<fg->n_shells; i++ ) {
- // cairo_line_to(cr, aw*fg->shell_centers[i]/mx,
- // ah*fg->fom_values[j][i]/my);
- // }
- // cairo_set_line_width(cr, 1.0);
- // fom_colour(fg->fom_types[j], col);
- // cairo_set_source_rgb(cr, col[0], col[1], col[2]);
- // cairo_stroke(cr);
- //}
+ draw_x_axis(cr, tics, 15, x1, x2, ox, w, h, axsp);
+
+ cairo_translate(cr, ox, axsp);
+ w -= ox;
+ h -= axsp;
+ cairo_rectangle(cr, 0, 0, w, h);
+ cairo_set_source_rgba(cr, 0.9, 0.9, 0.9, 0.9);
+ cairo_clip_preserve(cr);
+ cairo_fill(cr);
+ for ( j=0; j<fg->n_foms; j++ ) {
+ int i;
+ double col[3];
+ double y1, y2;
+ int split = 1;
+ fom_range(fg->fom_types[j], &y1, &y2);
+ for ( i=0; i<fg->n_shells; i++ ) {
+ double fv = fg->fom_values[j][i];
+ if ( !isnan(fv) ) {
+ if ( split ) {
+ cairo_move_to(cr, w*(fg->shell_centers[i]-x1)/(x2-x1),
+ h*(fv-y1)/(y2-y1));
+ split = 0;
+ } else {
+ cairo_line_to(cr, w*(fg->shell_centers[i]-x1)/(x2-x1),
+ h*(fv-y1)/(y2-y1));
+ }
+ } else {
+ split = 1;
+ }
+ }
+ cairo_set_line_width(cr, 1.0);
+ fom_colour(fg->fom_types[j], col);
+ cairo_set_source_rgb(cr, col[0], col[1], col[2]);
+ cairo_stroke(cr);
+ }
cairo_restore(cr);
diff --git a/src/gui_fom.c b/src/gui_fom.c
index 37a8bf52..b2b1e1a4 100644
--- a/src/gui_fom.c
+++ b/src/gui_fom.c
@@ -94,25 +94,6 @@ static int anomalous_foms_selected(struct fom_window *f)
}
-static void show_fom(enum fom_type fom,
- struct fom_context *fctx,
- struct fom_shells *shells)
-{
- int i;
-
- STATUS("Overall %s: %f (%i reflections)\n",
- fom_name(fom), fom_overall_value(fctx),
- fom_overall_num_reflections(fctx));
- STATUS("%10s %10s %10s\n", "1/d / nm^-1", fom_name(fom), "num refl");
- for ( i=0; i<shells->nshells; i++ ) {
- STATUS("%10f %10f %10i\n",
- fom_shell_centre(shells, i)/1e9,
- fom_shell_value(fctx, i),
- fom_shell_num_reflections(fctx, i));
- }
-}
-
-
static double *make_shell_centers(struct fom_shells *shells)
{
int i;
@@ -439,7 +420,6 @@ static void fom_response_sig(GtkWidget *dialog, gint resp,
f->fom_types[fom], f->dataset_names[ds]);
continue;
}
- show_fom(f->fom_types[fom], fctx, shells);
fom_types[fomi] = f->fom_types[fom];
fom_values[fomi] = make_fom_vals(fctx, shells);
@@ -689,7 +669,7 @@ gint fom_sig(GtkWidget *widget, struct crystfelproject *proj)
vbox = gtk_vbox_new(FALSE, 0.0);
content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- gtk_container_add(GTK_CONTAINER(content_area), vbox);
+ gtk_box_pack_start(GTK_BOX(content_area), GTK_WIDGET(vbox), TRUE, TRUE, 0.0);
gtk_container_set_border_width(GTK_CONTAINER(content_area), 8);
hbox = gtk_hbox_new(FALSE, 0.0);