IupPPlot

IUP - Portable User Interface

IupPPlot

Creates a PPlot plot. It inherits from IupCanvas.

PPlot is a library for creating plots that is system independent. It is maintained by Pier Philipsen ([email protected]) and available at SourceForge http://pplot.sourceforge.net/ with a very flexible license (BSD License). IupPPlot library includes the PPlot source code so no external references are needed. Also the standard PPlot distribution source code was changed to improve features and visual appearance.

IupPPlot first implementation was writen by Marian Trifon ([email protected]), then completed and documented by the IUP team.

Initialization and Usage

The IupPPlotOpen function must be called after a IupOpen, so that the control can be used. The "iup_pplot.h" file must also be included in the source code. The program must be linked to the controls library (iup_pplot), and with the CD library.

To make the control available in Lua, use the initialization function in C, iuppplotlua_open, after calling iuplua_open.  The iuplua_pplot.h file must also be included in the source code. The program must be linked to the lua control library (iuplua_pplot).

Guide

Each plot can contain 2 axis (X and Y), a title, a legend box, a grid, a dataset area and as many datasets you want.

Each data set is added using the IupPPlotAdd function. Al other plot parameters are configured by attributes.

If no attribute is set, the default values are choosed to try to best display the plot.

When setting attributes the plot is NOT redrawn until the REDRAW attribute is set or a redraw event occours.

The dataset area is delimited by a margin. Data is only plotted inside the dataset area. Axis and main title are positioned indepent of this margin. It is very important to set the margins when using axis automatic scaling or the axis itself maybe hidden.

The legend box is a list of the dataset names, each one drawn with the same color of the correspondent dataset. The box is located in one of the four corners of the dataset area.

The grid is automatically spaced accordingly the current axis displayed values.

The title is always centered in the top of the plot.

The axis are always positioned at the origin, except when CrossOrigin is disabled, then it is positioned at the left-bottom. If values are only positive then the origin will be placed in left bottom position. If values are negative and positive then origin will be placed inside the plot. The ticks in the axis are also automatically distributed.

Interaction

Zoom

Zoom in can be done selecting a region using the left mouse button. Zoom out is done with a single click of the left mouse button. If the Ctrl+X key combination is pressed the zoom selection is restricted to the X axis, the Y axis will be left unchanged. If the Ctrl+Y key combination is pressed the zoom selection is restricted to the Y axis, the X axis will be left unchanged. If the Ctrl+R key combination is pressed the zoom selection is restored to a free rectangle.

Each zoom in operation is stacked, so each zoom out operation goes back the the previous zoom selection.

Zoom operates on AXS_XMAX, AXS_XMIN, AXS_YMAX, AXS_YMIN even if AUTOMIN/MAX is enabled. The axis may be hidden depending on the selected rectangle.

CrossHair Cursor

If you press the Ctrl+Shift key combination, while holding the left mouse button down, a cross hair cursor will be displayed for each dataset in the plot. The X coordinate will control the cursor, the Y coordinate will reflect each dataset correspondent value.

Selection and Editing

Selection and editing of a dataset can be enabled using the DS_EDIT attribute.

To select all the samples in the dataset press the Shift key while clicking with the left mouse button near a sample in the dataset. To deselect all samples press the Shift key while clicking with the left mouse button in the background.

To select or deselect individual samples press the Ctrl key while clicking with the left mouse button near the sample in the dataset.

After selecting samples use the Del key to remove the selected samples. Also use the arrow keys to move the Y coordinate of the selected samples. Press the Ctrl key to increase the step size when moving the Y coordinate.

To Do's

  • Add support of legend text near each dataset plot.
  • Adjust AutoScale to start and end at major axis ticks.
  • Improve visual appearance and ticks of bar mode.
  • Improve the display of values near each sample.
  • PPlot force the definitions of the margins. It should have a way to automatic calculate the margins when doing automatic scaling.
  • PPlot has callback mode feature that is not available.
  • PPlot force the Grid to be automatically spaced following the major ticks.
  • PPlot generates lots of warnings on all compilers.
  • PPlot uses C++ and the STL library. So it may have portability issues. So far it does not compiles under Visual C++ 6. Use of STL is simple and can be removed.

Creation

Ihandle* IupPPlot(void); [in C]
iup.pplot{} -> (elem: ihandle) [in Lua]
pplot(action) [in LED]

