gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
Plot.H
Go to the documentation of this file.
1 /* Copyright 2000-2018 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 
18 #ifndef PLOT_H_
19 #define PLOT_H_
20 
21 #ifdef _MSC_VER
22 typedef unsigned int uint;
23 #pragma warning( disable : 4554)
24 #endif
25 
26 #include "ColourLineSpec.H"
27 #include "Table.H"
28 #include "Labels.H"
29 
30 #include <iostream>
31 #include <glib-object.h>
32 #include <gtk/gtk.h>
33 #include <gtkdatabox.h>
34 #include <gtkdatabox_points.h>
35 #include <gtkdatabox_lines.h>
36 #include <gtkdatabox_regions.h>
37 #include <gtkdatabox_ruler.h>
38 #include <gtkdatabox_grid.h>
39 #include <gtkdatabox_markers.h>
40 #include <gtkdatabox_offset_bars.h>
41 
42 #include <typeinfo>
43 #include <stdint.h>
44 //#include <vector>
45 //#include <stdlib.h>
46 //#include <string.h>
47 
48 using namespace std;
49 
89 class Plot : public Table {
95  template<typename TYPE>
96  GType findType(TYPE val) {
97  if (strcmp(typeid(val).name(), typeid(float).name())==0)
98  return G_TYPE_FLOAT;
99  if (strcmp(typeid(val).name(), typeid(double).name())==0)
100  return G_TYPE_DOUBLE;
101  if (strcmp(typeid(val).name(), typeid(int).name())==0)
102  return G_TYPE_INT;
103  if (strcmp(typeid(val).name(), typeid(unsigned int).name())==0)
104  return G_TYPE_UINT;
105  if (strcmp(typeid(val).name(), typeid(long).name())==0)
106  return G_TYPE_LONG;
107  if (strcmp(typeid(val).name(), typeid(unsigned long).name())==0)
108  return G_TYPE_ULONG;
109  if (strcmp(typeid(val).name(), typeid(int64_t).name())==0)
110  return G_TYPE_INT64;
111  if (strcmp(typeid(val).name(), typeid(uint64_t).name())==0)
112  return G_TYPE_UINT64;
113  if (strcmp(typeid(val).name(), typeid(char).name())==0)
114  return G_TYPE_CHAR;
115  if (strcmp(typeid(val).name(), typeid(unsigned char).name())==0)
116  return G_TYPE_UCHAR;
117  return G_TYPE_INVALID;
118  }
119 protected:
120  GtkWidget *axis;
121  GtkDataboxGraph *gridGraph;
122  bool holdOn;
123  bool gridOn;
124 public:
125 
128  Plot(void) {
129  // We are going to manually place everything
130  setHomogeneous(false);
131  resize(5,4); // setup the default table to be x dimension : ylabel, yruler, plot, yruler, ylabel
132  // y dimension : title, plot, xruler, xlabel
133 
134  axis=gtk_databox_new ();
135  setOptions((GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK));
136  setRegion(2,3,1,2); // put the plot in the middle
137  *this<<axis; // put the plot in the middle
138 
139  GtkWidget *xRuler = gtk_databox_ruler_new (GTK_ORIENTATION_HORIZONTAL);
140  //gtk_databox_ruler_set_scale_type (GTK_DATABOX_RULER (xRuler), GTK_DATABOX(axis)->priv->scale_type_x);
141  gtk_databox_set_ruler_x (GTK_DATABOX(axis), GTK_DATABOX_RULER (xRuler));
142  GtkWidget *yRuler = gtk_databox_ruler_new (GTK_ORIENTATION_VERTICAL);
143  //gtk_databox_ruler_set_scale_type (GTK_DATABOX_RULER (yRuler), GTK_DATABOX(axis)->priv->scale_type_y);
144  gtk_databox_set_ruler_y (GTK_DATABOX(axis), GTK_DATABOX_RULER (yRuler));
145 
146  setOptions((GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), (GtkAttachOptions)(GTK_FILL));
147  setRegion(2,3,2,3); // put the x axis on the bottom
148  *this<<xRuler;
149  setOptions((GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK));
150  setRegion(1, 2, 1, 2); // put the y axis on the left
151  *this<<yRuler;
152 
153  show();
154 
155  setBackground("w"); // default white colour
156 
157  gridGraph=NULL;
158  }
159 
163  void setBackground(const char *clsStr) {
164  setBackground(ColourLineSpec(clsStr));
165  }
166 
171 #if GTK_MAJOR_VERSION>2
172  GdkRGBA gdkC=cls.getColour();
173 #else
174  GdkColor gdkC=cls.getColour();
175 #endif
176  setBackground(gdkC);
177  }
178 
182 #if GTK_MAJOR_VERSION>2
183  void setBackground(const GdkRGBA gdkC) {
184  gtk_widget_override_background_color(axis, GTK_STATE_FLAG_NORMAL, &gdkC);
185 #else
186  void setBackground(const GdkColor gdkC) {
187  gtk_widget_modify_bg(axis, GTK_STATE_NORMAL, &gdkC); // set the background
188 #endif
189  }
190 
194  GtkWidget *gca(void) {
195  return getCurrentAxis();
196  }
197 
201  GtkWidget *getCurrentAxis(void) {
202  return axis;
203  }
204 
207  void show(void) {
208  gtk_widget_show_all(axis);
209  gtk_widget_show_all(getWidget());
210  }
211  void hide(void) {
212  gtk_widget_hide(axis);
213  gtk_widget_hide(getWidget());
214  }
215 
216 //#if GTK_MAJOR_VERSION>2
217 // /* Plots the cnt y values at x to the axis, with a default blue colour
218 // \param x The ordinates for plotting
219 // \param y The co-ordinates for plotting
220 // \param cnt The number of elements to plot
221 // \return the graph which was just added.
222 // \tparam XTYPE The type of the ordinate
223 // \tparam YTYPE The type of the co-ordinate
224 // */
225 // template<typename XTYPE, typename YTYPE>
226 // GtkDataboxGraph *plot(XTYPE *x, YTYPE *y, int cnt) {
227 //#else
234  GtkDataboxGraph * plot(gfloat *x, gfloat *y, int cnt) {
235 //#endif
236  ColourLineSpec cls;
237  return plot(x, y, cnt, cls);
238  }
239 
240 //#if GTK_MAJOR_VERSION>2
241 // /* Plots the cnt y values at x to the axis, with a specified colour and line type
242 // \param x The ordinates for plotting
243 // \param y The co-ordinates for plotting
244 // \param cnt The number of elements to plot
245 // \param clsChar The specification to be used with the ColourLineSpec class
246 // \return the graph which was just added.
247 // \tparam XTYPE The type of the ordinate
248 // \tparam YTYPE The type of the co-ordinate
249 // */
250 // template<typename XTYPE, typename YTYPE>
251 // GtkDataboxGraph *plot(XTYPE *x, YTYPE *y, int cnt, const char *clsChar) {
252 //#else
260  GtkDataboxGraph *plot(gfloat *x, gfloat *y, int cnt, const char *clsChar) {
261 //#endif
262  ColourLineSpec cls(clsChar);
263  return plot(x, y, cnt, cls);
264  }
265 
266 //#if GTK_MAJOR_VERSION<3
267  /* Plots the cnt y values at x to the axis
268  \param x The ordinates for plotting
269  \param y The co-ordinates for plotting
270  \param cnt The number of elements to plot
271  \param cls The ColourLineSpec class which determines the colour line type and size
272  \return the graph which was just added.
273  */
274  GtkDataboxGraph *plot(gfloat *x, gfloat *y, int cnt, ColourLineSpec &cls) {
275  if (!holdOn) {
276  clf();
277  if (gridOn)
278  grid(gridOn);
279  }
280 
281  //if (gtk_widget_get_realized (axis)){
282  GtkDataboxGraph *graph=NULL;
283 #if GTK_MAJOR_VERSION>2
284  GdkRGBA gdkC=cls.getColour();
285 #else
286  GdkColor gdkC=cls.getColour();
287 #endif
288  int size=cls.getSize();
289  if (cls.linePlot)
290  graph = gtk_databox_lines_new (cnt, x, y, &gdkC, size);
291  else
292  graph = gtk_databox_points_new (cnt, x, y, &gdkC, size);
293  gtk_databox_graph_add_front (GTK_DATABOX (axis), graph);
294  //}
295  return graph;
296  }
297 //#else
298 // /* Plots the cnt y values at x to the axis
299 // \param x The ordinates for plotting
300 // \param y The co-ordinates for plotting
301 // \param cnt The number of elements to plot
302 // \param cls The ColourLineSpec class which determines the colour line type and size
303 // \return the graph which was just added.
304 // \tparam XTYPE The type of the ordinate
305 // \tparam YTYPE The type of the co-ordinate
306 // */
307 // template<typename XTYPE, typename YTYPE>
308 // GtkDataboxGraph *plot(XTYPE *x, YTYPE *y, int cnt, const ColourLineSpec &cls) {
309 // if (cnt<=0)
310 // return NULL;
311 // GType xType, yType;
312 // if ((xType=findType(x[0]))==G_TYPE_INVALID)
313 // return NULL;
314 // if ((yType=findType(y[0]))==G_TYPE_INVALID)
315 // return NULL;
316 //
317 // if (!holdOn) {
318 // clf();
319 // if (gridOn)
320 // grid(gridOn);
321 // }
322 //
323 // GtkDataboxGraph *graph=NULL;
324 //#if GTK_MAJOR_VERSION>2
325 // GdkRGBA gdkC=cls.getColour();
326 //#else
327 // GdkColor gdkC=cls.getColour();
328 //#endif
329 // int size=cls.getSize();
330 // if (cls.linePlot)
331 // graph = gtk_databox_lines_new_full (cnt, cnt, x, 0, 1, xType, y, 0, 1, yType, &gdkC, size);
332 // else
333 // graph = gtk_databox_points_new_full (cnt, cnt, x, 0, 1, xType, y, 0, 1, yType, &gdkC, size);
334 // gtk_databox_graph_add_front (GTK_DATABOX (axis), graph);
335 // return graph;
336 // }
337 //#endif
338 
347  GtkDataboxGraph *plot(gfloat *x, gfloat *y1, gfloat *y2, int cnt) {
348  ColourLineSpec cls;
349  return plot(x, y1, y2, cnt, cls);
350  }
351 
362  GtkDataboxGraph *plot(gfloat *x, gfloat *y1, gfloat *y2, int cnt, const char *clsChar) {
363  ColourLineSpec cls(clsChar);
364  return plot(x, y1, y2, cnt, cls);
365  }
366 
377  GtkDataboxGraph *plot(gfloat *x, gfloat *y1, gfloat *y2, int cnt, ColourLineSpec &cls) {
378  if (!holdOn) {
379  clf();
380  if (gridOn)
381  grid(gridOn);
382  }
383 
384  //if (gtk_widget_get_realized (axis)) {
385  GtkDataboxGraph *graph=NULL;
386 #if GTK_MAJOR_VERSION>2
387  GdkRGBA gdkC=cls.getColour();
388 #else
389  GdkColor gdkC=cls.getColour();
390 #endif
391  int size=cls.getSize();
392  if (cls.linePlot)
393  graph = gtk_databox_regions_new (cnt, x, y1, y2, &gdkC);
394  else
395  graph = gtk_databox_offset_bars_new(cnt, x, y1, y2, &gdkC, size);
396  gtk_databox_graph_add_front (GTK_DATABOX (axis), graph);
397  //}
398  return graph;
399  }
400 
408  GtkDataboxGraph * semilogx(gfloat *x, gfloat *y, int cnt) {
409  ColourLineSpec cls;
410  return semilogx(x, y, cnt, cls);
411  }
412 
421  GtkDataboxGraph * semilogx(gfloat *x, gfloat *y, int cnt, const char *clsChar) {
422  ColourLineSpec cls(clsChar);
423  return semilogx(x, y, cnt, cls);
424  }
425 
434  GtkDataboxGraph *semilogx(gfloat *x, gfloat *y, int cnt, ColourLineSpec &cls) {
435  GtkDataboxGraph *graph=plot(x, y, cnt, cls);
436  gtk_databox_set_scale_type_x (GTK_DATABOX (axis), GTK_DATABOX_SCALE_LOG);
437  return graph;
438  }
439 
449  GtkDataboxGraph *semilogx(gfloat *x, gfloat *y1, gfloat *y2, int cnt) {
450  ColourLineSpec cls;
451  return semilogx(x, y1, y2, cnt, cls);
452  }
453 
465  GtkDataboxGraph *semilogx(gfloat *x, gfloat *y1, gfloat *y2, int cnt, const char *clsChar) {
466  ColourLineSpec cls(clsChar);
467  return semilogx(x, y1, y2, cnt, cls);
468  }
469 
481  GtkDataboxGraph *semilogx(gfloat *x, gfloat *y1, gfloat *y2, int cnt, ColourLineSpec &cls) {
482  GtkDataboxGraph *graph=plot(x, y1, y2, cnt, cls);
483  //if (gtk_widget_get_realized (axis))
484  if (gtk_databox_get_scale_type_x(GTK_DATABOX (axis))!=GTK_DATABOX_SCALE_LOG)
485  gtk_databox_set_scale_type_x (GTK_DATABOX (axis), GTK_DATABOX_SCALE_LOG);
486  return graph;
487  }
488 
496  GtkDataboxGraph *semilogy(gfloat *x, gfloat *y, int cnt) {
497  ColourLineSpec cls;
498  return semilogy(x, y, cnt, cls);
499  }
500 
509  GtkDataboxGraph *semilogy(gfloat *x, gfloat *y, int cnt, const char *clsChar) {
510  ColourLineSpec cls(clsChar);
511  return semilogy(x, y, cnt, cls);
512  }
513 
522  GtkDataboxGraph *semilogy(gfloat *x, gfloat *y, int cnt, ColourLineSpec &cls) {
523  GtkDataboxGraph *graph=plot(x, y, cnt, cls);
524  //if (gtk_widget_get_realized (axis))
525 
526  if (gtk_databox_get_scale_type_y(GTK_DATABOX (axis))!=GTK_DATABOX_SCALE_LOG)
527  gtk_databox_set_scale_type_y (GTK_DATABOX (axis), GTK_DATABOX_SCALE_LOG);
528  return graph;
529  }
530 
538  GtkDataboxGraph *loglog(gfloat *x, gfloat *y, int cnt) {
539  ColourLineSpec cls;
540  return loglog(x, y, cnt, cls);
541  }
542 
551  GtkDataboxGraph *loglog(gfloat *x, gfloat *y, int cnt, const char *clsChar) {
552  ColourLineSpec cls(clsChar);
553  return loglog(x, y, cnt, cls);
554  }
563  GtkDataboxGraph *loglog(gfloat *x, gfloat *y, int cnt, ColourLineSpec &cls) {
564  GtkDataboxGraph *graph=plot(x, y, cnt, cls);
565  if (gtk_databox_get_scale_type_x(GTK_DATABOX (axis))!=GTK_DATABOX_SCALE_LOG)
566  gtk_databox_set_scale_type_x (GTK_DATABOX (axis), GTK_DATABOX_SCALE_LOG);
567  if (gtk_databox_get_scale_type_y(GTK_DATABOX (axis))!=GTK_DATABOX_SCALE_LOG)
568  gtk_databox_set_scale_type_y (GTK_DATABOX (axis), GTK_DATABOX_SCALE_LOG);
569  return graph;
570  }
571 
578  GtkDataboxGraph * text(gfloat *x, gfloat *y, const char *textDisp, const char *clsChar) {
579  ColourLineSpec cls(clsChar);
580  return text(x, y, textDisp, cls);
581  }
582 
590  GtkDataboxGraph *text(gfloat *x, gfloat *y, const char *textDisp, ColourLineSpec &cls) {
591 #if GTK_MAJOR_VERSION>2
592  GdkRGBA gdkC=cls.getColour();
593 #else
594  GdkColor gdkC=cls.getColour();
595 #endif
596  GtkDataboxGraph *graph = gtk_databox_markers_new (1, x, y, &gdkC, 1, GTK_DATABOX_MARKERS_NONE);
597  bool boxed=false;
598  gtk_databox_markers_set_label (GTK_DATABOX_MARKERS (graph), 0, GTK_DATABOX_MARKERS_TEXT_CENTER, (gchar*)textDisp, boxed);
599  gtk_databox_graph_add_front (GTK_DATABOX (axis), graph);
600  return graph;
601  }
602 
605  void clear(void) {
606  clf();
607  }
608 
611  void clf(void) {
612  //if (gtk_widget_get_realized (axis))
613  gtk_databox_graph_remove_all(GTK_DATABOX (axis));
614  }
615 
618  void hold(bool on) {
619  holdOn=on;
620  }
621 
626  void grid(bool on) {
627  if (gridGraph) {
628  GtkDataboxGrid *gridG=GTK_DATABOX_GRID(gridGraph);
629  if (gtk_databox_grid_get_hline_vals(gridG)) { // reuse previously stored graph
630  grid(on, gtk_databox_grid_get_hlines(gridG), gtk_databox_grid_get_hline_vals(gridG), gtk_databox_grid_get_vlines(gridG), gtk_databox_grid_get_vline_vals(gridG));
631  return;
632  }
633  }
634  grid(on, 5, NULL, 5, NULL);
635  }
636 
644  void grid(bool on, int hCnt, gfloat *hLines, int vCnt, gfloat *vLines) {
645  //if (gtk_widget_get_realized (axis))
646  if (on) {
647  if (gridGraph!=NULL) {
648  gtk_databox_graph_remove(GTK_DATABOX (axis), gridGraph);
649  gridGraph=NULL;
650  }
651  ColourLineSpec cls("a1"); // gray line of size 1
652 #if GTK_MAJOR_VERSION>2
653  GdkRGBA gdkC=cls.getColour();
654 #else
655  GdkColor gdkC=cls.getColour();
656 #endif
657  int size=cls.getSize();
658  if ((hLines!=NULL) & (vLines!=NULL))
659  gridGraph=gtk_databox_grid_array_new(hCnt, vCnt, hLines, vLines, &gdkC, size);
660  else
661  gridGraph=gtk_databox_grid_new(hCnt, vCnt, &gdkC, size);
662  gtk_databox_graph_add_front (GTK_DATABOX (axis), gridGraph);
663  } else {
664  if (gridGraph!=NULL) {
665  gtk_databox_graph_remove(GTK_DATABOX (axis), gridGraph);
666  }
667  }
668  gridOn=on;
669  }
670 
678  void limits(float min_x, float max_x, float min_y, float max_y) {
679  if (min_y==max_y) // fix if min and max y are the same
680  if (min_y==0.)
681  max_y=-(min_y=-1.);
682  else
683  max_y=(min_y=max_y*.9)/.9*1.1;
684  if (min_x==max_x) // fix if max and min y are the same
685  if (min_x==0.)
686  max_x=-(min_x=-1.);
687  else
688  max_x=(min_x=max_x*.9)/.9*1.1;
689  gtk_databox_set_total_limits (GTK_DATABOX (axis), min_x, max_x, max_y, min_y);
690  }
691 
696  void limits(gfloat border=0.) {
697  // guard against a plot with no real limits in either or both axes.
698  gfloat min_x, max_x, min_y, max_y;
699  gint extrema_success = gtk_databox_calculate_extrema (GTK_DATABOX (axis), &min_x, &max_x, &min_y, &max_y);
700  if (min_x==max_x==0.)
701  if (min_y==max_y==0.)
702  limits(0.,1.,0.,1.);
703  else
704  limits(min_x-(max_y-min_y)*.1, max_x-(max_y-min_y)*.1,min_y,max_y);
705  else if (min_y==max_y==0.)
706  limits(min_x, max_x, min_y-(max_x-min_x)*.1, max_y-(max_x-min_x)*.1);
707 
708  gtk_databox_auto_rescale(GTK_DATABOX (axis), border);
709  }
710 
715  void replot(void) {
716  if (gtk_widget_is_drawable (GTK_WIDGET (axis)))
717  gtk_widget_queue_draw (GTK_WIDGET (axis));
718  }
719 
780  void set(GtkWidget *widget, ...) {
781  va_list args;
782  va_start(args, widget);
783  //cout<<"starting"<<endl;
784  while (1) { // terminates when a null is read
785  char *token=va_arg(args, char *);
786  if ((token==NULL) | (token==(char *)'\0'))
787  break;
788 
789  // first attempt to process non-axis (box) settings
790  if ((strcmp(&token[1],"oxShadow")==0) | (strcmp(&token[1],"oxshadow")==0))
791  gtk_databox_set_box_shadow(GTK_DATABOX(widget), (GtkShadowType)va_arg(args, int));
792  else if ((strcmp(&token[1],"Scale")==0) | (strcmp(&token[1],"scale")==0)) {
793  char *linearOrLog=va_arg(args, char*);
794  if (tolower(token[0])=='x') {
795  if (strcmp(&linearOrLog[1],"og")==0) // check for the right keyword
796  gtk_databox_set_scale_type_x (GTK_DATABOX (axis), GTK_DATABOX_SCALE_LOG);
797  else
798  gtk_databox_set_scale_type_x (GTK_DATABOX (axis), GTK_DATABOX_SCALE_LINEAR);
799  }
800  if (tolower(token[0])=='y') {
801  if (strcmp(&linearOrLog[1],"og")==0) // check for the right keyword
802  gtk_databox_set_scale_type_y (GTK_DATABOX (axis), GTK_DATABOX_SCALE_LOG);
803  else
804  gtk_databox_set_scale_type_y (GTK_DATABOX (axis), GTK_DATABOX_SCALE_LINEAR);
805  }
806  } else {
807  // process axis (ruler) settings
808  GtkDataboxRuler *ruler;
809  bool xRuler=1;
810  if (tolower(token[0])=='x')
811  ruler=gtk_databox_get_ruler_x(GTK_DATABOX (widget));
812  else {
813  ruler=gtk_databox_get_ruler_y(GTK_DATABOX (widget));
814  xRuler=0;
815  }
816 
817  if ((strcmp(&token[1],"MinorTick")==0) | (strcmp(&token[1],"minortick")==0)) {
818 
819  int draw_ticks=va_arg(args, int);
820  gtk_databox_ruler_set_draw_subticks(ruler,draw_ticks);
821 
822  } else if ((strcmp(&token[1],"Tick")==0) | (strcmp(&token[1],"tick")==0)) {
823  uint manual_tick_cnt=va_arg(args, int);
824  if (manual_tick_cnt==0)
825  gtk_databox_ruler_set_draw_ticks(ruler,manual_tick_cnt);
826  else {
827  gtk_databox_ruler_set_manual_tick_cnt(ruler, manual_tick_cnt);
828  gtk_databox_ruler_set_manual_ticks(ruler, va_arg(args, gfloat*));
829  }
830  } else if ((strcmp(&token[1],"LabelFormat")==0) | (strcmp(&token[1],"labelformat")==0)) {
831  int scaleType;
832  if (xRuler)
833  scaleType=gtk_databox_get_scale_type_x(GTK_DATABOX (widget));
834  else
835  scaleType=gtk_databox_get_scale_type_y(GTK_DATABOX (widget));
836 
837  if (scaleType==GTK_DATABOX_SCALE_LINEAR) // set the label format
838  gtk_databox_ruler_set_linear_label_format(ruler, va_arg(args, char*));
839  else
840  gtk_databox_ruler_set_log_label_format(ruler, va_arg(args, char*));
841 
842  } else if ((strcmp(&token[1],"LabelLength")==0) | (strcmp(&token[1],"labellength")==0)) {
843  int scaleType;
844  if (xRuler)
845  scaleType=gtk_databox_get_scale_type_x(GTK_DATABOX (widget));
846  else
847  scaleType=gtk_databox_get_scale_type_y(GTK_DATABOX (widget));
848 
849  gtk_databox_ruler_set_max_length(ruler, va_arg(args, int));
850  } else if ((strcmp(&token[1],"LabelLength")==0) | (strcmp(&token[1],"labellength")==0)) {
851  gtk_databox_ruler_set_max_length(ruler, va_arg(args, int));
852  } else if ((strcmp(&token[1],"TickLabel")==0) | (strcmp(&token[1],"ticklabel")==0)) {
853  gtk_databox_ruler_set_manual_tick_labels(ruler, (gchar**)va_arg(args, gchar**));
854  } else if ((strcmp(&token[1],"TickXOffset")==0) | (strcmp(&token[1],"tickxoffset")==0)) {
855  gtk_databox_ruler_set_text_hoffset(ruler, va_arg(args, int));
856  } else if ((strcmp(&token[1],"Position")==0) | (strcmp(&token[1],"position")==0)) {
857  gtk_databox_ruler_set_draw_position(ruler, va_arg(args, int));
858  } else if ((strcmp(&token[1],"Shadow")==0) | (strcmp(&token[1],"shadow")==0)) {
859  gtk_databox_ruler_set_box_shadow(ruler, (GtkShadowType)va_arg(args, int));
860  } else if ((strcmp(&token[1],"LabelAlignment")==0) | (strcmp(&token[1],"labelalignment")==0)) {
861  char *which=va_arg(args, char*);
862  if (strcmp(&which[1],"ight")==0) // check for the right keyword
863  gtk_databox_ruler_set_text_alignment(ruler, PANGO_ALIGN_RIGHT);
864  else if (strcmp(&which[1],"enter")==0) // check for the center keyword
865  gtk_databox_ruler_set_text_alignment(ruler, PANGO_ALIGN_CENTER);
866  else // left aligned which is standard
867  gtk_databox_ruler_set_text_alignment(ruler, PANGO_ALIGN_LEFT);
868  } else if ((strcmp(&token[1],"LabelRotate")==0) | (strcmp(&token[1],"labelrotate")==0)) {
869  char *which=va_arg(args, char*);
870  if (strcmp(&which[1],"ertical")==0) // check for the vertical keyword
871  gtk_databox_ruler_set_text_orientation(ruler, GTK_ORIENTATION_VERTICAL);
872  else
873  gtk_databox_ruler_set_text_orientation(ruler, GTK_ORIENTATION_HORIZONTAL);
874  }
875 
876  if (tolower(token[0])=='x')
877  gtk_databox_set_ruler_x(GTK_DATABOX (widget), ruler);
878  else
879  gtk_databox_set_ruler_y(GTK_DATABOX (widget), ruler);
880  }
881  }
882  va_end(args);
883  }
884 
890  void connectAfter(const char *event, GCallback callback, gpointer data) {
891  g_signal_connect_after(axis, event, callback, data);
892  }
893 
905  void xLabel(const char* label, int *indexes=NULL) {
906  if (indexes==NULL) {
907  setRegion(2, 3, 3, 4);
908  setOptions((GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), (GtkAttachOptions)(GTK_FILL));
909  } else
910  *this<<indexes;
911  *this<<(Labels()<<label).setAlignment(0.5, 0.5);
912  }
913 
918  void xLabelBL(const char* label) {
919  setOptions((GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_FILL | GTK_SHRINK));
920  int indexes[]= {1,2,2,3};
921  xLabel(label,indexes);
922  }
923 
935  void yLabel(const char* label, int *indexes=NULL) {
936  Labels ylabel;
937  ylabel<<label;
938  if (indexes==NULL) {
939  setRegion(0, 1, 1, 2);
940  setOptions((GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK));
941  ylabel.setAngle(90.0);
942  } else
943  *this<<indexes;
944  ylabel.setAlignment(0.5, 0.5);
945  *this<<ylabel.current();
946  }
947 
952  void yLabelTL(const char* label) {
953  setOptions((GtkAttachOptions)(GTK_FILL | GTK_SHRINK), (GtkAttachOptions)(GTK_FILL));
954  int indexes[]= {1,2,0,1};
955  yLabel(label,indexes);
956  }
957 
965  void title(const char* titleStr, int *indexes=NULL) {
966  Labels labels;
967  labels<<titleStr;
968  labels.setAlignment(0.5, 0.5);
969  title(labels.getWidget(), indexes);
970  }
971 
979  void title(GtkWidget *widget, int *indexes=NULL) {
980  if (indexes==NULL) {
981  setRegion(2, 3, 0, 1);
982  setOptions((GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), (GtkAttachOptions)(GTK_FILL));
983  } else
984  *this<<indexes;
985  *this<<widget;
986  }
987 //static bool expose(GtkWidget *widget, GdkEventExpose *event, gpointer data){
988 // Plot*p=static_cast<Plot*>(data);
989 // p->replot();
990 // return false;
991 //}
992 // cout<<"Plot::expose"<<endl;
993 // if (gtk_widget_get_realized (axis))
994 // return false;
995 // else
996 // return true;
997 //}
1001  void remove(GtkDataboxGraph *toRemove) {
1002  gtk_databox_graph_remove (GTK_DATABOX (axis), toRemove);
1003  }
1004 
1009  Plot &operator>>(GtkDataboxGraph *toRemove) {
1010  remove(toRemove);
1011  return *this;
1012  }
1013 
1016  gfloat pixelToX(gint16 pixel) {
1017  return gtk_databox_pixel_to_value_x(GTK_DATABOX (axis), pixel);
1018  }
1019 
1022  gfloat pixelToY(gint16 pixel) {
1023  return gtk_databox_pixel_to_value_y(GTK_DATABOX (axis), pixel);
1024  }
1025 };
1026 #endif //PLOT_H_
void limits(float min_x, float max_x, float min_y, float max_y)
Set the limits of the viewable region of the plot. This will set the viewable rectangle to be between...
Definition: Plot.H:678
float * x
size(signal)
void yLabelTL(const char *label)
Definition: Plot.H:952
Plot(void)
Definition: Plot.H:128
class to create and handle labels.
Definition: Labels.H:58
void clf(void)
Definition: Plot.H:611
Plot & operator>>(GtkDataboxGraph *toRemove)
Definition: Plot.H:1009
float getSize(void) const
GtkDataboxGraph * semilogx(gfloat *x, gfloat *y1, gfloat *y2, int cnt, ColourLineSpec &cls)
Plots with a logarithmic ordinate scale Plotting the data with a logarithmic ordinate scale and a def...
Definition: Plot.H:481
GtkWidget * getWidget(void)
returns the current GtkWidget* in the list
Definition: Labels.H:102
void connectAfter(const char *event, GCallback callback, gpointer data)
Definition: Plot.H:890
simplistic plotting class which mimicks a octave approach to plotting Use this class as if you were p...
Definition: Plot.H:89
void setBackground(const char *clsStr)
Definition: Plot.H:163
void title(const char *titleStr, int *indexes=NULL)
Definition: Plot.H:965
GtkDataboxGraph * semilogy(gfloat *x, gfloat *y, int cnt, ColourLineSpec &cls)
Plots with a logarithmic co-ordinate scale Plotting the data with a logarithmic co-ordinate scale...
Definition: Plot.H:522
STL namespace.
GtkDataboxGraph * plot(gfloat *x, gfloat *y, int cnt, ColourLineSpec &cls)
Definition: Plot.H:274
gfloat pixelToY(gint16 pixel)
Definition: Plot.H:1022
GdkColor getColour(void)
void hide(void)
Definition: Plot.H:211
void grid(bool on, int hCnt, gfloat *hLines, int vCnt, gfloat *vLines)
Definition: Plot.H:644
GtkDataboxGraph * semilogx(gfloat *x, gfloat *y, int cnt)
Plots with a logarithmic ordinate scale Plotting the data with a logarithmic ordinate scale and a def...
Definition: Plot.H:408
void show(void)
Definition: Plot.H:207
GtkWidget * axis
The axis widget.
Definition: Plot.H:120
GtkWidget * setAlignment(float xalign, float yalign)
Definition: Labels.H:143
void setAngle(double angle)
Definition: Labels.H:178
GtkDataboxGraph * plot(gfloat *x, gfloat *y, int cnt)
Definition: Plot.H:234
gfloat pixelToX(gint16 pixel)
Definition: Plot.H:1016
GtkDataboxGraph * plot(gfloat *x, gfloat *y1, gfloat *y2, int cnt, ColourLineSpec &cls)
Definition: Plot.H:377
GtkDataboxGraph * plot(gfloat *x, gfloat *y1, gfloat *y2, int cnt)
Definition: Plot.H:347
void setBackground(ColourLineSpec cls)
Definition: Plot.H:170
GtkDataboxGraph * text(gfloat *x, gfloat *y, const char *textDisp, ColourLineSpec &cls)
Definition: Plot.H:590
GtkDataboxGraph * semilogx(gfloat *x, gfloat *y, int cnt, ColourLineSpec &cls)
Plots with a logarithmic ordinate scale Plotting the data with a logarithmic ordinate scale...
Definition: Plot.H:434
unsigned int uint
Definition: Box.H:28
void title(GtkWidget *widget, int *indexes=NULL)
Definition: Plot.H:979
void yLabel(const char *label, int *indexes=NULL)
Definition: Plot.H:935
void setBackground(const GdkColor gdkC)
Definition: Plot.H:186
GtkWidget * getCurrentAxis(void)
Get the current axis.
Definition: Plot.H:201
GtkDataboxGraph * semilogx(gfloat *x, gfloat *y1, gfloat *y2, int cnt, const char *clsChar)
Plots with a logarithmic ordinate scale Plotting the data with a logarithmic ordinate scale and a def...
Definition: Plot.H:465
GtkDataboxGraph * loglog(gfloat *x, gfloat *y, int cnt, const char *clsChar)
Plots with logarithmic ordingate and co-ordinate scales Plotting the data with logarithmic ordinate a...
Definition: Plot.H:551
void replot(void)
Instruct gtk to replot If the underlying plot data pointers haven&#39;t changed, it is not necessary to c...
Definition: Plot.H:715
GtkDataboxGraph * semilogy(gfloat *x, gfloat *y, int cnt)
Plots with a logarithmic co-ordinate scale Plotting the data with a logarithmic co-ordinate scale and...
Definition: Plot.H:496
GtkDataboxGraph * text(gfloat *x, gfloat *y, const char *textDisp, const char *clsChar)
Definition: Plot.H:578
GType findType(TYPE val)
Definition: Plot.H:96
GtkDataboxGraph * semilogx(gfloat *x, gfloat *y1, gfloat *y2, int cnt)
Plots with a logarithmic ordinate scale Plotting the data with a logarithmic ordinate scale and a def...
Definition: Plot.H:449
void xLabel(const char *label, int *indexes=NULL)
Definition: Plot.H:905
void grid(bool on)
Definition: Plot.H:626
float * y
void clear(void)
Definition: Plot.H:605
GtkDataboxGraph * gridGraph
The grid which defaults to off.
Definition: Plot.H:121
void xLabelBL(const char *label)
Definition: Plot.H:918
GtkDataboxGraph * semilogy(gfloat *x, gfloat *y, int cnt, const char *clsChar)
Plots with a logarithmic co-ordinate scale Plotting the data with a logarithmic co-ordinate scale...
Definition: Plot.H:509
void hold(bool on)
Definition: Plot.H:618
GtkDataboxGraph * semilogx(gfloat *x, gfloat *y, int cnt, const char *clsChar)
Plots with a logarithmic ordinate scale Plotting the data with a logarithmic ordinate scale...
Definition: Plot.H:421
Definition: Table.H:43
GtkWidget * gca(void)
Get the current axis.
Definition: Plot.H:194
bool holdOn
Whether to hold the curves or not.
Definition: Plot.H:122
GtkDataboxGraph * loglog(gfloat *x, gfloat *y, int cnt, ColourLineSpec &cls)
Plots with logarithmic ordingate and co-ordinate scales Plotting the data with logarithmic ordinate a...
Definition: Plot.H:563
GtkDataboxGraph * plot(gfloat *x, gfloat *y1, gfloat *y2, int cnt, const char *clsChar)
Definition: Plot.H:362
void limits(gfloat border=0.)
Set the limits to autoscale Rescales the figure to show everything plotted.
Definition: Plot.H:696
GtkDataboxGraph * loglog(gfloat *x, gfloat *y, int cnt)
Plots with logarithmic ordingate and co-ordinate scales Plotting the data with logarithmic ordinate a...
Definition: Plot.H:538
bool gridOn
Whether to the grid is on.
Definition: Plot.H:123
GtkDataboxGraph * plot(gfloat *x, gfloat *y, int cnt, const char *clsChar)
Definition: Plot.H:260
bool linePlot
The indication for lines or points plotting.
encapsulates a method to specify colour and line or point plotting This class tries to encapsulate oc...
gtkIOStream: /tmp/gtkiostream/include/Plot.H Source File
GTK+ IOStream  Beta