22 typedef unsigned int uint;
23 #pragma warning( disable : 4554) 31 #include <glib-object.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> 95 template<
typename TYPE>
97 if (strcmp(
typeid(val).name(),
typeid(
float).name())==0)
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)
103 if (strcmp(
typeid(val).name(),
typeid(
unsigned int).name())==0)
105 if (strcmp(
typeid(val).name(),
typeid(
long).name())==0)
107 if (strcmp(
typeid(val).name(),
typeid(
unsigned long).name())==0)
109 if (strcmp(
typeid(val).name(),
typeid(int64_t).name())==0)
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)
115 if (strcmp(
typeid(val).name(),
typeid(
unsigned char).name())==0)
117 return G_TYPE_INVALID;
130 setHomogeneous(
false);
134 axis=gtk_databox_new ();
135 setOptions((GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK));
139 GtkWidget *xRuler = gtk_databox_ruler_new (GTK_ORIENTATION_HORIZONTAL);
141 gtk_databox_set_ruler_x (GTK_DATABOX(axis), GTK_DATABOX_RULER (xRuler));
142 GtkWidget *yRuler = gtk_databox_ruler_new (GTK_ORIENTATION_VERTICAL);
144 gtk_databox_set_ruler_y (GTK_DATABOX(axis), GTK_DATABOX_RULER (yRuler));
146 setOptions((GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), (GtkAttachOptions)(GTK_FILL));
149 setOptions((GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK));
150 setRegion(1, 2, 1, 2);
171 #if GTK_MAJOR_VERSION>2 182 #if GTK_MAJOR_VERSION>2 183 void setBackground(
const GdkRGBA gdkC) {
184 gtk_widget_override_background_color(axis, GTK_STATE_FLAG_NORMAL, &gdkC);
187 gtk_widget_modify_bg(axis, GTK_STATE_NORMAL, &gdkC);
195 return getCurrentAxis();
208 gtk_widget_show_all(axis);
209 gtk_widget_show_all(getWidget());
212 gtk_widget_hide(axis);
213 gtk_widget_hide(getWidget());
234 GtkDataboxGraph *
plot(gfloat *
x, gfloat *
y,
int cnt) {
237 return plot(x, y, cnt, cls);
260 GtkDataboxGraph *
plot(gfloat *
x, gfloat *
y,
int cnt,
const char *clsChar) {
263 return plot(x, y, cnt, cls);
282 GtkDataboxGraph *graph=NULL;
283 #if GTK_MAJOR_VERSION>2 290 graph = gtk_databox_lines_new (cnt, x, y, &gdkC, size);
292 graph = gtk_databox_points_new (cnt, x, y, &gdkC, size);
293 gtk_databox_graph_add_front (GTK_DATABOX (axis), graph);
347 GtkDataboxGraph *
plot(gfloat *
x, gfloat *y1, gfloat *y2,
int cnt) {
349 return plot(x, y1, y2, cnt, cls);
362 GtkDataboxGraph *
plot(gfloat *
x, gfloat *y1, gfloat *y2,
int cnt,
const char *clsChar) {
364 return plot(x, y1, y2, cnt, cls);
385 GtkDataboxGraph *graph=NULL;
386 #if GTK_MAJOR_VERSION>2 393 graph = gtk_databox_regions_new (cnt, x, y1, y2, &gdkC);
395 graph = gtk_databox_offset_bars_new(cnt, x, y1, y2, &gdkC, size);
396 gtk_databox_graph_add_front (GTK_DATABOX (axis), graph);
410 return semilogx(x, y, cnt, cls);
421 GtkDataboxGraph *
semilogx(gfloat *
x, gfloat *
y,
int cnt,
const char *clsChar) {
423 return semilogx(x, y, cnt, cls);
435 GtkDataboxGraph *graph=plot(x, y, cnt, cls);
436 gtk_databox_set_scale_type_x (GTK_DATABOX (axis), GTK_DATABOX_SCALE_LOG);
449 GtkDataboxGraph *
semilogx(gfloat *
x, gfloat *y1, gfloat *y2,
int cnt) {
451 return semilogx(x, y1, y2, cnt, cls);
465 GtkDataboxGraph *
semilogx(gfloat *
x, gfloat *y1, gfloat *y2,
int cnt,
const char *clsChar) {
467 return semilogx(x, y1, y2, cnt, cls);
482 GtkDataboxGraph *graph=plot(x, y1, y2, cnt, cls);
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);
498 return semilogy(x, y, cnt, cls);
509 GtkDataboxGraph *
semilogy(gfloat *
x, gfloat *
y,
int cnt,
const char *clsChar) {
511 return semilogy(x, y, cnt, cls);
523 GtkDataboxGraph *graph=plot(x, y, cnt, cls);
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);
538 GtkDataboxGraph *
loglog(gfloat *
x, gfloat *
y,
int cnt) {
540 return loglog(x, y, cnt, cls);
551 GtkDataboxGraph *
loglog(gfloat *
x, gfloat *
y,
int cnt,
const char *clsChar) {
553 return loglog(x, y, cnt, 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);
578 GtkDataboxGraph *
text(gfloat *
x, gfloat *
y,
const char *textDisp,
const char *clsChar) {
580 return text(x, y, textDisp, cls);
591 #if GTK_MAJOR_VERSION>2 596 GtkDataboxGraph *graph = gtk_databox_markers_new (1, x, y, &gdkC, 1, GTK_DATABOX_MARKERS_NONE);
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);
613 gtk_databox_graph_remove_all(GTK_DATABOX (axis));
628 GtkDataboxGrid *gridG=GTK_DATABOX_GRID(gridGraph);
629 if (gtk_databox_grid_get_hline_vals(gridG)) {
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));
634 grid(on, 5, NULL, 5, NULL);
644 void grid(
bool on,
int hCnt, gfloat *hLines,
int vCnt, gfloat *vLines) {
647 if (gridGraph!=NULL) {
648 gtk_databox_graph_remove(GTK_DATABOX (axis), gridGraph);
652 #if GTK_MAJOR_VERSION>2 658 if ((hLines!=NULL) & (vLines!=NULL))
659 gridGraph=gtk_databox_grid_array_new(hCnt, vCnt, hLines, vLines, &gdkC, size);
661 gridGraph=gtk_databox_grid_new(hCnt, vCnt, &gdkC, size);
662 gtk_databox_graph_add_front (GTK_DATABOX (axis), gridGraph);
664 if (gridGraph!=NULL) {
665 gtk_databox_graph_remove(GTK_DATABOX (axis), gridGraph);
678 void limits(
float min_x,
float max_x,
float min_y,
float max_y) {
683 max_y=(min_y=max_y*.9)/.9*1.1;
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);
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.)
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);
708 gtk_databox_auto_rescale(GTK_DATABOX (axis), border);
716 if (gtk_widget_is_drawable (GTK_WIDGET (axis)))
717 gtk_widget_queue_draw (GTK_WIDGET (axis));
780 void set(GtkWidget *widget, ...) {
782 va_start(args, widget);
785 char *token=va_arg(args,
char *);
786 if ((token==NULL) | (token==(
char *)
'\0'))
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)
796 gtk_databox_set_scale_type_x (GTK_DATABOX (axis), GTK_DATABOX_SCALE_LOG);
798 gtk_databox_set_scale_type_x (GTK_DATABOX (axis), GTK_DATABOX_SCALE_LINEAR);
800 if (tolower(token[0])==
'y') {
801 if (strcmp(&linearOrLog[1],
"og")==0)
802 gtk_databox_set_scale_type_y (GTK_DATABOX (axis), GTK_DATABOX_SCALE_LOG);
804 gtk_databox_set_scale_type_y (GTK_DATABOX (axis), GTK_DATABOX_SCALE_LINEAR);
808 GtkDataboxRuler *ruler;
810 if (tolower(token[0])==
'x')
811 ruler=gtk_databox_get_ruler_x(GTK_DATABOX (widget));
813 ruler=gtk_databox_get_ruler_y(GTK_DATABOX (widget));
817 if ((strcmp(&token[1],
"MinorTick")==0) | (strcmp(&token[1],
"minortick")==0)) {
819 int draw_ticks=va_arg(args,
int);
820 gtk_databox_ruler_set_draw_subticks(ruler,draw_ticks);
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);
827 gtk_databox_ruler_set_manual_tick_cnt(ruler, manual_tick_cnt);
828 gtk_databox_ruler_set_manual_ticks(ruler, va_arg(args, gfloat*));
830 }
else if ((strcmp(&token[1],
"LabelFormat")==0) | (strcmp(&token[1],
"labelformat")==0)) {
833 scaleType=gtk_databox_get_scale_type_x(GTK_DATABOX (widget));
835 scaleType=gtk_databox_get_scale_type_y(GTK_DATABOX (widget));
837 if (scaleType==GTK_DATABOX_SCALE_LINEAR)
838 gtk_databox_ruler_set_linear_label_format(ruler, va_arg(args,
char*));
840 gtk_databox_ruler_set_log_label_format(ruler, va_arg(args,
char*));
842 }
else if ((strcmp(&token[1],
"LabelLength")==0) | (strcmp(&token[1],
"labellength")==0)) {
845 scaleType=gtk_databox_get_scale_type_x(GTK_DATABOX (widget));
847 scaleType=gtk_databox_get_scale_type_y(GTK_DATABOX (widget));
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)
863 gtk_databox_ruler_set_text_alignment(ruler, PANGO_ALIGN_RIGHT);
864 else if (strcmp(&which[1],
"enter")==0)
865 gtk_databox_ruler_set_text_alignment(ruler, PANGO_ALIGN_CENTER);
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)
871 gtk_databox_ruler_set_text_orientation(ruler, GTK_ORIENTATION_VERTICAL);
873 gtk_databox_ruler_set_text_orientation(ruler, GTK_ORIENTATION_HORIZONTAL);
876 if (tolower(token[0])==
'x')
877 gtk_databox_set_ruler_x(GTK_DATABOX (widget), ruler);
879 gtk_databox_set_ruler_y(GTK_DATABOX (widget), ruler);
890 void connectAfter(
const char *event, GCallback callback, gpointer data) {
891 g_signal_connect_after(axis, event, callback, data);
905 void xLabel(
const char* label,
int *indexes=NULL) {
907 setRegion(2, 3, 3, 4);
908 setOptions((GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), (GtkAttachOptions)(GTK_FILL));
911 *
this<<(
Labels()<<label).setAlignment(0.5, 0.5);
919 setOptions((GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_FILL | GTK_SHRINK));
920 int indexes[]= {1,2,2,3};
921 xLabel(label,indexes);
935 void yLabel(
const char* label,
int *indexes=NULL) {
939 setRegion(0, 1, 1, 2);
940 setOptions((GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK));
953 setOptions((GtkAttachOptions)(GTK_FILL | GTK_SHRINK), (GtkAttachOptions)(GTK_FILL));
954 int indexes[]= {1,2,0,1};
955 yLabel(label,indexes);
965 void title(
const char* titleStr,
int *indexes=NULL) {
979 void title(GtkWidget *widget,
int *indexes=NULL) {
981 setRegion(2, 3, 0, 1);
982 setOptions((GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), (GtkAttachOptions)(GTK_FILL));
1001 void remove(GtkDataboxGraph *toRemove) {
1002 gtk_databox_graph_remove (GTK_DATABOX (axis), toRemove);
1017 return gtk_databox_pixel_to_value_x(GTK_DATABOX (axis), pixel);
1023 return gtk_databox_pixel_to_value_y(GTK_DATABOX (axis), pixel);
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...
void yLabelTL(const char *label)
TYPE current(void)
return a pointer to the current lug
class to create and handle labels.
Plot & operator>>(GtkDataboxGraph *toRemove)
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...
GtkWidget * getWidget(void)
returns the current GtkWidget* in the list
void connectAfter(const char *event, GCallback callback, gpointer data)
simplistic plotting class which mimicks a octave approach to plotting Use this class as if you were p...
void setBackground(const char *clsStr)
void title(const char *titleStr, int *indexes=NULL)
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...
GtkDataboxGraph * plot(gfloat *x, gfloat *y, int cnt, ColourLineSpec &cls)
gfloat pixelToY(gint16 pixel)
void grid(bool on, int hCnt, gfloat *hLines, int vCnt, gfloat *vLines)
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...
GtkWidget * axis
The axis widget.
GtkWidget * setAlignment(float xalign, float yalign)
void setAngle(double angle)
GtkDataboxGraph * plot(gfloat *x, gfloat *y, int cnt)
gfloat pixelToX(gint16 pixel)
GtkDataboxGraph * plot(gfloat *x, gfloat *y1, gfloat *y2, int cnt, ColourLineSpec &cls)
GtkDataboxGraph * plot(gfloat *x, gfloat *y1, gfloat *y2, int cnt)
void setBackground(ColourLineSpec cls)
GtkDataboxGraph * text(gfloat *x, gfloat *y, const char *textDisp, ColourLineSpec &cls)
GtkDataboxGraph * semilogx(gfloat *x, gfloat *y, int cnt, ColourLineSpec &cls)
Plots with a logarithmic ordinate scale Plotting the data with a logarithmic ordinate scale...
void title(GtkWidget *widget, int *indexes=NULL)
void yLabel(const char *label, int *indexes=NULL)
void setBackground(const GdkColor gdkC)
GtkWidget * getCurrentAxis(void)
Get the current axis.
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...
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...
void replot(void)
Instruct gtk to replot If the underlying plot data pointers haven't changed, it is not necessary to c...
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...
GtkDataboxGraph * text(gfloat *x, gfloat *y, const char *textDisp, const char *clsChar)
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...
void xLabel(const char *label, int *indexes=NULL)
GtkDataboxGraph * gridGraph
The grid which defaults to off.
void xLabelBL(const char *label)
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...
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...
GtkWidget * gca(void)
Get the current axis.
bool holdOn
Whether to hold the curves or not.
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...
GtkDataboxGraph * plot(gfloat *x, gfloat *y1, gfloat *y2, int cnt, const char *clsChar)
void limits(gfloat border=0.)
Set the limits to autoscale Rescales the figure to show everything plotted.
GtkDataboxGraph * loglog(gfloat *x, gfloat *y, int cnt)
Plots with logarithmic ordingate and co-ordinate scales Plotting the data with logarithmic ordinate a...
bool gridOn
Whether to the grid is on.
GtkDataboxGraph * plot(gfloat *x, gfloat *y, int cnt, const char *clsChar)
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...