This function returns the identifier of the created pplot, or NULL if an error occurs.

Auxiliary Functions

void IupPPlotBegin(Ihandle* self, int strXdata); [in C]
iup.PPlotBegin(self: ihandle, strXdata: number) [in Lua]

Prepares a dataset to receive samples. If strXdata is 1 then the X axis value is a string.

void IupPPlotAdd(Ihandle* self, float x, float y); [in C]
iup.PPlotAdd(self: ihandle, x, y: number) [in Lua]

Adds a sample to the dataset. Can only be called if IupPPlotBegin was called with strXdata=0.

void IupPPlotAddStr(Ihandle* self, const char* x, float y); [in C]
iup.PPlotAddStr(self: ihandle, x: string, y: number) [in Lua]

Same as IupPPlotAdd, but allows to use a string as the X axis value. Can only be called if IupPPlotBegin was called with strXdata=1.

int IupPPlotEnd(Ihandle* self); [in C]
iup.PPlotEnd(self: ihandle) -> (index: number) [in Lua]

Adds a 2D dataset to the plot and returns the dataset index. Redraw is NOT done until the REDRAW attribute is set. Also it will change the current dataset index to the return value. You can only set attributes of a dataset AFTER you added the dataset.  Can only be called if IupPPlotBegin was called. Whenever you create a dataset all its "DS_*" attributes will be set to the default values. Notice that DS_MODE must be set before other "DS_*" attributes.

void IupPPlotInsert(Ihandle *self, int index, int sample_index, float x, float y); [in C]
void IupPPlotInsertStr(Ihandle *self, int index, int sample_index, const char* x, float y);
iup.IupPPlotInsert(self: ihandle, index, sample_index, x, y: number) [in Lua]
iup.IupPPlotInsertStr(self: ihandle, index, sample_index, x, y: number)

Inserts a sample in a dataset. It is used after the dataset is added to the plot.

void IupPPlotTransform(Ihandle* self, float x, float y, int *ix, int *iy); [in C]
iup.PPlotTransform(self: ihandle, x, y: number) -> (ix, iy: number) [in Lua]

Converts coordinates in plot units to pixels. It should be used in PREDRAW_CB and POSTDRAW_CB callbacks only. Output variables can be NULL if not used.

void IupPPlotPaintTo(Ihandle* self, cdCanvas* cnv); [in C]
iup.PPlotPaintTo(self: ihandle, cnv: cdCanvas) [in Lua]

Plots to the given CD canvas instead of the display canvas.

Attributes

The IupPPlot element understands all attributes defined for a conventional canvas, see IupCanvas.

Apart from these attributes, IupPPlot understands specific attributes used to define the plot parameters:

REDRAW [write-only]: redraw the plot and update the display. Value is ignored. All other attributes will not update the display, so you can set many attributes without visual output.

USE_IMAGERGB: defines if the double buffer will use standard driver image (NO - faster) or an RGB image (YES - slower). Default: NO. The IMAGERGB driver has anti-aliasing which can improve the line drawing.

USE_GDI+ [Windows Only]: defines if the double buffer will use GDI+ (YES) for drawing or standard GDI (NO). Default: NO. The GDI+ driver has anti-aliasing which can improve the line drawing.

FONT: the font use in all text elements of the plot: title, legend and labels.

BGCOLOR: the background color. The default value is white "255 255 255".

FGCOLOR: the title color. The default value is black "0 0 0".

TITLE: the title. Located always at the top center area.

TITLEFONTSIZE, TITLEFONTSTYLE: the title font size and style. The default values depends on the FONT attribute and the returned value is NULL. Set to NULL, to use the FONT attribute values. Style can be "PLAIN", "BOLD", "ITALIC" or "BOLDITALIC".

MARGINLEFT, MARGINRIGHT, MARGINTOP, MARGINBOTTOM: margin of the dataset area. Default: "15", "15", "30", "15".

LEGENDSHOW: shows or hides the legend box. Can be YES or NO. Default: NO.

LEGENDPOS: legend box position. Can be: "TOPLEFT", "TOPRIGHT", "BOTTOMLEFT", or "BOTTOMRIGHT. Default: "TOPRIGHT".

LEGENDFONTSIZE, LEGENDFONTSTYLE: the legend box text font size and style.

GRIDLINESTYLE: line style of the grid. Can be: "CONTINUOUS", "DASHED", "DOTTED", "DASH_DOT", "DASH_DOT_DOT". Default is "CONTINUOUS".

