void build_example1(GtkWidget *active_plot,GtkPlotDT *data, gint num) { GdkColor color; gdouble *px1= (gdouble *)g_malloc(sizeof(gdouble)*num*3); gdouble *py1= (gdouble *)g_malloc(sizeof(gdouble)*num*3); gdouble *px2= (gdouble *)g_malloc(sizeof(gdouble)*num*3); gdouble *py2= (gdouble *)g_malloc(sizeof(gdouble)*num*3); gdouble ax,ay,bx,by,cx,cy; GtkPlotDTtriangle *t= NULL; GList *list = NULL; gint i = 0; list = data->triangles; while(list){ t = (GtkPlotDTtriangle *)list->data; ax= gtk_plot_dt_get_node(data,t->a)->x; ay= gtk_plot_dt_get_node(data,t->a)->y; bx= gtk_plot_dt_get_node(data,t->b)->x; by= gtk_plot_dt_get_node(data,t->b)->y; cx= gtk_plot_dt_get_node(data,t->c)->x; cy= gtk_plot_dt_get_node(data,t->c)->y; px1[i*3+0]= ax; py1[i*3+0]= ay; px2[i*3+0]= bx-ax; py2[i*3+0]= by-ay; px1[i*3+1]= bx; py1[i*3+1]= by; px2[i*3+1]= cx-bx; py2[i*3+1]= cy-by; px1[i*3+2]= cx; py1[i*3+2]= cy; px2[i*3+2]= ax-cx; py2[i*3+2]= ay-cy; i++; list = list->next; } fprintf(stderr,"%d triangles, %d points\n",num,num*3); dataset[0] = GTK_PLOT_DATA(gtk_plot_flux_new()); gtk_plot_add_data(GTK_PLOT(active_plot), dataset[0]); gtk_widget_show(GTK_WIDGET(dataset[0])); gtk_plot_data_set_points(dataset[0], px1, py1, px2, py2, num*3); gtk_plot_flux_center(GTK_PLOT_FLUX(dataset[0]), FALSE); gdk_color_parse("red", &color); gdk_color_alloc(gdk_colormap_get_system(), &color); gtk_plot_flux_set_arrow(GTK_PLOT_FLUX(dataset[0]), 0, 0, 0); gtk_plot_data_set_symbol(dataset[0], GTK_PLOT_SYMBOL_CIRCLE, GTK_PLOT_SYMBOL_OPAQUE, 0,1, &color, &color); gtk_plot_data_set_line_attributes(dataset[0], GTK_PLOT_LINE_NONE, 0, &color); gtk_plot_data_set_legend(dataset[0], "Delaunay triangulization"); }
void build_example1(GtkWidget *active_plot) { GdkColor color; static gdouble px1[]={0., 0.2, 0.4, 0.6, 0.8, 1.0}; static gdouble py1[]={.2, .4, .5, .35, .30, .40}; static gdouble px2[]={.12, .22, .27, .12, .052, .42}; static gdouble py2[]={.0, .05, .12, .22, .16, .1}; /* static gdouble px1[]={0., 0.2, 0.4, 0.6, 0.8, 1.0}; static gdouble py1[]={.2, .4, .5, .35, .30, .40}; static gdouble px2[]={.02, 0, -.02, 0, .052, .42}; static gdouble py2[]={.0, .05, .0, -0.02, .16, .1}; */ dataset[0] = GTK_PLOT_DATA(gtk_plot_flux_new()); gtk_plot_add_data(GTK_PLOT(active_plot), dataset[0]); gtk_widget_show(GTK_WIDGET(dataset[0])); gtk_plot_data_set_points(dataset[0], px1, py1, px2, py2, 6); gtk_plot_flux_set_size_max(GTK_PLOT_FLUX(dataset[0]), 50); gtk_plot_flux_set_scale_max(GTK_PLOT_FLUX(dataset[0]), 0.5); /* gtk_plot_flux_set_labels_prefix(GTK_PLOT_FLUX(dataset[0]), "A"); gtk_plot_flux_set_labels_suffix(GTK_PLOT_FLUX(dataset[0]), "B"); */ /* gtk_plot_flux_center(GTK_PLOT_FLUX(dataset[0]), FALSE); */ gdk_color_parse("red", &color); gdk_color_alloc(gdk_colormap_get_system(), &color); gtk_plot_data_set_symbol(dataset[0], GTK_PLOT_SYMBOL_NONE, GTK_PLOT_SYMBOL_OPAQUE, 10, 2, &color, &color); gtk_plot_data_set_line_attributes(dataset[0], GTK_PLOT_LINE_NONE, 0, 0, 1, &color); gtk_plot_data_set_legend(dataset[0], "Flux"); }
static void gtk_plot_flux_get_legend_size(GtkPlotData *data, gint *width, gint *height) { GtkPlotFlux *flux; GtkPlot *plot = NULL; GtkPlotText legend; gint lascent, ldescent, lheight, lwidth; gdouble m; gchar new_label[100], text[100]; flux = GTK_PLOT_FLUX(data); plot = data->plot; m = plot->magnification; legend = plot->legends_attr; if(data->legend) legend.text = data->legend; else legend.text = ""; *width = *height = 0; if(data->show_legend) gtk_plot_text_get_size(legend.text, legend.angle, legend.font, roundint(legend.height * m), width, height, &lascent, &ldescent); if(flux->show_scale){ gchar aux_text[100]; gtk_plot_axis_parse_label(data->gradient, flux->scale_max, flux->labels_precision, flux->labels_style, text); if(flux->labels_prefix){ g_snprintf(aux_text, 100, "%s%s", flux->labels_prefix, text); g_snprintf(text, 100, "%s", aux_text); } if(flux->labels_suffix) { g_snprintf(aux_text, 100, "%s%s", text, flux->labels_suffix); g_snprintf(text, 100, "%s", aux_text); } g_snprintf(new_label, 100, "%s", text); legend.text = new_label; gtk_plot_text_get_size(legend.text, 0, legend.font, roundint(legend.height * m), &lwidth, &lheight, &lascent, &ldescent); *width = MAX(*width, lwidth + roundint(m*(flux->size_max + 8))); *height += MAX(lheight , roundint(m*flux->arrow_width)); } }
static void gtk_plot_flux_destroy(GtkObject *object) { GtkPlotFlux *flux = GTK_PLOT_FLUX(object); if(flux->labels_prefix) g_free(flux->labels_prefix); flux->labels_prefix = NULL; if(flux->labels_suffix) g_free(flux->labels_suffix); flux->labels_suffix = NULL; if (GTK_OBJECT_CLASS (parent_class)->destroy) (*GTK_OBJECT_CLASS (parent_class)->destroy) (object); }
static void gtk_plot_flux_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GtkPlotFlux *data; data = GTK_PLOT_FLUX (object); switch (prop_id) { case ARG_CENTERED: g_value_set_boolean(value, data->centered); break; case ARG_WIDTH: g_value_set_int(value, data->arrow_width); break; case ARG_LENGTH: g_value_set_int(value, data->arrow_length); break; case ARG_STYLE: g_value_set_int(value, data->arrow_style); break; case ARG_SCALE_MAX: g_value_set_double(value, data->scale_max); break; case ARG_SIZE_MAX: g_value_set_int(value, data->size_max); break; case ARG_SHOW_SCALE: g_value_set_boolean(value, data->show_scale); break; case ARG_LABEL_PRECISION: g_value_set_int(value, data->labels_precision); break; case ARG_LABEL_STYLE: g_value_set_int(value, data->labels_style); break; case ARG_LABEL_PREFIX: g_value_set_string(value, data->labels_prefix); break; case ARG_LABEL_SUFFIX: g_value_set_string(value, data->labels_suffix); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void gtk_plot_flux_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GtkPlotFlux *data; data = GTK_PLOT_FLUX (object); switch (prop_id) { case ARG_CENTERED: data->centered = g_value_get_boolean(value); break; case ARG_WIDTH: data->arrow_width = g_value_get_int(value); break; case ARG_LENGTH: data->arrow_length = g_value_get_int(value); break; case ARG_STYLE: data->arrow_style = g_value_get_int(value); break; case ARG_SCALE_MAX: data->scale_max = g_value_get_double(value); break; case ARG_SIZE_MAX: data->size_max = g_value_get_int(value); break; case ARG_SHOW_SCALE: data->show_scale = g_value_get_boolean(value); break; case ARG_LABEL_PRECISION: data->labels_precision = g_value_get_int(value); break; case ARG_LABEL_STYLE: data->labels_style = g_value_get_int(value); break; case ARG_LABEL_PREFIX: gtk_plot_flux_set_labels_prefix(data, g_value_get_string(value)); break; case ARG_LABEL_SUFFIX: gtk_plot_flux_set_labels_suffix(data, g_value_get_string(value)); break; } }
static void gtk_plot_flux_draw_legend(GtkPlotData *data, gint x, gint y) { GtkPlotFlux *flux; GtkPlot *plot = NULL; GtkPlotText legend; GdkRectangle area; gint lascent, ldescent, lheight, lwidth; gdouble m; gboolean centered; GtkAllocation allocation; flux = GTK_PLOT_FLUX(data); centered = flux->centered; g_return_if_fail(data->plot != NULL); g_return_if_fail(GTK_IS_PLOT(data->plot)); g_return_if_fail(gtk_widget_get_visible(GTK_WIDGET(data->plot))); plot = data->plot; gtk_widget_get_allocation( GTK_WIDGET(plot), &allocation); area.x = allocation.x; area.y = allocation.y; area.width = allocation.width; area.height = allocation.height; m = plot->magnification; legend = plot->legends_attr; if(data->legend) legend.text = data->legend; else legend.text = ""; gtk_plot_text_get_size(legend.text, legend.angle, legend.font, roundint(legend.height * m), &lwidth, &lheight, &lascent, &ldescent); if(data->show_legend){ legend.x = (gdouble)(area.x + x) / (gdouble)area.width; legend.y = (gdouble)(area.y + y + lascent) / (gdouble)area.height; gtk_plot_draw_text(plot, legend); } if(flux->show_scale){ gchar new_label[100], text_max[100]; flux->centered = FALSE; gtk_plot_flux_draw_arrow(flux, area.x + x, area.y + y + lheight * 3 / 2, area.x + x + roundint(flux->size_max*m), area.y + y + lheight * 3 / 2); y += MAX(lheight, roundint(m*flux->arrow_width)); gtk_plot_axis_parse_label(data->gradient, flux->scale_max, flux->labels_precision, flux->labels_style, text_max); if(flux->labels_prefix){ gchar aux_text[100]; g_snprintf(aux_text, 100, "%s%s", flux->labels_prefix, text_max); g_snprintf(text_max, 100, "%s", aux_text); } if(flux->labels_suffix){ gchar aux_text[100]; g_snprintf(aux_text, 100, "%s%s", text_max, flux->labels_suffix); g_snprintf(text_max, 100, "%s", aux_text); } g_snprintf(new_label, 100, "%s", text_max); legend.x = (gdouble)(area.x + x + m*(flux->size_max + 4)) / (gdouble)area.width; legend.y = (gdouble)(area.y + y + lascent) / (gdouble)area.height; legend.text = new_label; gtk_plot_draw_text(plot, legend); flux->centered = centered; y += lheight; } else y += lheight; }
static void gtk_plot_flux_draw_symbol(GtkPlotData *dataset, gdouble x, gdouble y, gdouble z, gdouble a, gdouble dx, gdouble dy, gdouble dz, gdouble da) { GtkPlot *plot; GtkPlotFlux *flux = NULL; //GdkRectangle area; //, clip_area; gdouble m; gdouble x1 = 0.0, y1 = 0.0, x2 = 0.0, y2=0.0; gdouble factor, size, xm; GtkAllocation allocation; g_return_if_fail(GTK_IS_PLOT_FLUX(dataset)); flux = GTK_PLOT_FLUX(dataset); g_return_if_fail(dataset->plot != NULL); g_return_if_fail(gtk_widget_get_visible(GTK_WIDGET(dataset->plot))); plot = dataset->plot; m = plot->magnification; gtk_widget_get_allocation( GTK_WIDGET(plot), &allocation); //area.x = allocation.x; //area.y = allocation.y; //area.width = allocation.width; //area.height = allocation.height; /* clip_area.x = area.x + roundint(plot->x * area.width); clip_area.y = area.y + roundint(plot->y * area.height); clip_area.width = roundint(plot->width * area.width); clip_area.height = roundint(plot->height * area.height); gtk_plot_pc_clip(plot->pc, &clip_area); */ if(GTK_IS_PLOT3D(plot)){ gdouble z1; xm = sqrt(dx * dx + dy * dy + dz * dz); factor = xm / flux->scale_max; size = factor * flux->size_max; x2 = size * dx / xm; y2 = size * dy / xm; gtk_plot3d_get_pixel(GTK_PLOT3D(plot), x, y, z, &x1, &y1, &z1); }else{ if(plot->clip_data && (x < plot->xmin || x > plot->xmax || y < plot->ymin || y > plot->ymax)) return; xm = sqrt(dx * dx + dy * dy); factor = xm / flux->scale_max; size = factor * flux->size_max; gtk_plot_get_pixel(plot, x, y, &x1, &y1); if (xm > 0.0) { x2 = size * dx / xm; y2 = size * dy / xm; /* check for NaN */ if (x2 == x2 && y2 == y2) gtk_plot_flux_draw_arrow (flux, x1, y1, x1+x2*m, y1-y2*m); } gtk_plot_data_draw_symbol(dataset, x1, y1); } /* gtk_plot_pc_clip(plot->pc, NULL); */ }