Skip to content

Commit

Permalink
change to use stride
Browse files Browse the repository at this point in the history
  • Loading branch information
pchilds committed Sep 15, 2012
1 parent 0e02b99 commit e824fb9
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 160 deletions.
8 changes: 5 additions & 3 deletions gtk2plot/gtkplot.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ void gtk_plot_set_colour(GtkPlot *plot, GArray *rd, GArray *gr, GArray *bl, GArr
{(plot->rd)=g_array_ref(rd); (plot->gr)=g_array_ref(gr); (plot->bl)=g_array_ref(bl); (plot->al)=g_array_ref(al);} {(plot->rd)=g_array_ref(rd); (plot->gr)=g_array_ref(gr); (plot->bl)=g_array_ref(bl); (plot->al)=g_array_ref(al);}
} }


void gtk_plot_set_indices(GtkPlot *plot, GArray *nx, GArray *sz) void gtk_plot_set_indices(GtkPlot *plot, GArray *nx, GArray *sz, GArray *st)
{ {
if (plot->ind) g_array_free((plot->ind), FALSE); if (plot->ind) g_array_free((plot->ind), FALSE);
if (plot->sizes) g_array_free((plot->sizes), FALSE); if (plot->sizes) g_array_free((plot->sizes), FALSE);
{(plot->ind)=g_array_ref(nx); (plot->sizes)=g_array_ref(sz);} if (plot->stride) g_array_free((plot->stride), FALSE);
{(plot->ind)=g_array_ref(nx); (plot->sizes)=g_array_ref(sz); (plot->stride)=g_array_ref(st);}
} }


