-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
88 lines (82 loc) · 4.21 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
The GtkPlot Widget Family
----------------------
Version 0.0.0, January 2011
GtkPlotLinear provides a widget for automated plotting of data on a linear-linear scale.
GtkPlotLogLinear, PlotLinearLog will provide similar functionality for plotting on a semilog scale.
GtkPlotLogLog will provide similar functionality for plotting on a log-log scale.
GtkPlotPolar provides similar functionality for a polar scale.
This program is my first attempt to write an object in a non-object-oriented language using object-oriented libraries and coded in as unobject-oriented a fashion as possible.
The program is coded preferentially to an in-line structure to maximise performance so my apologies to anyone that attempts to modify or understand it, but I like that my >10000 point graphs load fast.
Motivation; Technology; License
-------------------------------
GtkPlot builds upon GtkDrawingArea. It compiles & works under gtk+2. upgrading to gtk+3 is currently under work.
This code is released under the GNU LGPL version 2 (for the gtk+2 version; the LGPL version 3 for the gtk+3 version) or (at your option) any later versions, making it suitable for pretty much anything.
Usage
-----
Once the library is installed (see the INSTALL file) you can link to the shared library by:
1) In the source code link to the headers with, e.g.:
#include <gtkplot-2.0/gtkplotlinear.h>
2) Compile your program by identifying gtkplot-2.0 with pkgconfig, e.g.:
gcc -o testplotlinear testplotlinear.c `pkg-config --cflags --libs gtk+-2.0 gtk2plot-2.0`
A new plot can be made in gtk+2 using, e.g.:
GtkWidget *plotname;
plotname=gtk_plot_linear_new();
gtk_widget_show(plotname);
Data can be sent to the plot using GArray structures as:
GtkPlotLinear *plot;
GArray *xarrayname, *yarrayname, *sizes, *indices;
gint arraysize, n=0;
...
xarrayname=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), arraysize);
yarrayname=g_array_sized_new(FALSE, FALSE, sizeof(gdouble), arraysize);
...
sizes=g_array_sized_new(FALSE, FALSE, sizeof(gint), arraysize);
g_array_append_val(sizes, arraysize);
indices=g_array_sized_new(FALSE, FALSE, sizeof(gint), arraysize);
g_array_append_val(indices, n);
plot=GTK_PLOT_LINEAR(plotname);
(plot->xdata)=xname;
(plot->ydata)=yname;
(plot->sizes)=sizes;
(plot->ind)=indices;
(for polar plotting these xdata and ydata arrays are replaced by rdata and thdata with similar x,y -> r,th replacements throughout)
A new interface for doing this without memory leaks is under development.
Redrawing the axes can be done by:
gdouble xmin, xmax, ymin, ymax;
gtk_plot_linear_update_scale(plotname, xmin, xmax, ymin, ymax);
to get strict axis bounds or:
gdouble xmin, xmax, ymin, ymax;
gtk_plot_linear_update_scale_pretty(plotname, xmin, xmax, ymin, ymax);
to get the best fit of six or less major tick divisions at multiples of 1, 2 or 5 times a power of 10.
Properties can be changed or accessed using:
g_object_set(G_OBJECT(plotname), "propertyname", value, ..., NULL);
g_object_get(G_OBJECT(plotname), "propertyname", value, ..., NULL);
respectively, where the propertyname's are explained in the _class_init function (multiple propertyname-value pairs can be entered but there must always be a NULL at the end regardless).
Publically accessable variables described in the _PlotLinear struct in the plotlinear.h header file can be accessed with:
GtkPlotLinear *plot;
gchar *label;
guint mode;
...
mode=2;
label="Frequency (Hz)";
plot=GTK_PLOT_LINEAR(plotname);
(plot->xlab)=g_strdup(label);
(plot->flagd)=mode;
The widget also emits a signal "moved" when the mouse moves over it which is useful for getting the corresponding location in the graph as:
void pltmv(GtkPlotLinear *plot, gpointer data)
{
gdouble x,y;
x=(plot->xps);
y=(plot->yps);
}
...
int main(int argc, char *argv[])
GtkPlotLinear *plot;
...
plot=GTK_PLOT_LINEAR(plotname);
g_signal_connect(plot, "moved", G_CALLBACK(pltmv), NULL);
See the example file testplotlinear.c for an example of interacting with the GtkPlotLinear widget to its full extent.
Known Bugs/Issues
-----------------
GtkPlotPolar scales in an unhelpful manner and is generally very buggy (see TODO)
----------------------- THE END --------------------------------