static void gtk_plot_gdk_set_lineattr (GtkPlotPC *pc, gfloat line_width, GdkLineStyle line_style, GdkCapStyle cap_style, GdkJoinStyle join_style) { if(!GTK_PLOT_GDK(pc)->gc) return; gdk_gc_set_line_attributes(GTK_PLOT_GDK(pc)->gc, roundint(line_width), line_style, cap_style, join_style); }
static void gtk_plot_gdk_draw_polygon (GtkPlotPC *pc, gint filled, GtkPlotPoint *points, gint numpoints) { GdkPoint *p = NULL; gint i; if(!GTK_PLOT_GDK(pc)->gc) return; if(!GTK_PLOT_GDK(pc)->drawable) return; p = (GdkPoint *)g_malloc(numpoints * sizeof(GdkPoint)); for(i = 0; i < numpoints; i++){ p[i].x = roundint(points[i].x); p[i].y = roundint(points[i].y); } gdk_draw_polygon(GTK_PLOT_GDK(pc)->drawable, GTK_PLOT_GDK(pc)->gc, filled, p, numpoints); g_free(p); }
static void gtk_plot_canvas_rectangle_draw (GtkPlotCanvas *canvas, GtkPlotCanvasChild *child) { GtkPlotCanvasRectangle *rectangle = GTK_PLOT_CANVAS_RECTANGLE(child); gint width = child->allocation.width; gint height = child->allocation.height; gdouble m = canvas->magnification; if(width == 0 && height == 0) return; if(rectangle->filled){ gtk_plot_pc_set_color(canvas->pc, &rectangle->bg); gtk_plot_pc_draw_rectangle(canvas->pc, TRUE, child->allocation.x, child->allocation.y, width, height); } if(rectangle->line.line_style != GTK_PLOT_LINE_NONE && rectangle->border != GTK_PLOT_BORDER_NONE){ gtk_plot_canvas_set_line_attributes(canvas, rectangle->line); gtk_plot_pc_draw_rectangle(canvas->pc, FALSE, child->allocation.x, child->allocation.y, width, height); if(rectangle->border == GTK_PLOT_BORDER_SHADOW){ gtk_plot_pc_draw_rectangle(canvas->pc, TRUE, child->allocation.x + roundint(rectangle->shadow_width * m), child->allocation.y + height, width, roundint(rectangle->shadow_width * m)); gtk_plot_pc_draw_rectangle(canvas->pc, TRUE, child->allocation.x + width, child->allocation.y + roundint(rectangle->shadow_width * m), roundint(rectangle->shadow_width * m), height); } } }
static void gtk_plot_canvas_text_size_allocate(GtkPlotCanvas *canvas, GtkPlotCanvasChild *child) { GtkPlotCanvasText *text = GTK_PLOT_CANVAS_TEXT(child); gint tx, ty, x, y, width, height; gdouble m = canvas->magnification; text->text.x = child->rx1; text->text.y = child->ry1; x = roundint(text->text.x * canvas->pixmap_width); y = roundint(text->text.y * canvas->pixmap_height); gtk_plot_text_get_area(text->text.text, text->text.angle, text->text.justification, text->text.font, roundint(m * text->text.height), &tx, &ty, &width, &height); if(text->text.border != GTK_PLOT_BORDER_NONE){ tx -= text->text.border_space; ty -= text->text.border_space; width += 2 * text->text.border_space; height += 2 * text->text.border_space; } tx += x; ty += y; child->allocation.x = tx; child->allocation.y = ty; child->allocation.width = width; child->allocation.height = height; gtk_plot_canvas_get_position(canvas, tx + width, ty + height, &child->rx2, &child->ry2); }
void drawregnms() { int len,my; double d,*h,*ins,*out,w,w2,y; dvec *x; my=(int)My; setgxywh(Rx,Ry+my,Rw,Rh-(my+LabelHit+Ly)); len=Date->n; PDate=dvec_new(len+1); DO(len,PDate->v[i]=Date->v[i]); PDate->v[len]=PDate->v[len-1]+PDate->v[1]-PDate->v[0]; getdateaxis(0); ins=Data->v; out=Data->v+len; PData=dmat_new(1,len); DO(len,PData->v[i]=ins[i]+out[i]); drawpre(0); x=dvec_new(len); DO(len,x->v[i]=(XPos->v[i]+XPos->v[i+1])/2); fitgrafx(x); w=MAX(1,(floor(Gw/len))-2); w2=ceil(w/2); y=Gy+Gh; d=YMax-YMin; h=g_malloc(len*sizeof(double)); DO(len,h[i]=roundint(Gh*(PData->v[i])-YMin)/d); cairo_set_line_width(CR,1); DO(len,{ cairo_rectangle(CR,x->v[i]-w2,(y-h[i]),w,h[i]); cairo_set_source(CR,InColor); cairo_fill_preserve(CR); cairo_set_source(CR,BarColor); cairo_stroke(CR);});
void drawprice() { int cls,h,my,rws; if (Kex!=NULL){drawpricesym();return;} rws=Data->r; cls=Data->c; PDate=dvec_dup(Date); PData=dmat_new(rws,cls); DO(Data->n,PData->v[i]=Data->v[i]); if (Split) { h=roundint(Rh/4); setsxywh(Rx,(Ry+Rh-h),Rw,h-Ly); setrxywh(Rx,Ry,Rw,Rh-(1+h+Ly)); } my=(int) My; setgxywh(Rx,Ry+my,Rw,Rh-(my+LabelHit+Ly)); getdateaxis(0); drawpre(-1); drawprices(); drawpost(); drawkeys(); if (!Split) return; dmat_free(PData); PData=dmat_new(1,cls); DO(cls,PData->v[i]=Size->v[i]); setrxywh(Sx,Sy,Sw,Sh); setgxywh(Sx,Sy+my,Sw,Sh-(my+LabelHit+Ly)); drawpre(-1); drawvolumes(); drawpost(); }
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_bar_draw_legend(GtkPlotData *data, gint x, gint y) { GtkPlotBar *bar; GtkPlot *plot = NULL; GtkPlotText legend; GdkRectangle area; gint lascent, ldescent, lheight, lwidth; gdouble m; bar = GTK_PLOT_BAR(data); g_return_if_fail(data->plot != NULL); g_return_if_fail(GTK_IS_PLOT(data->plot)); g_return_if_fail(GTK_WIDGET_VISIBLE(data)); g_return_if_fail(GTK_WIDGET_VISIBLE(data->plot)); plot = data->plot; area.x = GTK_WIDGET(plot)->allocation.x; area.y = GTK_WIDGET(plot)->allocation.y; area.width = GTK_WIDGET(plot)->allocation.width; area.height = GTK_WIDGET(plot)->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); legend.x = (gdouble)(area.x + x + roundint((plot->legends_line_width + 4) * m)) / (gdouble)area.width; legend.y = (gdouble)(area.y + y + lascent) / (gdouble)area.height; gtk_plot_draw_text(plot, legend); if(data->symbol.symbol_style == GTK_PLOT_SYMBOL_OPAQUE){ gtk_plot_pc_set_color(plot->pc, &plot->background); gtk_plot_pc_draw_rectangle(plot->pc, TRUE, x, y, roundint(plot->legends_line_width * m), lascent + ldescent); } gtk_plot_pc_set_lineattr (plot->pc, data->symbol.border.line_width, 0, 0, 0); gtk_plot_pc_set_dash(plot->pc, 0, 0, 0); if(data->symbol.symbol_style == GTK_PLOT_SYMBOL_FILLED){ gtk_plot_pc_set_color(plot->pc, &data->symbol.color); gtk_plot_pc_draw_rectangle(plot->pc, TRUE, x, y, roundint(plot->legends_line_width * m), lascent + ldescent); } gtk_plot_pc_set_color(plot->pc, &data->symbol.border.color); gtk_plot_pc_draw_rectangle(plot->pc, FALSE, x, y, roundint(plot->legends_line_width * m), lascent + ldescent); }
static void gtk_plot_bar_draw_symbol(GtkPlotData *dataset, gdouble x, gdouble y, gdouble z, gdouble a, gdouble dx, gdouble dy, gdouble dz, gdouble da) { GtkPlot *plot; GtkPlotBar *bar; GdkRectangle area, clip_area; gdouble px, py, px0, py0; gdouble x1 = 0.0, y1 = 0.0, width = 0.0, height = 0.0; gdouble ex, ey; bar = GTK_PLOT_BAR(dataset); plot = dataset->plot; area.x = GTK_WIDGET(plot)->allocation.x; area.y = GTK_WIDGET(plot)->allocation.y; area.width = GTK_WIDGET(plot)->allocation.width; area.height = GTK_WIDGET(plot)->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)){ } else { switch(bar->orientation){ case GTK_ORIENTATION_VERTICAL: gtk_plot_get_pixel(plot, x-bar->width, y, &px, &py); gtk_plot_get_pixel(plot, x+bar->width, MAX(0., plot->ymin), &px0, &py0); if(dataset->show_yerrbars) gtk_plot_get_pixel(plot, x, y + dy, &ex, &ey); break; case GTK_ORIENTATION_HORIZONTAL: gtk_plot_get_pixel(plot, y, x+bar->width, &px, &py); gtk_plot_get_pixel(plot, MAX(0., plot->xmin), x-bar->width, &px0, &py0); if(dataset->show_xerrbars) gtk_plot_get_pixel(plot, y + dy, x, &ex, &ey); break; } x1 = MIN(px, px0); y1 = MIN(py, py0); if(GTK_IS_PLOT_PS(plot->pc)){ width = fabs(px - px0); height = fabs(py0 - py); } else { width = abs(roundint(px - px0)); height = abs(roundint(py0 - py)); } if(dataset->symbol.symbol_style == GTK_PLOT_SYMBOL_OPAQUE){ gtk_plot_pc_set_color(plot->pc, &plot->background); gtk_plot_pc_draw_rectangle (plot->pc, TRUE, x1, y1, width, height); } gtk_plot_pc_set_lineattr (plot->pc, dataset->symbol.border.line_width, 0, 0, 0); gtk_plot_pc_set_dash (plot->pc, 0, 0, 0); if(dataset->symbol.symbol_style == GTK_PLOT_SYMBOL_FILLED){ gtk_plot_pc_set_color(plot->pc, &dataset->symbol.color); gtk_plot_pc_draw_rectangle (plot->pc, TRUE, x1, y1, width, height); } gtk_plot_pc_set_color(plot->pc, &dataset->symbol.border.color); gtk_plot_pc_draw_rectangle (plot->pc, FALSE, x1, y1, width, height); if(dataset->show_yerrbars){ gtk_plot_pc_draw_line(plot->pc, ex, py, ex, ey); gtk_plot_pc_draw_line(plot->pc, px, ey, px0, ey); } if(dataset->show_xerrbars){ gtk_plot_pc_draw_line(plot->pc, px, ey, ex, ey); gtk_plot_pc_draw_line(plot->pc, ex, py, ex, py0); } } gtk_plot_pc_clip(plot->pc, NULL); }
static void gtk_plot_candle_draw_legend(GtkPlotData *data, gint x, gint y) { GtkPlotCandle *box; GtkPlot *plot = NULL; GtkPlotText legend; GdkRectangle area; gint lascent, ldescent, lheight, lwidth; gdouble m; box = GTK_PLOT_CANDLE(data); g_return_if_fail(data->plot != NULL); g_return_if_fail(GTK_IS_PLOT(data->plot)); if(!GTK_WIDGET_REALIZED(data->plot)) return; plot = data->plot; area.x = GTK_WIDGET(plot)->allocation.x; area.y = GTK_WIDGET(plot)->allocation.y; area.width = GTK_WIDGET(plot)->allocation.width; area.height = GTK_WIDGET(plot)->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); legend.x = (gdouble)(area.x + x + roundint((plot->legends_line_width + 4) * m)) / (gdouble)area.width; legend.y = (gdouble)(area.y + y + lascent) / (gdouble)area.height; gtk_plot_draw_text(plot, legend); gtk_plot_pc_set_lineattr (plot->pc, data->symbol.border.line_width, 0, 0, 0); gtk_plot_pc_set_dash (plot->pc, 0, 0, 0); gtk_plot_pc_set_color(plot->pc, &data->symbol.color); if(data->symbol.symbol_style == GTK_PLOT_SYMBOL_EMPTY){ gtk_plot_pc_draw_line(plot->pc, x, y + (lascent + ldescent) / 2, x + roundint(plot->legends_line_width * m), y + (lascent + ldescent) / 2); } else { gtk_plot_pc_draw_rectangle(plot->pc, TRUE, x, y, roundint(plot->legends_line_width * m), lascent + ldescent); gtk_plot_pc_set_color(plot->pc, &data->symbol.border.color); gtk_plot_pc_draw_rectangle(plot->pc, FALSE, x, y, roundint(plot->legends_line_width * m), lascent + ldescent); } }
static void gtk_plot_surface_draw_legend(GtkPlotData *data, gint x, gint y) { GtkPlotSurface *surface; GtkPlot *plot = NULL; GtkPlotText legend; GdkRectangle area; gint lascent, ldescent, lheight, lwidth; gdouble m; surface = GTK_PLOT_SURFACE(data); g_return_if_fail(data->plot != NULL); g_return_if_fail(GTK_IS_PLOT(data->plot)); plot = data->plot; area.x = GTK_WIDGET(plot)->allocation.x; area.y = GTK_WIDGET(plot)->allocation.y; area.width = GTK_WIDGET(plot)->allocation.width; area.height = GTK_WIDGET(plot)->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(!surface->height_gradient){ gtk_plot_pc_set_color(plot->pc, &surface->color); gtk_plot_pc_draw_rectangle(plot->pc, TRUE, x, y, roundint(plot->legends_line_width * m), lascent + ldescent); }else{ gdouble level, step; gint lx = x, lstep; step = (data->gradient.end - data->gradient.begin) / 10; lstep = roundint(plot->legends_line_width * m / 10.); for(level = data->gradient.begin; level < data->gradient.end; level += step){ GdkColor color; gtk_plot_data_get_gradient_level(data, level, &color); gtk_plot_pc_set_color(plot->pc, &color); gtk_plot_pc_draw_rectangle(plot->pc, TRUE, lx, y, lstep, lascent + ldescent); lx += lstep; } } legend.x = (gdouble)(area.x + x + roundint((plot->legends_line_width + 4) * m)) / (gdouble)area.width; legend.y = (gdouble)(area.y + y + lascent) / (gdouble)area.height; gtk_plot_draw_text(plot, legend); y += 2*lheight; gtk_plot_data_draw_gradient(data, x, y); }
static void gtk_plot_surface_update_range (GtkPlotData *data) { GtkPlotSurface *surface; GtkPlot *plot; if(!data->redraw_pending) return; surface = GTK_PLOT_SURFACE(data); plot = data->plot; if(!surface->recalc_dt && data->num_points > 0){ gtk_plot_surface_recalc_nodes(surface); data->redraw_pending = FALSE; surface->recalc_dt = FALSE; return; } if(!data->is_function && data->num_points > 0){ if(surface->recalc_dt) gtk_plot_surface_build_mesh(surface); else gtk_plot_surface_recalc_nodes(surface); data->redraw_pending = FALSE; surface->recalc_dt = FALSE; return; } if(data->is_function){ gdouble xstep, ystep; gdouble xmin, xmax, ymin, ymax; gdouble x, y; gdouble *fx = NULL, *fy = NULL, *fz = NULL; gdouble *old_x, *old_y, *old_z; gint nx, ny; gint npoints; xmin = GTK_PLOT(plot)->xmin; xmax = GTK_PLOT(plot)->xmax; ymin = GTK_PLOT(plot)->ymin; ymax = GTK_PLOT(plot)->ymax; xstep = surface->xstep; surface->nx = roundint((xmax - xmin) / xstep) + 1; ystep = surface->ystep; surface->ny = roundint((ymax - ymin) / ystep) + 1; npoints = surface->nx * surface->ny; fx = (gdouble *)g_malloc((npoints + 1) * sizeof(gdouble)); fy = (gdouble *)g_malloc((npoints + 1) * sizeof(gdouble)); fz = (gdouble *)g_malloc((npoints + 1) * sizeof(gdouble)); npoints = 0; y = ymin; for(ny = 0; ny < surface->ny; ny++) { x = xmin; for(nx = 0; nx < surface->nx; nx++) { gboolean error; fx[npoints] = x; fy[npoints] = y; fz[npoints] = data->function3d(plot, data, x, y, &error); x += xstep; npoints++; } y += ystep; } old_x = data->x; old_y = data->y; old_z = data->z; data->x = fx; data->y = fy; data->z = fz; data->num_points = npoints; gtk_plot_surface_build_mesh(surface); g_free(fx); g_free(fy); g_free(fz); data->x = old_x; data->y = old_y; data->z = old_z; } data->redraw_pending = FALSE; surface->recalc_dt = FALSE; }
void gtk_plot_surface_build_mesh(GtkPlotSurface *surface) { GtkPlotData *data; GtkPlot *plot; data = GTK_PLOT_DATA(surface); if(!data->plot) return; plot = data->plot; if(data->is_function){ gdouble xstep, ystep; gdouble xmin, xmax, ymin, ymax; gdouble x, y; gdouble *fx = NULL, *fy = NULL, *fz = NULL; gdouble *old_x, *old_y, *old_z; gint nx, ny; gint npoints; xmin = GTK_PLOT(plot)->xmin; xmax = GTK_PLOT(plot)->xmax; ymin = GTK_PLOT(plot)->ymin; ymax = GTK_PLOT(plot)->ymax; xstep = surface->xstep; surface->nx = roundint((xmax - xmin) / xstep) + 1; ystep = surface->ystep; surface->ny = roundint((ymax - ymin) / ystep) + 1; npoints = surface->nx * surface->ny; fx = (gdouble *)g_malloc((npoints + 1) * sizeof(gdouble)); fy = (gdouble *)g_malloc((npoints + 1) * sizeof(gdouble)); fz = (gdouble *)g_malloc((npoints + 1) * sizeof(gdouble)); npoints = 0; y = ymin; for(ny = 0; ny < surface->ny; ny++) { x = xmin; for(nx = 0; nx < surface->nx; nx++) { gboolean error; fx[npoints] = x; fy[npoints] = y; fz[npoints] = data->function3d(plot, data, x, y, &error); x += xstep; npoints++; } y += ystep; } old_x = data->x; old_y = data->y; old_z = data->z; data->x = fx; data->y = fy; data->z = fz; data->num_points = npoints; gtk_plot_surface_real_build_mesh(surface); g_free(fx); g_free(fy); g_free(fz); } else if(data->is_iterator){ gdouble x, y, z, a, dx, dy, dz, da; gchar *label; gdouble *fx = NULL, *fy = NULL, *fz = NULL; gint iter; if(data->iterator_mask & GTK_PLOT_DATA_X) fx = g_new0(gdouble, data->num_points); if(data->iterator_mask & GTK_PLOT_DATA_Y) fy = g_new0(gdouble, data->num_points); if(data->iterator_mask & GTK_PLOT_DATA_Z) fz = g_new0(gdouble, data->num_points); for(iter = 0; iter < data->num_points; iter++) { gboolean error; data->iterator (plot, data, iter, &x, &y, &z, &a, &dx, &dy, &dz, &da, &label, &error); if(error) { break; } else { if(data->iterator_mask & GTK_PLOT_DATA_X) fx[iter] = x; if(data->iterator_mask & GTK_PLOT_DATA_Y) fy[iter] = y; if(data->iterator_mask & GTK_PLOT_DATA_Z) fz[iter] = z; } } data->x = fx; data->y = fy; data->z = fz; gtk_plot_surface_real_build_mesh(surface); g_free(fx); g_free(fy); g_free(fz); } else gtk_plot_surface_real_build_mesh(surface); }
long OBDH2RCVRtime(long obdh_intg, long obdh_frac, long *gps_intg, long *gps_frac, long icu_blk_nr, FILE *tim1b) /*-----------------------------------------------------------------------------> / purpose: Return GPS time based on OBDH Time input and ACC BlockNr / / coded by: Gerhard L.H. Kruizinga 10/30/01 / modified: Gerhard L.H. Kruizinga 02/18/02 / modified: Gerhard L.H. Kruizinga 09/09/03 / / input: / obdh_intg obdh time (integer seconds) / obdh_frac obdh time fraction (micro seconds) / icu_blk_nr icu data block number associate with obdh time / tim1b file pointer to TIM1B file / output: / gps_intg gps time (integer seconds) / gps_frac obdh time fraction (micro seconds) / return / 0L if mapping succesful / 1L request time after TIM file range / 21L GPS mapping not determined (no tim1b record available) / 22L GPS mapping not defined / 23L GPS mapping not determined (no start icu block nr available) / 24L GPS mapping not determined (no final icu block nr available) / 25L GPS mapping not determined (icu block nr != tim1b block nr) / 26L GPS mapping not determined (icu block nr outside tim1b block nr range) / 27L GPS mapping not determined (cannot compute GPS mapping) / 3L problem reading tim1b header / 4L tim1b file is not a tim1b file or tim1b file is an ascii file / -1L request time before TIM file range <-----------------------------------------------------------------------------*/ { static long first = 1,first_obs = 1; static long Tim1bStart,Tim1bFinal,tim1b_nrecs; static long block_time_diff, prev_block_time_diff = -999999; long ndx,i; double Time; static TIM1X_t **tim1b_recs,tim1b_record; FileHeader_t tim1b_header; char bits8[8]; *gps_intg = obdh_intg; *gps_frac = obdh_frac; /*>>>> if file pointer is not set return input as output <<<<*/ if (tim1b == NULL) return 0L; /*>>>> on first call load tim1b file into memory <<<<*/ if (first) { InitializeHeaderStruct(&tim1b_header); if (ReadFileHeader(tim1b,&tim1b_header) == false) { fprintf(stderr,"\n Problem reading tim1b file header in OBDH2RCVRtime\n"); fprintf(stderr," See message above for problem\n\n"); return 3L; } if (tim1b_header.filetype != GetFileType("ipTIM1XF") || tim1b_header.formattype != 0) { fprintf(stderr,"\n TIM1A file in OBDH2RCVRtime is not a TIM mapping file or \n"); fprintf(stderr," TIM1A file is an ascii TIM mapping file . Check Input file!\n\n"); return 4L; } while(ReadTIM1XFRecord(tim1b,&tim1b_record) == true) { if (first_obs) {Tim1bStart = tim1b_record.obdh_time; first_obs = 0;} Tim1bFinal = tim1b_record.obdh_time; } tim1b_nrecs = Tim1bFinal -Tim1bStart + 1; tim1b_recs = (TIM1X_t **) malloc ((size_t)tim1b_nrecs * sizeof(TIM1X_t *)); loop(i,tim1b_nrecs) tim1b_recs[i] = NULL; rewind(tim1b); if (ReadFileHeader(tim1b,&tim1b_header) == false) { fprintf(stderr,"\n Problem second reading tim1b file header in OBDH2RCVRtime\n"); fprintf(stderr," See message above for problem\n\n"); return 3L; } while(ReadTIM1XFRecord(tim1b,&tim1b_record) == true) { if (first) {Tim1bStart = tim1b_record.obdh_time; first = 0;} ndx = tim1b_record.obdh_time - Tim1bStart; if (ndx < 0 || ndx > tim1b_nrecs-1) { fprintf(stderr," Data point in OBDH2RCVRtime at %d not within time_span %d <-> %d\n", tim1b_record.obdh_time,Tim1bStart,Tim1bFinal); continue; } tim1b_recs[ndx] = (TIM1X_t *) malloc(sizeof(TIM1X_t)); *tim1b_recs[ndx] = tim1b_record; } if (icu_blk_nr != NOBLOCK) prev_block_time_diff = obdh_intg - icu_blk_nr; first = 0; } block_time_diff = obdh_intg - icu_blk_nr; ndx = obdh_intg - Tim1bStart; /* correct for one second offset applied to ACC data in EncodeICUpacket */ if (icu_blk_nr != NOBLOCK) ndx++; if ((icu_blk_nr != NOBLOCK) && (block_time_diff != prev_block_time_diff) && (obdh_frac > 1000000)) { ndx++; } /*>>> check for valid ndx range <<<<*/ if (ndx < 0) return -1L; if (ndx > tim1b_nrecs-1) return 1L; /*>>> check if tim1b record is in memory <<<<*/ if (tim1b_recs[ndx] == NULL) return 21L; /*>>> check if GPS mapping is defined <<<<*/ GetCharBits(tim1b_recs[ndx]->qualflg,bits8); if (bits8[3]) return 22L; if (bits8[6]) return 27L; Time = (double) tim1b_recs[ndx]->gpstime_intg + 1e-6*(double) tim1b_recs[ndx]->gpstime_frac + 1e-6*(double) obdh_frac; *gps_intg = (long) Time; *gps_frac = roundint( 1e6*(Time - (double) *gps_intg)); /*>>>> check if icu_blk_nr matches or for multiple block compute proper offset <<<<*/ if (icu_blk_nr >= 0) { if (tim1b_recs[ndx]->first_icu_blknr == NOBLOCK) { prev_block_time_diff = block_time_diff; *gps_intg = obdh_intg; *gps_frac = obdh_frac; return 23L; } if (tim1b_recs[ndx]->final_icu_blknr == NOBLOCK) { prev_block_time_diff = block_time_diff; *gps_intg = obdh_intg; *gps_frac = obdh_frac; return 24L; } if (tim1b_recs[ndx]->first_icu_blknr == tim1b_recs[ndx]->final_icu_blknr) { if (icu_blk_nr != tim1b_recs[ndx]->first_icu_blknr) { fprintf(stderr," Input ICU block number = %d != tim1b ICU blocknumber %d\n", icu_blk_nr,tim1b_recs[ndx]->first_icu_blknr); prev_block_time_diff = block_time_diff; *gps_intg = obdh_intg; *gps_frac = obdh_frac; return 25L; } } else { if (icu_blk_nr < tim1b_recs[ndx]->first_icu_blknr || icu_blk_nr > tim1b_recs[ndx]->final_icu_blknr) { fprintf(stderr," Input ICU block number = %d is out of tim1b block number", icu_blk_nr); fprintf(stderr," range %d <-> %d\n",tim1b_recs[ndx]->first_icu_blknr, tim1b_recs[ndx]->final_icu_blknr); prev_block_time_diff = block_time_diff; *gps_intg = obdh_intg; *gps_frac = obdh_frac; return 26L; } *gps_intg = tim1b_recs[ndx]->gpstime_intg + icu_blk_nr - tim1b_recs[ndx]->first_icu_blknr; } prev_block_time_diff = block_time_diff; } /* correct new gps time for 1 second delay in ACC data time tag */ if (icu_blk_nr != NOBLOCK) *gps_intg = *gps_intg - 1; return 0L; }
static GdkBitmap * scale_bitmap (GdkWindow *window, GdkBitmap *bitmap, gdouble scale_x, gdouble scale_y) { GdkGC *gc; GdkVisual *visual = NULL; GdkImage *image = NULL, *new_image = NULL; GdkBitmap *new_bitmap = NULL; gint x, y, width, height, new_width, new_height; GdkColor color; if(!bitmap) return NULL; if(!window) return NULL; gc = gdk_gc_new(bitmap); gdk_window_get_size(bitmap, &width, &height); if(scale_x == 1.0 && scale_y == 1.0){ new_bitmap = gdk_pixmap_new(window, width, height, 1); color.pixel = 0; gdk_gc_set_foreground(gc, &color); gdk_draw_rectangle(new_bitmap, gc, TRUE, 0, 0, width, height); color.pixel = 1; gdk_gc_set_foreground(gc, &color); gdk_draw_pixmap(new_bitmap, gc, bitmap, 0, 0, 0, 0, width, height); gdk_gc_unref(gc); return new_bitmap; } new_width = roundint(width * scale_x); new_height = roundint(height * scale_y); /* make a client side image of the bitmap, and * scale the data into a another client side image */ visual = gdk_window_get_visual (bitmap); if(!visual) return NULL; new_image = gdk_image_new(GDK_IMAGE_FASTEST,visual,new_width,new_height); if(!new_image) return NULL; new_bitmap = gdk_pixmap_new(window, new_width, new_height, 1); image = gdk_drawable_get_image(bitmap, 0, 0, width, height); color.pixel = 0; gdk_gc_set_foreground(gc, &color); gdk_draw_rectangle(new_bitmap, gc, TRUE, 0, 0, width, height); color.pixel = 1; gdk_gc_set_foreground(gc, &color); for(x = 0; x < new_width; x++){ for(y = 0; y < new_height; y++){ gint px, py; gulong pixel; px = MIN(roundint(x / scale_x), width - 1); py = MIN(roundint(y / scale_y), height - 1); pixel = gdk_image_get_pixel(image, px, py); gdk_image_put_pixel(new_image, x, y, pixel); } } /* draw the image into a new pixmap */ gdk_draw_image(new_bitmap,gc,new_image,0,0,0,0,new_width,new_height); gdk_image_destroy(image); gdk_image_destroy(new_image); gdk_gc_unref(gc); return new_bitmap; }
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, z2 = 0; 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; z2 = size * dz / 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; x2 = size * dx / xm; y2 = size * dy / xm; gtk_plot_get_pixel(plot, x, y, &x1, &y1); 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); */ }
w2=ceil(w/2); y=Gy+Gh; d=YMax-YMin; h=g_malloc(len*sizeof(double)); DO(len,h[i]=roundint(Gh*(PData->v[i])-YMin)/d); cairo_set_line_width(CR,1); DO(len,{ cairo_rectangle(CR,x->v[i]-w2,(y-h[i]),w,h[i]); cairo_set_source(CR,InColor); cairo_fill_preserve(CR); cairo_set_source(CR,BarColor); cairo_stroke(CR);}); DO(len,h[i]=roundint(Gh*(out[i]-YMin)/d)); DO(len,{ cairo_rectangle(CR,x->v[i]-w2,(y-h[i]),w,h[i]); cairo_set_source(CR,BarColor); cairo_fill_preserve(CR); cairo_stroke(CR);}); cairo_set_source(CR,Black); pango_layout_set_font_description(PL,LabelFontB); pango_layout_set_text(PL,"Trades Inside/Outside NBBO",-1); cairo_move_to(CR,Gx,Gy-(LabelHit+Ly)); pango_cairo_show_layout(CR,PL); drawpost(); dvec_free(x);
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 GdkBitmap * scale_bitmap (GdkWindow *window, GdkBitmap *bitmap, gdouble scale_x, gdouble scale_y) { GdkGC *gc; GdkColormap *colormap; GdkColorContext *cc; GdkVisual *visual; GdkImage *image; GdkBitmap *new_bitmap; gint x, y, width, height, new_width, new_height; GdkColor color; if(!bitmap) return NULL; if(!window) return NULL; gc = gdk_gc_new(bitmap); colormap = gdk_colormap_get_system (); visual = gdk_visual_get_system (); cc = gdk_color_context_new(visual, colormap); gdk_window_get_size(bitmap, &width, &height); if(scale_x == 1.0 && scale_y == 1.0){ new_bitmap = gdk_pixmap_new(window, width, height, 1); color.pixel = 0; gdk_gc_set_foreground(gc, &color); gdk_draw_rectangle(new_bitmap, gc, TRUE, 0, 0, width, height); color.pixel = 1; gdk_gc_set_foreground(gc, &color); gdk_draw_pixmap(new_bitmap, gc, bitmap, 0, 0, 0, 0, width, height); return new_bitmap; } new_width = roundint(width * scale_x); new_height = roundint(height * scale_y); new_bitmap = gdk_pixmap_new(window, new_width, new_height, 1); color.pixel = 0; gdk_gc_set_foreground(gc, &color); gdk_draw_rectangle(new_bitmap, gc, TRUE, 0, 0, width, height); color.pixel = 1; gdk_gc_set_foreground(gc, &color); image = gdk_image_get(bitmap, 0, 0, width, height); for(x = 0; x < new_width; x++){ for(y = 0; y < new_height; y++){ gint px, py; gulong pixel; px = MIN(roundint(x / scale_x), width - 1); py = MIN(roundint(y / scale_y), height - 1); pixel = gdk_image_get_pixel(image, px, py); if(pixel != 0) gdk_draw_point(new_bitmap, gc, x, y); } } gdk_image_destroy(image); gdk_color_context_free(cc); return new_bitmap; }