void gtk_plot_set_index(GtkPlot *plot, GArray *nx) void gtk_plot_set_index(GtkPlot *plot, GArray *nx)
Expand All @@ -67,6 +68,7 @@ static void gtk_plot_finalise(GtkPlot *plot)
{ {
if (plot->ind) g_array_free((plot->ind), FALSE); if (plot->ind) g_array_free((plot->ind), FALSE);
if (plot->sizes) g_array_free((plot->sizes), FALSE); if (plot->sizes) g_array_free((plot->sizes), FALSE);
if (plot->stride) g_array_free((plot->stride), FALSE);
if (plot->afont) pango_font_description_free(plot->afont); if (plot->afont) pango_font_description_free(plot->afont);
if (plot->lfont) pango_font_description_free(plot->lfont); if (plot->lfont) pango_font_description_free(plot->lfont);
if (plot->rd) g_array_free((plot->rd), FALSE); if (plot->rd) g_array_free((plot->rd), FALSE);
Expand All @@ -92,7 +94,7 @@ static void gtk_plot_init(GtkPlot *plot)
{pango_font_description_set_family((plot->afont), "sans"); pango_font_description_set_family((plot->lfont), "sans");} {pango_font_description_set_family((plot->afont), "sans"); pango_font_description_set_family((plot->lfont), "sans");}
{pango_font_description_set_style((plot->afont), PANGO_STYLE_NORMAL); pango_font_description_set_style((plot->lfont), PANGO_STYLE_NORMAL);} {pango_font_description_set_style((plot->afont), PANGO_STYLE_NORMAL); pango_font_description_set_style((plot->lfont), PANGO_STYLE_NORMAL);}
{pango_font_description_set_size((plot->afont), 12*PANGO_SCALE); pango_font_description_set_size((plot->lfont), 12*PANGO_SCALE);} {pango_font_description_set_size((plot->afont), 12*PANGO_SCALE); pango_font_description_set_size((plot->lfont), 12*PANGO_SCALE);}
{(plot->sizes)=NULL; (plot->ind)=NULL;} {(plot->sizes)=NULL; (plot->ind)=NULL; (plot->stride)=NULL;}
(plot->rd)=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 10); (plot->rd)=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 10);
(plot->gr)=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 10); (plot->gr)=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 10);
(plot->bl)=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 10); (plot->bl)=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 10);
Expand Down
4 changes: 2 additions & 2 deletions gtk2plot/gtkplot.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
struct _GtkPlot struct _GtkPlot
{ {
GtkDrawingArea parent; GtkDrawingArea parent;
GArray *ind, *sizes; /* indices of first element and number of elements for each trace */ GArray *ind, *sizes, *stride; /* indices of first element, number of elements for each trace and spacing in array between elements of the same plot*/
GArray *rd, *gr, *bl, *al; /* colour and alpha of the plots */ GArray *rd, *gr, *bl, *al; /* colour and alpha of the plots */
PangoFontDescription *afont, *lfont; /* font descriptions for the tick mark and axis labels */ PangoFontDescription *afont, *lfont; /* font descriptions for the tick mark and axis labels */
}; };
Expand All @@ -49,7 +49,7 @@
}; };
void gtk_plot_set_font(GtkPlot *plot, PangoFontDescription *lf, PangoFontDescription *af); void gtk_plot_set_font(GtkPlot *plot, PangoFontDescription *lf, PangoFontDescription *af);
void gtk_plot_set_colour(GtkPlot *plot, GArray *rd, GArray *gr, GArray *bl, GArray *al); void gtk_plot_set_colour(GtkPlot *plot, GArray *rd, GArray *gr, GArray *bl, GArray *al);
void gtk_plot_set_indices(GtkPlot *plot, GArray *nd, GArray *sz); void gtk_plot_set_indices(GtkPlot *plot, GArray *nd, GArray *sz, GArray *st);
void gtk_plot_set_index(GtkPlot *plot, GArray *nd); void gtk_plot_set_index(GtkPlot *plot, GArray *nd);
GtkWidget *gtk_plot_new(void); GtkWidget *gtk_plot_new(void);
G_END_DECLS G_END_DECLS
Expand Down
25 changes: 17 additions & 8 deletions gtk2plot/gtkplotlinear.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ static void draw(GtkWidget *widget, cairo_t *cr)
GtkPlotLinear *plot; GtkPlotLinear *plot;
GtkPlot *plt; GtkPlot *plt;
GtkAllocation alloc; GtkAllocation alloc;
gint j, k, xw, yw, xr, xr2, yr, yr2, xa, ya, xl, yl, xu, yu, tf, tz, to, tn, tnn, xv, yv, xvn, yvn, dtt, tx, wd, hg, ft, lt, xt; gint dtt, ft, hg, j, k, lt, st, tf, to, tn, tnn, tx, tz, wd, xa, xl, xr, xr2, xt, xu, xv, xvn, xw, ya, yl, yr, yr2, yu, yv, yvn, yw;
gdouble vv, wv, zv, av, dt, lr1, lr2, delx, dely; gdouble av, delx, dely, dt, lr, lr2, vv, wv, zv;
guint lr3; guint lr3;
gchar *str1=NULL; gchar *str1=NULL;
gchar lbl[BFL]; gchar lbl[BFL];
Expand Down Expand Up @@ -2939,7 +2939,10 @@ static void draw(GtkWidget *widget, cairo_t *cr)
{vv=g_array_index((plt->rd), gdouble, dtt); wv=g_array_index((plt->gr), gdouble, dtt); zv=g_array_index((plt->bl), gdouble, dtt); av=g_array_index((plt->al), gdouble, dtt);} {vv=g_array_index((plt->rd), gdouble, dtt); wv=g_array_index((plt->gr), gdouble, dtt); zv=g_array_index((plt->bl), gdouble, dtt); av=g_array_index((plt->al), gdouble, dtt);}
cairo_set_source_rgba(cr, vv, wv, zv, av); cairo_set_source_rgba(cr, vv, wv, zv, av);
ft=g_array_index((plt->ind), gint, k); ft=g_array_index((plt->ind), gint, k);
lt=g_array_index((plt->sizes), gint, k)+ft; if (ft>=(plot->ydata->len)) break;
st=g_array_index((plt->stride), gint, k);
lt=(g_array_index((plt->sizes), gint, k)*st)+ft;
if (lt>(plot->ydata->len)) lt=(plot->ydata->len);
xv=xl+((xu-xl)*(g_array_index((plot->xdata), gdouble, ft)-(priv->bounds.xmin))/((priv->bounds.xmax)-(priv->bounds.xmin))); xv=xl+((xu-xl)*(g_array_index((plot->xdata), gdouble, ft)-(priv->bounds.xmin))/((priv->bounds.xmax)-(priv->bounds.xmin)));
yv=yl+((yu-yl)*(g_array_index((plot->ydata), gdouble, ft)-(priv->bounds.ymin))/((priv->bounds.ymax)-(priv->bounds.ymin))); yv=yl+((yu-yl)*(g_array_index((plot->ydata), gdouble, ft)-(priv->bounds.ymin))/((priv->bounds.ymax)-(priv->bounds.ymin)));
if (xv<xl) if (xv<xl)
Expand All @@ -2963,7 +2966,7 @@ static void draw(GtkWidget *widget, cairo_t *cr)
cairo_fill(cr); cairo_fill(cr);
cairo_move_to(cr, xv, yv); cairo_move_to(cr, xv, yv);
} }
for (j=1+ft; j<lt; j++) for (j=st+ft; j<lt; j+=st)
{ {
xvn=xl+((xu-xl)*(g_array_index((plot->xdata), gdouble, j)-(priv->bounds.xmin))/((priv->bounds.xmax)-(priv->bounds.xmin))); xvn=xl+((xu-xl)*(g_array_index((plot->xdata), gdouble, j)-(priv->bounds.xmin))/((priv->bounds.xmax)-(priv->bounds.xmin)));
yvn=yl+((yu-yl)*(g_array_index((plot->ydata), gdouble, j)-(priv->bounds.ymin))/((priv->bounds.ymax)-(priv->bounds.ymin))); yvn=yl+((yu-yl)*(g_array_index((plot->ydata), gdouble, j)-(priv->bounds.ymin))/((priv->bounds.ymax)-(priv->bounds.ymin)));
Expand Down Expand Up @@ -3289,7 +3292,10 @@ static void draw(GtkWidget *widget, cairo_t *cr)
{vv=g_array_index((plt->rd), gdouble, dtt); wv=g_array_index((plt->gr), gdouble, dtt); zv=g_array_index((plt->bl), gdouble, dtt); av=g_array_index((plt->al), gdouble, dtt);} {vv=g_array_index((plt->rd), gdouble, dtt); wv=g_array_index((plt->gr), gdouble, dtt); zv=g_array_index((plt->bl), gdouble, dtt); av=g_array_index((plt->al), gdouble, dtt);}
cairo_set_source_rgba(cr, vv, wv, zv, av); cairo_set_source_rgba(cr, vv, wv, zv, av);
ft=g_array_index((plt->ind), gint, k); ft=g_array_index((plt->ind), gint, k);
lt=g_array_index((plt->sizes), gint, k)+ft; if (ft>=(plot->ydata->len)) break;
st=g_array_index((plt->stride), gint, k);
lt=(g_array_index((plt->sizes), gint, k)*st)+ft;
if (lt>(plot->ydata->len)) lt=(plot->ydata->len);
xv=xl+((xu-xl)*(g_array_index((plot->xdata), gdouble, ft)-(priv->bounds.xmin))/((priv->bounds.xmax)-(priv->bounds.xmin)));/*segfault here when adding a plot*/ xv=xl+((xu-xl)*(g_array_index((plot->xdata), gdouble, ft)-(priv->bounds.xmin))/((priv->bounds.xmax)-(priv->bounds.xmin)));/*segfault here when adding a plot*/
yv=yl+((yu-yl)*(g_array_index((plot->ydata), gdouble, ft)-(priv->bounds.ymin))/((priv->bounds.ymax)-(priv->bounds.ymin))); yv=yl+((yu-yl)*(g_array_index((plot->ydata), gdouble, ft)-(priv->bounds.ymin))/((priv->bounds.ymax)-(priv->bounds.ymin)));
if (xv<xl) if (xv<xl)
Expand All @@ -3307,7 +3313,7 @@ static void draw(GtkWidget *widget, cairo_t *cr)
else if (yv>yl)xt=GTK_PLOT_LINEAR_BORDERS_DN; else if (yv>yl)xt=GTK_PLOT_LINEAR_BORDERS_DN;
else if (yv<yu) xt=GTK_PLOT_LINEAR_BORDERS_UP; else if (yv<yu) xt=GTK_PLOT_LINEAR_BORDERS_UP;
else {xt=0; cairo_move_to(cr, xv, yv);} else {xt=0; cairo_move_to(cr, xv, yv);}
for (j=1+ft; j<lt; j++) for (j=st+ft; j<lt; j+=st)
{ {
xvn=xl+((xu-xl)*(g_array_index(plot->xdata, gdouble, j)-(priv->bounds.xmin))/((priv->bounds.xmax)-(priv->bounds.xmin))); xvn=xl+((xu-xl)*(g_array_index(plot->xdata, gdouble, j)-(priv->bounds.xmin))/((priv->bounds.xmax)-(priv->bounds.xmin)));
yvn=yl+((yu-yl)*(g_array_index(plot->ydata, gdouble, j)-(priv->bounds.ymin))/((priv->bounds.ymax)-(priv->bounds.ymin))); yvn=yl+((yu-yl)*(g_array_index(plot->ydata, gdouble, j)-(priv->bounds.ymin))/((priv->bounds.ymax)-(priv->bounds.ymin)));
Expand Down Expand Up @@ -3646,15 +3652,18 @@ static void draw(GtkWidget *widget, cairo_t *cr)
{vv=g_array_index((plt->rd), gdouble, dtt); wv=g_array_index((plt->gr), gdouble, dtt); zv=g_array_index((plt->bl), gdouble, dtt); av=g_array_index((plt->al), gdouble, dtt);} {vv=g_array_index((plt->rd), gdouble, dtt); wv=g_array_index((plt->gr), gdouble, dtt); zv=g_array_index((plt->bl), gdouble, dtt); av=g_array_index((plt->al), gdouble, dtt);}
cairo_set_source_rgba(cr, vv, wv, zv, av); cairo_set_source_rgba(cr, vv, wv, zv, av);
ft=g_array_index((plt->ind), gint, k); ft=g_array_index((plt->ind), gint, k);
lt=g_array_index((plt->sizes), gint, k)+ft; if (ft>=(plot->ydata->len)) break;
st=g_array_index((plt->stride), gint, k);
lt=(g_array_index((plt->sizes), gint, k)*st)+ft;
if (lt>(plot->ydata->len)) lt=(plot->ydata->len);
xv=xl+((xu-xl)*(g_array_index(plot->xdata, gdouble, ft)-(priv->bounds.xmin))/((priv->bounds.xmax)-(priv->bounds.xmin))); xv=xl+((xu-xl)*(g_array_index(plot->xdata, gdouble, ft)-(priv->bounds.xmin))/((priv->bounds.xmax)-(priv->bounds.xmin)));
yv=yl+((yu-yl)*(g_array_index(plot->ydata, gdouble, ft)-(priv->bounds.ymin))/((priv->bounds.ymax)-(priv->bounds.ymin))); yv=yl+((yu-yl)*(g_array_index(plot->ydata, gdouble, ft)-(priv->bounds.ymin))/((priv->bounds.ymax)-(priv->bounds.ymin)));
if ((yv<=yl)&&(yv>=yu)&&(xv>=xl)&&(xv<=xu)) if ((yv<=yl)&&(yv>=yu)&&(xv>=xl)&&(xv<=xu))
{ {
cairo_arc(cr, xv, yv, (plot->ptsize), 0, MY_2PI); cairo_arc(cr, xv, yv, (plot->ptsize), 0, MY_2PI);
cairo_fill(cr); cairo_fill(cr);
} }
for (j=1+ft; j<lt; j++) for (j=st+ft; j<lt; j+=st)
{ {
xv=xl+((xu-xl)*(g_array_index(plot->xdata, gdouble, j)-(priv->bounds.xmin))/((priv->bounds.xmax)-(priv->bounds.xmin))); xv=xl+((xu-xl)*(g_array_index(plot->xdata, gdouble, j)-(priv->bounds.xmin))/((priv->bounds.xmax)-(priv->bounds.xmin)));
yv=yl+((yu-yl)*(g_array_index(plot->ydata, gdouble, j)-(priv->bounds.ymin))/((priv->bounds.ymax)-(priv->bounds.ymin))); yv=yl+((yu-yl)*(g_array_index(plot->ydata, gdouble, j)-(priv->bounds.ymin))/((priv->bounds.ymax)-(priv->bounds.ymin)));
Expand Down
39 changes: 27 additions & 12 deletions gtk2plot/gtkplotpolar.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ static void draw(GtkWidget *widget, cairo_t *cr)
GtkPlotPolar *plot; GtkPlotPolar *plot;
GtkPlot *plt; GtkPlot *plt;
GtkAllocation alloc; GtkAllocation alloc;
gint j, k, xw, yw, kx, j0, jl, xt, wd, hg, ft, lt; gint ft, hg, j, j0, jl, k, kx, lt, st, wd, xt, xw, yw;
gdouble dtt, tt, dtr, thx, thn, dt, sx, csx, ssx, dr1, drs, drc, dz, rt, dwr, rl, ctx, ctn, stx, stn, r, th, rn, tn, x, y, vv, wv, xv, yv; gdouble dtr, dtt, tt, thx, thn, dt, sx, csx, ssx, dr1, drs, drc, dz, rt, dwr, rl, ctx, ctn, stx, stn, r, th, rn, tn, x, y, vv, wv, xv, yv;
gchar lbl[BFL]; gchar lbl[BFL];
gchar *str1=NULL, *str2=NULL, *str3; gchar *str1=NULL, *str2=NULL, *str3;
PangoLayout *lyt; PangoLayout *lyt;
Expand Down Expand Up @@ -1758,7 +1758,10 @@ static void draw(GtkWidget *widget, cairo_t *cr)
{vv=g_array_index((plt->rd), gdouble, ft); wv=g_array_index((plt->gr), gdouble, ft); xv=g_array_index((plt->bl), gdouble, ft); yv=g_array_index((plt->al), gdouble, ft);} {vv=g_array_index((plt->rd), gdouble, ft); wv=g_array_index((plt->gr), gdouble, ft); xv=g_array_index((plt->bl), gdouble, ft); yv=g_array_index((plt->al), gdouble, ft);}
cairo_set_source_rgba(cr, vv, wv, xv, yv); cairo_set_source_rgba(cr, vv, wv, xv, yv);
ft=g_array_index((plt->ind), gint, k); ft=g_array_index((plt->ind), gint, k);
lt=g_array_index((plt->sizes), gint, k)+ft; if (ft>=(plot->ydata->len)) break;
st=g_array_index((plt->stride), gint, k);
lt=(g_array_index((plt->sizes), gint, k)*st)+ft;
if (lt>(plot->ydata->len)) lt=(plot->ydata->len);
for (ssx=MY_2PI; ssx>-10; ssx-=MY_2PI) for (ssx=MY_2PI; ssx>-10; ssx-=MY_2PI)
{ {
r=g_array_index((plot->rdata), gdouble, ft); r=g_array_index((plot->rdata), gdouble, ft);
Expand Down Expand Up @@ -1786,7 +1789,7 @@ static void draw(GtkWidget *widget, cairo_t *cr)
cairo_fill(cr); cairo_fill(cr);
cairo_move_to(cr, x, y); cairo_move_to(cr, x, y);
} }
for (j=1+ft; j<lt; j++) for (j=st+ft; j<lt; j+=st)
{ {
{rn=g_array_index((plot->rdata), gdouble, j); tn=ssx+g_array_index((plot->thdata), gdouble, j);} {rn=g_array_index((plot->rdata), gdouble, j); tn=ssx+g_array_index((plot->thdata), gdouble, j);}
if (rn<(priv->bounds.rmin)) if (rn<(priv->bounds.rmin))
Expand Down Expand Up @@ -2478,7 +2481,10 @@ static void draw(GtkWidget *widget, cairo_t *cr)
{vv=g_array_index((plt->rd), gdouble, ft); wv=g_array_index((plt->gr), gdouble, ft); xv=g_array_index((plt->bl), gdouble, ft); yv=g_array_index((plt->al), gdouble, ft);} {vv=g_array_index((plt->rd), gdouble, ft); wv=g_array_index((plt->gr), gdouble, ft); xv=g_array_index((plt->bl), gdouble, ft); yv=g_array_index((plt->al), gdouble, ft);}
cairo_set_source_rgba(cr, vv, wv, xv, yv); cairo_set_source_rgba(cr, vv, wv, xv, yv);
ft=g_array_index((plt->ind), gint, k); ft=g_array_index((plt->ind), gint, k);
lt=g_array_index((plt->sizes), gint, k)+ft; if (ft>=(plot->ydata->len)) break;
st=g_array_index((plt->stride), gint, k);
lt=(g_array_index((plt->sizes), gint, k)*st)+ft;
if (lt>(plot->ydata->len)) lt=(plot->ydata->len);
for (ssx=MY_2PI; ssx>-10; ssx-=MY_2PI) for (ssx=MY_2PI; ssx>-10; ssx-=MY_2PI)
{ {
r=g_array_index((plot->rdata), gdouble, ft); r=g_array_index((plot->rdata), gdouble, ft);
Expand Down Expand Up @@ -2507,7 +2513,7 @@ static void draw(GtkWidget *widget, cairo_t *cr)
cairo_fill(cr); cairo_fill(cr);
cairo_move_to(cr, x, y); cairo_move_to(cr, x, y);
} }
for (j=1+ft; j<lt; j++) for (j=st+ft; j<lt; j+=st)
{ {
rn=g_array_index((plot->rdata), gdouble, j); rn=g_array_index((plot->rdata), gdouble, j);
tn=ssx+g_array_index((plot->thdata), gdouble, j); tn=ssx+g_array_index((plot->thdata), gdouble, j);
Expand Down Expand Up @@ -3284,7 +3290,10 @@ static void draw(GtkWidget *widget, cairo_t *cr)
{vv=g_array_index((plt->rd), gdouble, ft); wv=g_array_index((plt->gr), gdouble, ft); xv=g_array_index((plt->bl), gdouble, ft); yv=g_array_index((plt->al), gdouble, ft);} {vv=g_array_index((plt->rd), gdouble, ft); wv=g_array_index((plt->gr), gdouble, ft); xv=g_array_index((plt->bl), gdouble, ft); yv=g_array_index((plt->al), gdouble, ft);}
cairo_set_source_rgba(cr, vv, wv, xv, yv); cairo_set_source_rgba(cr, vv, wv, xv, yv);
ft=g_array_index((plt->ind), gint, k); ft=g_array_index((plt->ind), gint, k);
lt=g_array_index((plt->sizes), gint, k)+ft; if (ft>=(plot->ydata->len)) break;
st=g_array_index((plt->stride), gint, k);
lt=(g_array_index((plt->sizes), gint, k)*st)+ft;
if (lt>(plot->ydata->len)) lt=(plot->ydata->len);
for (ssx=MY_2PI; ssx>-10; ssx-=MY_2PI) for (ssx=MY_2PI; ssx>-10; ssx-=MY_2PI)
{ {
r=g_array_index((plot->rdata), gdouble, ft); r=g_array_index((plot->rdata), gdouble, ft);
Expand All @@ -3311,7 +3320,7 @@ static void draw(GtkWidget *widget, cairo_t *cr)
y=(priv->y0)-(drs*sin(th)); y=(priv->y0)-(drs*sin(th));
cairo_move_to(cr, x, y); cairo_move_to(cr, x, y);
} }
for (j=1+ft; j<lt; j++) for (j=st+ft; j<lt; j+=st)
{ {
rn=g_array_index((plot->rdata), gdouble, j); rn=g_array_index((plot->rdata), gdouble, j);
tn=ssx+g_array_index((plot->thdata), gdouble, j); tn=ssx+g_array_index((plot->thdata), gdouble, j);
Expand Down Expand Up @@ -4084,7 +4093,10 @@ static void draw(GtkWidget *widget, cairo_t *cr)
{vv=g_array_index((plt->rd), gdouble, ft); wv=g_array_index((plt->gr), gdouble, ft); xv=g_array_index((plt->bl), gdouble, ft); yv=g_array_index((plt->al), gdouble, ft);} {vv=g_array_index((plt->rd), gdouble, ft); wv=g_array_index((plt->gr), gdouble, ft); xv=g_array_index((plt->bl), gdouble, ft); yv=g_array_index((plt->al), gdouble, ft);}
cairo_set_source_rgba(cr, vv, wv, xv, yv); cairo_set_source_rgba(cr, vv, wv, xv, yv);
ft=g_array_index((plt->ind), gint, k); ft=g_array_index((plt->ind), gint, k);
lt=g_array_index((plt->sizes), gint, k)+ft; if (ft>=(plot->ydata->len)) break;
st=g_array_index((plt->stride), gint, k);
lt=(g_array_index((plt->sizes), gint, k)*st)+ft;
if (lt>(plot->ydata->len)) lt=(plot->ydata->len);
for (ssx=MY_2PI; ssx>-10; ssx-=MY_2PI) for (ssx=MY_2PI; ssx>-10; ssx-=MY_2PI)
{ {
r=g_array_index((plot->rdata), gdouble, ft); r=g_array_index((plot->rdata), gdouble, ft);
Expand All @@ -4111,7 +4123,7 @@ static void draw(GtkWidget *widget, cairo_t *cr)
y=(priv->y0)-(drs*sin(th)); y=(priv->y0)-(drs*sin(th));
cairo_move_to(cr, x, y); cairo_move_to(cr, x, y);
} }
for (j=1+ft; j<lt; j++) for (j=st+ft; j<lt; j+=st)
{ {
rn=g_array_index((plot->rdata), gdouble, j); rn=g_array_index((plot->rdata), gdouble, j);
tn=ssx+g_array_index((plot->thdata), gdouble, j); tn=ssx+g_array_index((plot->thdata), gdouble, j);
Expand Down Expand Up @@ -4885,8 +4897,11 @@ static void draw(GtkWidget *widget, cairo_t *cr)
{vv=g_array_index((plt->rd), gdouble, ft); wv=g_array_index((plt->gr), gdouble, ft); xv=g_array_index((plt->bl), gdouble, ft); yv=g_array_index((plt->al), gdouble, ft);} {vv=g_array_index((plt->rd), gdouble, ft); wv=g_array_index((plt->gr), gdouble, ft); xv=g_array_index((plt->bl), gdouble, ft); yv=g_array_index((plt->al), gdouble, ft);}
cairo_set_source_rgba(cr, vv, wv, xv, yv); cairo_set_source_rgba(cr, vv, wv, xv, yv);
ft=g_array_index((plt->ind), gint, k); ft=g_array_index((plt->ind), gint, k);
lt=g_array_index((plt->sizes), gint, k)+ft; if (ft>=(plot->ydata->len)) break;
for (j=ft; j<lt; j++) st=g_array_index((plt->stride), gint, k);
lt=(g_array_index((plt->sizes), gint, k)*st)+ft;
if (lt>(plot->ydata->len)) lt=(plot->ydata->len);
for (j=ft+st; j<lt; j+=st)
{ {
r=g_array_index((plot->rdata), gdouble, j); r=g_array_index((plot->rdata), gdouble, j);
th=g_array_index((plot->thdata), gdouble, j); th=g_array_index((plot->thdata), gdouble, j);
Expand Down
54 changes: 33 additions & 21 deletions gtk2plot/testplotlinear.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ void prt(GtkWidget *widget, gpointer data)


void opd(GtkWidget *widget, gpointer data) void opd(GtkWidget *widget, gpointer data)
{ {
GArray *x, *y, *sz, *nx; GArray *nx, *st, *sz, *x, *y;
GtkPlotLinear *plt; GtkPlotLinear *plt;
GtkWidget *wfile; GtkWidget *wfile;
gdouble xi, xf, lcl, mny, mxy; gdouble xi, xf, lcl, mny, mxy;
Expand All @@ -339,8 +339,9 @@ void opd(GtkWidget *widget, gpointer data)
sal=g_strv_length(strary); sal=g_strv_length(strary);
x=g_array_new(FALSE, FALSE, sizeof(gdouble)); x=g_array_new(FALSE, FALSE, sizeof(gdouble));
y=g_array_new(FALSE, FALSE, sizeof(gdouble)); y=g_array_new(FALSE, FALSE, sizeof(gdouble));
sz=g_array_new(FALSE, FALSE, sizeof(gint)); st=g_array_sized_new(FALSE, FALSE, sizeof(gint), 1);
nx=g_array_new(FALSE, FALSE, sizeof(gint)); sz=g_array_sized_new(FALSE, FALSE, sizeof(gint), 1);
nx=g_array_sized_new(FALSE, FALSE, sizeof(gint), 1);
lc=0; lc=0;
for (k=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(jind)); k<sal; k++) for (k=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(jind)); k<sal; k++)
{ {
Expand Down Expand Up @@ -368,10 +369,12 @@ void opd(GtkWidget *widget, gpointer data)
g_array_append_val(sz, lc); g_array_append_val(sz, lc);
k=0; k=0;
g_array_append_val(nx, k); g_array_append_val(nx, k);
k=1;
g_array_append_val(st, k);
xi=g_array_index(x, gdouble, 0); xi=g_array_index(x, gdouble, 0);
xf=g_array_index(x, gdouble, (lc-1)); xf=g_array_index(x, gdouble, (lc-1));
gtk_plot_linear_set_data(plt, x, y, nx, sz); gtk_plot_linear_set_data(plt, x, y, nx, sz, st);
{g_array_unref(x); g_array_unref(y); g_array_unref(nx); g_array_unref(sz);} {g_array_unref(x); g_array_unref(y); g_array_unref(nx); g_array_unref(sz); g_array_unref(st);}
gtk_plot_linear_update_scale(plot, xi, xf, mny, mxy); gtk_plot_linear_update_scale(plot, xi, xf, mny, mxy);
} }
else else
Expand All @@ -388,16 +391,16 @@ void opd(GtkWidget *widget, gpointer data)


void ad(GtkWidget *widget, gpointer data) void ad(GtkWidget *widget, gpointer data)
{ {
GArray *x, *y, *sz, *nx; GArray *nx, *st, *sz, *x, *y;
gchar *contents, *fin=NULL, *str;
gchar **strary, **strat;
gdouble lcl, mny, mxy, xi, xf;
GError *Err;
gint lc, lc2;
GtkPlot *pt; GtkPlot *pt;
GtkPlotLinear *plt; GtkPlotLinear *plt;
GtkWidget *wfile; GtkWidget *wfile;
gdouble xi, xf, lcl, mny, mxy;
guint k, sal; guint k, sal;
gint lc, lc2;
gchar *contents, *str, *fin=NULL;
gchar **strary, **strat;
GError *Err;


wfile=gtk_file_chooser_dialog_new("Select Data File", GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); wfile=gtk_file_chooser_dialog_new("Select Data File", GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
g_signal_connect(G_OBJECT(wfile), "destroy", G_CALLBACK(gtk_widget_destroy), G_OBJECT(wfile)); g_signal_connect(G_OBJECT(wfile), "destroy", G_CALLBACK(gtk_widget_destroy), G_OBJECT(wfile));
Expand All @@ -415,11 +418,16 @@ void ad(GtkWidget *widget, gpointer data)
pt=GTK_PLOT(plot); pt=GTK_PLOT(plot);
x=g_array_new(FALSE, FALSE, sizeof(gdouble)); x=g_array_new(FALSE, FALSE, sizeof(gdouble));
y=g_array_new(FALSE, FALSE, sizeof(gdouble)); y=g_array_new(FALSE, FALSE, sizeof(gdouble));
st=g_array_new(FALSE, FALSE, sizeof(gint));
sz=g_array_new(FALSE, FALSE, sizeof(gint)); sz=g_array_new(FALSE, FALSE, sizeof(gint));
nx=g_array_new(FALSE, FALSE, sizeof(gint)); nx=g_array_new(FALSE, FALSE, sizeof(gint));
{sal=0; lc=0; lc2=0;} lc=1;
g_array_append_val(st, lc);
{sal=0; lc=0;}
while (sal<(pt->sizes->len)) while (sal<(pt->sizes->len))
{ {
lc=1;
g_array_append_val(st, lc);
lc2=g_array_index((pt->ind), gint, sal); lc2=g_array_index((pt->ind), gint, sal);
g_array_append_val(nx, lc2); g_array_append_val(nx, lc2);
lc=g_array_index((pt->sizes), gint, sal); lc=g_array_index((pt->sizes), gint, sal);
Expand Down Expand Up @@ -463,8 +471,8 @@ void ad(GtkWidget *widget, gpointer data)
gtk_statusbar_push(GTK_STATUSBAR(statusbar), gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), str), str); gtk_statusbar_push(GTK_STATUSBAR(statusbar), gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), str), str);
g_free(str); g_free(str);
g_array_append_val(sz, lc); g_array_append_val(sz, lc);
gtk_plot_linear_set_data(plt, x, y, nx, sz); gtk_plot_linear_set_data(plt, x, y, nx, sz, st);
{g_array_unref(x); g_array_unref(y); g_array_unref(nx); g_array_unref(sz);} {g_array_unref(x); g_array_unref(y); g_array_unref(nx); g_array_unref(sz); g_array_unref(st);}
gtk_plot_linear_update_scale(plot, xi, xf, mny, mxy); gtk_plot_linear_update_scale(plot, xi, xf, mny, mxy);
} }
else else
Expand Down Expand Up @@ -505,14 +513,14 @@ void upg(GtkWidget *widget, gpointer data)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
AtkObject *atk_widget, *atk_label; AtkObject *atk_widget, *atk_label;
GArray *x, *y, *sz, *nx, *car, *cag, *cab, *caa; GArray *caa, *cab, *cag, *car, *nx, *sz, *x, *y;
gdouble fll, val;
GtkAccelGroup *accel_group=NULL;
GtkAdjustment *adj;
GtkPlot *pt; GtkPlot *pt;
GtkPlotLinear *plt; GtkPlotLinear *plt;
GtkWidget *vbox, *vbox2, *mnb, *mnu, *mni, *hpane, *butt, *label; GtkWidget *vbox, *vbox2, *mnb, *mnu, *mni, *hpane, *butt, *label;
GtkAdjustment *adj;
guint j; guint j;
gdouble fll, val;
GtkAccelGroup *accel_group=NULL;


gtk_init(&argc, &argv); gtk_init(&argc, &argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL); window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
Expand Down Expand Up @@ -593,11 +601,15 @@ int main(int argc, char *argv[])
g_signal_connect(plot, "moved", G_CALLBACK(pltmv), NULL); g_signal_connect(plot, "moved", G_CALLBACK(pltmv), NULL);
x=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 75); x=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 75);
y=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 75); y=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), 75);
sz=g_array_new(FALSE, FALSE, sizeof(gint)); st=g_array_sized_new(FALSE, FALSE, sizeof(gint), 2);
nx=g_array_new(FALSE, FALSE, sizeof(gint)); sz=g_array_sized_new(FALSE, FALSE, sizeof(gint), 2);
nx=g_array_sized_new(FALSE, FALSE, sizeof(gint), 2);
plt=GTK_PLOT_LINEAR(plot); plt=GTK_PLOT_LINEAR(plot);
pt=GTK_PLOT(plot); pt=GTK_PLOT(plot);
(plt->flagd)=3; (plt->flagd)=3;
j=1;
g_array_append_val(st, j);
g_array_append_val(st, j);
j=0; j=0;
g_array_append_val(nx, j); g_array_append_val(nx, j);
while (j<50) while (j<50)
Expand All @@ -622,7 +634,7 @@ int main(int argc, char *argv[])
} }
g_array_append_val(sz, j); g_array_append_val(sz, j);
gtk_plot_linear_set_data(plt, x, y, nx, sz); gtk_plot_linear_set_data(plt, x, y, nx, sz);
{g_array_unref(x); g_array_unref(y); g_array_unref(nx); g_array_unref(sz);} {g_array_unref(x); g_array_unref(y); g_array_unref(nx); g_array_unref(sz); g_array_unref(st);}
(plt->ptsize)=4; (plt->ptsize)=4;
car=g_array_new(FALSE, FALSE, sizeof(gdouble)); car=g_array_new(FALSE, FALSE, sizeof(gdouble));
cag=g_array_new(FALSE, FALSE, sizeof(gdouble)); cag=g_array_new(FALSE, FALSE, sizeof(gdouble));
Expand Down
Loading

0 comments on commit e824fb9

Please sign in to comment.