static void filter(GwyGraph *graph) { GwyContainer *data; GwyGraphCurveModel *cmodel, *cmodelnew; GwyGraphModel *model; const gdouble *xdata, *ydata; gdouble *newydata; gint i, ncurves, ndata; GQuark quark; gwy_app_data_browser_get_current(GWY_APP_CONTAINER, &data, GWY_APP_GRAPH_MODEL_KEY, &quark, 0); gwy_app_undo_qcheckpointv(data, 1, &quark); model = gwy_graph_get_model(graph); ncurves = gwy_graph_model_get_n_curves(model); for (i = 0; i < ncurves; i++) { cmodel = gwy_graph_model_get_curve(model, i); cmodelnew = gwy_graph_curve_model_new_alike(cmodel); xdata = gwy_graph_curve_model_get_xdata(cmodel); ydata = gwy_graph_curve_model_get_ydata(cmodel); ndata = gwy_graph_curve_model_get_ndata(cmodel); newydata = g_new(gdouble, ndata); filter_do(ydata, newydata, ndata); gwy_graph_curve_model_set_data(cmodelnew, xdata, newydata, ndata); g_free(newydata); gwy_graph_model_remove_curve(gwy_graph_get_model(graph), i); gwy_graph_model_add_curve(model, cmodelnew); g_object_unref(cmodelnew); } }
static void render_data(GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer data) { GwyGraphData *graph_data = GWY_GRAPH_DATA(data); const GwyGraphDataCurve *curve; const gdouble *d; gchar buffer[32]; gint id, row; id = GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(column), quark_id)); /* Be fault-tolerant */ if (!graph_data->graph_model || id >= graph_data->curves->len) return; curve = &g_array_index(graph_data->curves, GwyGraphDataCurve, id); gtk_tree_model_get(model, iter, 0, &row, -1); if (row >= gwy_graph_curve_model_get_ndata(curve->gcmodel)) { g_object_set(renderer, "text", "", NULL); return; } if (g_object_get_qdata(G_OBJECT(renderer), quark_id)) d = gwy_graph_curve_model_get_ydata(curve->gcmodel); else d = gwy_graph_curve_model_get_xdata(curve->gcmodel); /* TODO: improve formatting using some value format (may be hard to do * for all value range) */ g_snprintf(buffer, sizeof(buffer), "%g", d[row]); g_object_set(renderer, "text", buffer, NULL); }
static void zoom_in_changed(EntropyControls *controls, GtkToggleButton *check) { GwyGraphModel *gmodel = gwy_graph_get_model(GWY_GRAPH(controls->graph)); GwyGraphCurveModel *gcmodel; const gdouble *xdata, *ydata; gdouble S; guint ndata, i; g_object_set(gmodel, "x-min-set", FALSE, "x-max-set", FALSE, "y-min-set", FALSE, "y-max-set", FALSE, NULL); if (!(controls->args->zoom_in = gtk_toggle_button_get_active(check)) || (gwy_graph_model_get_n_curves(gmodel) < 2)) { return; } gcmodel = gwy_graph_model_get_curve(gmodel, 1); ydata = gwy_graph_curve_model_get_ydata(gcmodel); S = ydata[0]; gcmodel = gwy_graph_model_get_curve(gmodel, 0); ndata = gwy_graph_curve_model_get_ndata(gcmodel); if (ndata < 5) return; xdata = gwy_graph_curve_model_get_xdata(gcmodel); ydata = gwy_graph_curve_model_get_ydata(gcmodel); for (i = 1; i+1 < ndata; i++) { if (ydata[i] > S - G_LN2) { g_object_set(gmodel, "x-min", xdata[i-1], "x-min-set", TRUE, "y-min", ydata[i-1], "y-min-set", TRUE, NULL); break; } } for (i = ndata-2; i; i--) { if (ydata[i] < S + G_LN2) { g_object_set(gmodel, "x-max", xdata[i+1], "x-max-set", TRUE, "y-max", ydata[i+1], "y-max-set", TRUE, NULL); break; } } }