graph_label *add_label(v5d_info *info, gchar *str, v5d_graph_type gtype) { graph_label *label; gint cnt=1, x, y; if(info->graph_label_list){ cnt = g_list_length (info->graph_label_list )+1; } label_position(info->v5d_display_context, cnt, &x, &y); label = (graph_label *) g_malloc(sizeof(graph_label)); label->gtype = gtype; label->data = NULL; label->labelid = vis5d_make_label(info->v5d_display_context, x, y, chomp(str)); info->graph_label_list = g_list_append(info->graph_label_list, (gpointer) label); return label; }
void update_label(v5d_info *info, graph_label *label, gchar *str) { gint cnt, x, y; vis5d_delete_label(info->v5d_display_context, label->labelid); cnt = g_list_index(info->graph_label_list, label) + 1; label_position(info->v5d_display_context, cnt, &x, &y); label->labelid = vis5d_make_label(info->v5d_display_context, x, y, chomp(str)); }
void update_graph_labels(v5d_info *info) { GList *item; gint cnt=1, x, y; if(! info->graph_label_list) return; item = g_list_first(info->graph_label_list); while(item!=NULL){ label_position(info->v5d_display_context, cnt, &x, &y); vis5d_move_label(info->v5d_display_context, ((graph_label *)item->data)->labelid, x,y); item = g_list_next(item); cnt++; } }
void label_interior_position(double *x, double *y) const { // start with the default label position label_position(x,y); unsigned size = cont_.size(); // if we are not a polygon, or the default is within the polygon we are done if (size < 3 || hit_test(*x,*y,0)) return; // otherwise we find a horizontal line across the polygon and then return the // center of the widest intersection between the polygon and the line. std::vector<double> intersections; // only need to store the X as we know the y double x0=0; double y0=0; rewind(0); unsigned command = vertex(&x0, &y0); double x1,y1; while (SEG_END != (command=vertex(&x1, &y1))) { if (command != SEG_MOVETO) { // if the segments overlap if (y0==y1) { if (y0==*y) { double xi = (x0+x1)/2.0; intersections.push_back(xi); } } // if the path segment crosses the bisector else if ((y0 <= *y && y1 >= *y) || (y0 >= *y && y1 <= *y)) { // then calculate the intersection double xi = x0; if (x0 != x1) { double m = (y1-y0)/(x1-x0); double c = y0 - m*x0; xi = (*y-c)/m; } intersections.push_back(xi); } } x0 = x1; y0 = y1; } // no intersections we just return the default if (intersections.empty()) return; x0=intersections[0]; double max_width = 0; for (unsigned ii = 1; ii < intersections.size(); ++ii) { double x1=intersections[ii]; double xc=(x0+x1)/2.0; double width = fabs(x1-x0); if (width > max_width && hit_test(xc,*y,0)) { *x=xc; max_width = width; } } }