GRIDCOLOR: grid color. Default: "200 200 200".

GRID: shows or hides the grid in both or a specific axis. Can be: YES (both), HORIZONTAL, VERTICAL or NO. Default: NO.

REMOVE [write-only]: removes a dataset given its index.

CLEAR [write-only]: removes all datasets. Value is ignored.

COUNT [read-only]: total number of datasets.

CURRENT: current dataset index. Default is -1. When a dataset is added it becames the current dataset.

DS_LEGEND: legend text of the current dataset. Default is dynamically generated: "plot 0", "plot 1", "plot 2", ...

DS_COLOR: color of the current dataset and it legend text. Default  is dynamically generated for the 6 first datasets, others are default to black "0 0 0". The first 6 are: 0="255 0 0", 1="0 0 255", 2="0 255 0", 3="0 255 255", 4="255 0 255", 5="255 255 0".

DS_MODE: drawing mode of the current dataset. Can be: "LINE", "BAR", "MARK" or "MARKLINE". Default: "LINE". This must be set before other "DS_*" attributes.

DS_LINESTYLE: line style of the current dataset. Can be: "CONTINUOUS", "DASHED", "DOTTED", "DASH_DOT", "DASH_DOT_DOT". Default is "CONTINUOUS".

DS_LINEWIDTH: line width of the current dataset. Default: 1.

DS_MARKSTYLE: mark style of the current dataset. Can be: "PLUS", "STAR", "CIRCLE", "X", "BOX", "DIAMOND", "HOLLOW_CIRCLE", "HOLLOW_BOX", "HOLLOW_DIAMOND". Default is "X".

DS_MARKSIZE: mark size of the current dataset. Default: 7.

DS_SHOWVALUES: enable or disable the display of the values near each sample. Can be YES or NO. Default: NO.

DS_REMOVE [write-only]: removes a sample from the current dataset given its index.

DS_EDIT: enable or disable the current dataset selection and editing. Can be YES or NO. Default: NO.

AXS_XCOLOR, AXS_YCOLOR: axis, ticks and label color. Default: "0 0 0".

AXS_XMAX, AXS_XMIN, AXS_YMAX, AXS_YMIN: minimum and maximum displayed values of the respective axis. Automatically calculated values when AUTOMIN or AUTOMAX are enabled.

AXS_XAUTOMIN, AXS_XAUTOMAX, AXS_YAUTOMIN, AXS_YAUTOMAX: configures the automatic scaling of the minimum and maximum display values. Can be YES or NO. Default: YES.

AXS_XLABEL, AXS_YLABEL: text label of the  respective axis.

AXS_XLABELCENTERED, AXS_YLABELCENTERED: text label position at center (YES) or at top/right (NO). Default: YES.

AXS_XREVERSE, AXS_YREVERSE: reverse the axis direction. Can be YES or NO. Default: NO.

AXS_XCROSSORIGIN, AXS_YCROSSORIGIN: allow the axis to cross the origin and to be placed inside the dataset area. Can be YES or NO. Default: YES.

AXS_XSCALE, AXS_YSCALE: configures the scale of the respective axis. Can be: LIN (liner), LOG10 (base 10), LOG2 (base 2) and LOGN (base e). Default: LIN.

AXS_XFONTSIZE, AXS_YFONTSIZE, AXS_XFONTSTYLE, AXS_YFONTSTYLE: axis label text font size and style. See TITLEFONTSIZE and TITLEFONTSTYLE.

AXS_XTICK, AXS_YTICK: enable or disable the axis tick display. Can be YES or NO. Default: YES.

AXS_XTICKFORMAT, AXS_YTICKFORMAT: axis tick number C format string. Default: "%.0f".

AXS_XTICKFONTSIZE, AXS_YTICKFONTSIZE, AXS_XTICKFONTSTYLE, AXS_YTICKFONTSTYLE: axis tick number font size and style.  See TITLEFONTSIZE and TITLEFONTSTYLE.

AXS_XAUTOTICK, AXS_YAUTOTICK: configures the automatic tick spacing. Can be YES or NO. Default: YES.

AXS_XTICKMAJORSPAN, AXS_YTICKMAJORSPAN: The spacing between major ticks. Default is 1 when AUTOTICK is disabled.

AXS_XTICKDIVISION, AXS_YTICKDIVISION: number of ticks between each major tick. Default is 5 when AUTOTICK is disabled.

