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_polar_draw_circle(GtkPlotPolar *polar) { GtkWidget *widget; GtkPlot *plot; GtkPlotAxis *axis, perp; GtkPlotText tick; gchar label[100]; gdouble x, y; gint line_width; gdouble xp, yp, width, height, size; gint ntick; gdouble m; gdouble x_tick = 0.; gdouble x1, y1; gdouble ox, oy; gint text_height, text_width, ascent, descent; gdouble rotation; gboolean veto = FALSE; gint sign = 1; GtkAllocation allocation; widget = GTK_WIDGET(polar); plot = GTK_PLOT(polar); m = plot->magnification; rotation = polar->rotation; if(plot->reflect_y) sign = -1; xp = plot->internal_allocation.x; yp = plot->internal_allocation.y; width = plot->internal_allocation.width; height = plot->internal_allocation.height; ox = width / 2.; oy = height / 2.; x = xp + ox; y = yp + oy; axis = plot->bottom; line_width = axis->line.line_width; gtk_plot_pc_set_color(plot->pc, &axis->line.color); gtk_plot_pc_set_lineattr(plot->pc, axis->line.line_width, 0, 3, 0); gtk_plot_get_pixel(plot, plot->ymax, 90.0 - rotation, &x1, &size); size = fabs(size - y); gtk_plot_pc_draw_circle (plot->pc, FALSE, x, y, 2 * size); gtk_plot_pc_set_lineattr(plot->pc, axis->ticks_width, 0, 1, 0); gtk_plot_text_get_size("0", 0, axis->labels_attr.font, roundint(axis->labels_attr.height * m), &text_width, &text_height, &ascent, &descent); for(ntick = 0; ntick < axis->ticks.nticks; ntick++){ x_tick = axis->ticks.values[ntick].value; if(!axis->ticks.values[ntick].minor && x_tick >= axis->ticks.min){ if(!axis->custom_labels){ gtk_plot_axis_parse_label(axis, x_tick, axis->label_precision, axis->label_style, label); } else { g_signal_emit_by_name(GTK_OBJECT(axis), "tick_label", &x_tick, label, &veto); if(!veto) gtk_plot_axis_parse_label(axis, x_tick, axis->label_precision, axis->label_style, label); } gtk_plot_get_pixel(plot, plot->ymax, x_tick, &x1, &y1); x_tick += rotation; if(axis->major_mask & GTK_PLOT_TICKS_IN){ perp.direction.x = cos(x_tick * PI / 180. * sign); perp.direction.y = -sin(x_tick * PI / 180. * sign); gtk_plot_pc_draw_line(plot->pc, x1, y1, x1 + perp.direction.x*m*axis->ticks_length, y1 + perp.direction.y*m*axis->ticks_length); } if(axis->major_mask & GTK_PLOT_TICKS_OUT){ perp.direction.x = -cos(x_tick * PI / 180. * sign); perp.direction.y = sin(x_tick * PI / 180. * sign); gtk_plot_pc_draw_line(plot->pc, x1, y1, x1 - perp.direction.x*m*axis->ticks_length, y1 - perp.direction.y*m*axis->ticks_length); } tick = axis->labels_attr; tick.text = label; if((x_tick >= 0.0 && x_tick < 90.0) || (x_tick > 270.0 && x_tick <= 360.0)) tick.justification = GTK_JUSTIFY_LEFT; if(x_tick > 90.0 && x_tick < 270.0) tick.justification = GTK_JUSTIFY_RIGHT; if(x_tick == 90.0 || x_tick == 270.0) tick.justification = GTK_JUSTIFY_CENTER; y1 += text_height / 2; if((x_tick - rotation) != 360.0 && axis->label_mask != 0){ gtk_widget_get_allocation (widget, &allocation); perp.direction.x = -cos(x_tick * PI / 180. * sign); perp.direction.y = sin(x_tick * PI / 180. * sign); tick.x = x1; tick.y = y1; tick.x -= roundint(perp.direction.x*axis->labels_offset * m); tick.y -= roundint(perp.direction.y*axis->labels_offset * m); tick.x = (gdouble)tick.x / (gdouble)allocation.width; tick.y = (gdouble)tick.y / (gdouble)allocation.height; gtk_plot_draw_text(plot, tick); } } if(axis->ticks.values[ntick].minor && x_tick >= axis->ticks.min){ gtk_plot_get_pixel(plot, plot->ymax, x_tick, &x1, &y1); x_tick += rotation; if(axis->minor_mask & GTK_PLOT_TICKS_IN){ perp.direction.x = cos(x_tick * PI / 180. * sign); perp.direction.y = -sin(x_tick * PI / 180. * sign); gtk_plot_pc_draw_line(plot->pc, x1, y1, x1 + perp.direction.x*m*axis->ticks_length/2., y1 + perp.direction.y*m*axis->ticks_length/2.); } if(axis->minor_mask & GTK_PLOT_TICKS_OUT){ perp.direction.x = -cos(x_tick * PI / 180. * sign); perp.direction.y = sin(x_tick * PI / 180. * sign); gtk_plot_pc_draw_line(plot->pc, x1, y1, x1 - perp.direction.x*m*axis->ticks_length/2., y1 - perp.direction.y*m*axis->ticks_length/2.); } } } }
static void gtk_plot_polar_draw_labels(GtkPlotPolar *polar, GtkPlotAxis *axis, GtkPlotVector tick_direction) { GtkWidget *widget; GtkPlot *plot; GtkPlotText title, tick; gchar label[100]; gdouble x_tick; gint x, y; gdouble xx, yy; gint ox, oy; gint text_height, text_width, ascent, descent; gint xp, yp, width, height; gint ntick; gdouble m; gboolean veto = FALSE; gdouble x0, y0; GtkAllocation allocation; widget = GTK_WIDGET(polar); plot = GTK_PLOT(polar); m = plot->magnification; xp = plot->internal_allocation.x; yp = plot->internal_allocation.y; width = plot->internal_allocation.width; height = plot->internal_allocation.height; ox = width / 2.; oy = height / 2.; x = xp + ox * axis->direction.x + axis->origin.x; y = yp + oy * axis->direction.y + axis->origin.y; gtk_plot_pc_set_color(plot->pc, &axis->labels_attr.fg); gtk_plot_text_get_size("0", 0, axis->labels_attr.font, roundint(axis->labels_attr.height * m), &text_width, &text_height, &ascent, &descent); switch(axis->labels_attr.angle){ case 0: y += text_height / 2.; break; case 90: break; case 180: y -= text_height / 2.; break; case 270: break; } if(axis->direction.x == 0) gtk_plot_get_pixel(plot, 0, -polar->rotation+90, &x0, &y0); else gtk_plot_get_pixel(plot, 0, -polar->rotation, &y0, &x0); tick = axis->labels_attr; for(ntick = 0; ntick < axis->ticks.nticks; ntick++){ if(axis->ticks.values[ntick].minor) continue; x_tick = axis->ticks.values[ntick].value; if(axis->direction.x == 0) gtk_plot_get_pixel(plot, x_tick, -polar->rotation+90, &xx, &yy); else gtk_plot_get_pixel(plot, x_tick, -polar->rotation, &yy, &xx); yy = yy - y0; xx = axis->direction.x * yy; yy = axis->direction.y * yy; if(x_tick >= axis->ticks.min-1.e-9){ if(!axis->custom_labels){ gtk_plot_axis_parse_label(axis, x_tick, axis->label_precision, axis->label_style, label); } else { g_signal_emit_by_name(GTK_OBJECT(axis), "tick_label", &x_tick, label, &veto); if(!veto) gtk_plot_axis_parse_label(axis, x_tick, axis->label_precision, axis->label_style, label); } tick.text = label; gtk_widget_get_allocation (widget, &allocation); if(axis->label_mask & GTK_PLOT_LABEL_IN){ tick.x = x + xx; tick.y = y + yy; tick.x = tick.x + tick_direction.x*roundint(axis->labels_offset * m); tick.y = tick.y + tick_direction.y*roundint(axis->labels_offset * m); tick.x = (gdouble)tick.x / (gdouble)allocation.width; tick.y = (gdouble)tick.y / (gdouble)allocation.height; gtk_plot_draw_text(plot, tick); tick.x = x - xx; tick.y = y - yy; tick.x = tick.x + tick_direction.x*roundint(axis->labels_offset * m); tick.y = tick.y + tick_direction.y*roundint(axis->labels_offset * m); tick.x = (gdouble)tick.x / (gdouble)allocation.width; tick.y = (gdouble)tick.y / (gdouble)allocation.height; gtk_plot_draw_text(plot, tick); } if(axis->label_mask & GTK_PLOT_LABEL_OUT){ tick.x = x + xx; tick.y = y + yy; tick.x = tick.x - tick_direction.x*roundint(axis->labels_offset * m); tick.y = tick.y - tick_direction.y*roundint(axis->labels_offset * m); tick.x = (gdouble)tick.x / (gdouble)allocation.width; tick.y = (gdouble)tick.y / (gdouble)allocation.height; gtk_plot_draw_text(plot, tick); tick.x = x - xx; tick.y = y - yy; tick.x = tick.x - tick_direction.x*roundint(axis->labels_offset * m); tick.y = tick.y - tick_direction.y*roundint(axis->labels_offset * m); tick.x = (gdouble)tick.x / (gdouble)allocation.width; tick.y = (gdouble)tick.y / (gdouble)allocation.height; gtk_plot_draw_text(plot, tick); } } } if(axis->title_visible && axis->title.text) { title = axis->title; gtk_plot_draw_text(plot, title); } }
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; }