AXS_XAUTOTICKSIZE, AXS_YAUTOTICKSIZE: configures the automatic tick size. Can be YES or NO. Default: YES.

AXS_XTICKSIZE, AXS_YTICKSIZE: size of ticks in pixels. Default is 5 when AUTOTICKSIZE is disabled.

AXS_XTICKMAJORSIZE, AXS_YTICKMAJORSIZE: size of major ticks in pixels. Default is 8 when AUTOTICKSIZE is disabled.

Callbacks

The IupGLCanvas element understands all callbacks defined for a conventional canvas, see IupCanvas.

Addicionally:

DELETE_CB: Action generated when the Del key is pressed to removed a sample from a dataset. If multiple points are selected it is called once for each selected point.

int function(Ihandle *self, int index, int sample_index, float x, float y); [in C]
elem:delete_cb(index, sample_index, x, y: number) -> (ret: number) [in Lua]

index: index of the dataset
sample_index: index of the sample in the dataset
x
: X coodinate value of the sample
y: Y coodinate value of the sample

If the return value is IUP_IGNORE then the sample is not deleted.

DELETEBEGIN_CB, DELETEEND_CB: Actions generated when a delete operation will begin or end. But they are called only if DELETE_CB is also defined.

int function(Ihandle *self); [in C]
elem:deletebegin_cb() -> (ret: number) [in Lua]
elem:deleteend_cb() -> (ret: number) [in Lua]

If the DELETEBEGIN_CB callback returns IUP_IGNORE the delete operation for all the selected samples are aborted.

SELECT_CB: Action generated when a sample is selected. If multiple points are selected it is called once for each new selected point. It is called only if the selection state of te sample is about to be changed.

int function(Ihandle *self, int index, int sample_index, float x, float y, int select); [in C]
elem:select_cb(index, sample_index, x, y, select: number) -> (ret: number) [in Lua]

index: index of the dataset
sample_index: index of the sample in the dataset
x
: X coodinate value of the sample
y: Y coodinate value of the sample
select: boolean value that a non zero value indicates if the point is to be selected.

If the return value is IUP_IGNORE then the sample is not selected.

SELECTBEGIN_CB, SELECTEND_CB: Actions generated when a selection operation will begin or end. But they are called only if SELECT_CB is also defined.

int function(Ihandle *self); [in C]
elem:selectbegin_cb() -> (ret: number) [in Lua]
elem:selectend_cb() -> (ret: number) [in Lua]

If the SELECTBEGIN_CB callback returns IUP_IGNORE the selection operation is aborted.

EDIT_CB: Action generated when a sample is selected. If multiple points are selected it is called once for each new selected point. It is called only if the selection state of te sample is about to be changed.

int function(Ihandle *self, int index, int sample_index, float x, float y, float *new_x, float *new_y); [in C]
elem:edit_cb(index, sample_index, x, y, new_x, new_y: number) -> (new_x, new_y, ret: number) [in Lua]

index: index of the dataset
sample_index: index of the sample in the dataset
x
: X coodinate value of the sample
y: Y coodinate value of the sample
new_x: the new X coodinate value of the sample
new_y: the new Y coodinate value of the sample

If the return value is IUP_IGNORE then the sample is not edited. The application can changed the new value before it is edited.

EDITBEGIN_CB, EDITEND_CB: Actions generated when an editing operation will begin or end. But they are called only if EDIT_CB is also defined.

int function(Ihandle *self); [in C]
elem:editbegin_cb() -> (ret: number) [in Lua]
elem:editend_cb() -> (ret: number) [in Lua]

If the EDITBEGIN_CB callback returns IUP_IGNORE the editing operation is aborted.

PREDRAW_CB, POSTDRAW_CB: Actions generated before and after the redraw operation. Predraw can be used to draw a different background and Postdraw can be used to draw addicional information in the plot. Predraw has no restrictions, but Postdraw is clipped to the dataset area. To position elements in plot units, use the IupPPlotTransform function.

int function(Ihandle *self, cdCanvas* cnv); [in C]
elem:predraw_cb(cnv: cdCanvas) -> (ret: number) [in Lua]
elem:postdraw_cb(cnv: cdCanvas) -> (ret: number) [in Lua]

cnv: the CD canvas where the draw operation occours.

Examples

Browse Example Files

See Also

IupCanvas