Scrolling Widget (Release 2.0)

Classname: XwScrollWidgetClass

Description:

The Scrolling widget displays one or more curves in a diagram with ascending abscissa. The new values are inserted and the diagram will scroll towards descending abscissa, giving the effect of a pen recorder, where only a short piece of paper is visible. A s such a recorder may be positioned in different ways, the widget is able to move the paper to the left, upwards and downwards, so really emulating a scrolling paper. The basic difference to paper is, that it isn't possible to get the paper back from the i n visible part. But in general, it is a solution to display measured values over time with a defined time-range of visible data.

Example of three-curve sine, scrolling to the left:

Graphic1

Resources:

The widget includes the »core« and the »primitive« class with all resources.To describe the features of the scrolling widget, it has several resources for it's own. The following table contains the resource-name, the resource-class and the accesst ype. Def ining the resource in a general resourcefile file like .Xdefaults, means, leave out the prefix XwN or XwC. The access type defines, if the resource may be set at creation »C«, using XtSetValues »S«, only at creation using XtSetArg »CS« and being read using XtGetValues »G«.



Name

Class

Type

Default

Access

XwNdestroyCallback


XtCallbackList

NULL

S C

XmNexposeCallback

XmCExposeCallback

XtCallbackList

NULL

S C

XmNresizeCallback

XmCResizeCallback

XtCallbackList

NULL

S C

XmNinputCallback


XtCallbackList

NULL

S C

XwNscrolldirection

XwCScrolldirection

int

horizontal

C S G

XwNscrollBorder

XwCCscrollBorder

bool

FALSE

C S G

XwNscrollGridScale

XwCScrollGridScale

Float [4]

NULL

CS S G

XwNscrollScale

XwCScrollScale

Float [4]

NULL

CS S G

XwNscrollAnnotColor

XwCScrollAnnotColor

Pixel

inherit

C S G

XwNscrollGridColor

XwCScrollGridColor

Pixel

inherit

C S G

XwNscrollCUcolor

XwCScrollCUcolor

Pixel

inherit

C S G

XwNscrollAnnotXNdec

XwCScrollAnnotXNdec

int

0

C S G

XwNscrollAnnotYNdec

XwCScrollAnnotYNdec

int

0

C S G

XwNscrollAnnotXNgrid

XwCScrollAnnotXNgrid

int

0

C S G

XwNscrollAnnotYNgrid

XwCScrollAnnotYNgrid

int

0

C S G

XwNscrollNcurves

XwCScrollNcurves

int

DefaultNcurves (10)

C G

XwNscrollAnnotation

XwCScrollAnnotation

int

left+down

C S G

XwNscrollAddvalue

XwCScrollAddvalue

Bool

FALSE

C S G

XwNscrollCurve

XwCScrollCurve

Pixel

NULL

C S G

XwNscrollAddtext

XwCScrollAddtext

String

NULL

C S G

XmNfontList

XmCFontList

XmFontList

Default

C S G

XwNscrollHistory

XwCScrollHistory

Bool

FALSE

C S G

XwNscrollHistorysize

XwCScrollHistorysize

int

2 * abscissa

C S G



Detailed Description of special Resources

Callbacks:

Possible callbacks are:

XwNdestroyCallback XmNexposeCallback XmNresizeCallback. XmNinputCallback. Of course the most important is the resize callback. The widget tries to handle resizing itself by rescaling and redrawing the grid and annotation and to save the previous visible history by copying it (as is!) into the visible window, but this might be seen as a bug. So, when the resize callback is called, all the work is done, the user may clear the window (using the XwNscrollScale and XwNscrollGridScale, which will clear the win dow) and redraw his remebered values. This will result in a better picture. Since release 2.0, the widget contains an optional storing of history. If this is enabled, resizing will redisplay the history in the newly scaled manner. Together with that histor y the Input-callback might be used. It reacts on button-1-press and gets the abscissa value back. The delivered callback data structure is the same for all four callbacks:

typedef struct{

int reason;

XEvent *event;

int fd; float value;

Dimension width;

Dimension height;

}XwScrollCallbackStruct;

The three additional values are not useful at destroy-callback. In the other cases, »value« is the abscissavalue of the lastpush into visible( respectively the klicked abscissa), the two Dimensions deliver the size of the visible diagram area.

Scaling:

Now we group the resources into two parts, first the necessary resources:

XwNscrollScale XwNscrollGridScale

Both may only be set at creation or using SetValue. They require an array of four float values, the first pair defines abscissa, the second ordinate. Where XwNscrollScale defines the first value as the initial minimum of visible and the second as the visi ble size of actual axis. XwNscrollGridScale has a similar definition, the first value is the visible minimum and the second the distance between two gridlines. In any case the values are user defined units, not pixels, so this information is used to calcul ate the transformation into screen pixels. Now it's easy to see, why a rescale (or grid change) will result in clearing the visible area. Please keep in mind, that internally the minimum value of grid is used to hold scrolling information, so using GetValu e will return the last drawn gridminimum (the visible).

All other resources may be set at any time.

Direction and placement:

XwNscrolldirection

It defines the movement direction of the plot. For in-program usage there are defined mnemonics (marked in bold/italic) . The most important (and the default) is horizontal scrolling with the increasing abscissa to the right. Horizontal. == 0, movement is to the left. Next is moving down, having the newest value on top, increasing abscissa points upward. XwScrollVertUp == 2 The last one is the inverse, movement goes upward, newest (and increasing) value is downward. XwScrollVertDown.== 1

XwNscrollAnnotation

It defines, where to place the annotation of abscissa and ordinate. It should be a sum of the definitions for horizontal and vertical placement with one exception. If you want to have the abscissa annotation inside the plot (which leaves more space for the diagram and gives a bit more speed) use XwScrollInAnno == 1 to set it. This fixes the position of abscissa, whereas all other will set the position independently of direction.
to inhibit any annotion, just set this resource to 0 == XwScrollNoAnno.

In detail: position either left or right: XwScrollLeAnno == 2 / XwScrollRiAnno == 4; position above or under the plot: XwScrollDoAnno == 16 / XwScrollUpAnno == 8.

Annotation and grid layout:

Setting the number of digits after the decimal point:

XwNscrollAnnotXNdec XwNscrollAnnotYNdec

As the default is zero, setting these resources is only needed, if a finer resolution is wanted. But please remember, that the used space increases with the number of decimals.

Now if there is still not enough space, you may want to put annotation only at every n'th gridline XwNscrollAnnotXNgrid XwNscrollAnnotYNgrid These define the number of gridlines between annotations.

Colours:

Next is to play with colours. The colour for a plotted curve may be set, when it is defined or changed at any time using the conveniance routines. But for all other colours! First of all, they are inherited from the parent, using background and foreground colours. Colours for Grid, Annotation, Diagram-background may be set via the following resources:

XwNscrollAnnotColor Annotation colour XwNscrollGridColor Colour of grid lines
XwNCUcolor Background colour of diagram
The normal resources for background will define the widget's background colour.

Text and values:

If you want to display the actual value together with the last point, use either the resource, which defines this for all curves, or the corresponding convenience routine to define this per curve. The resource XwNscrollAddvalue, if set to TRUE, will displa y the actual value for all curves. If this is set via resource, the routine to set it per curve will have no effect. The number of digits after the decimal point is taken from the annotation number of digits plus one.

Now it is possible to display a descriptive text for this widget. Using the resource definition will display the given text and using the convenience routines, will add the text per curve. So setting XwNscrollAddtext to any text, will display this text at the left side of the diagram.

Finally the resource XwNscrollBorder is defined to plot a border around the diagram area, but this doesn't work well, as the pixmaps will overwrite the plotted border.

History:

XwNscrollHistory enables a cyclic buffer per curve of defaultsize twice as big as the pixelsize of abscissa. If the size seems to small to hold all the visible use XwNscrollHistorysize to set a better size. This history now enables the widget to show a mu ch better redisplaying at resize and allows the user to retrieve the history (visible area) for example to do a plot to paper or run some analysing functions. Convenience routines are included to support the feature.

Convenience Functions:

Name: XwCreateScroll
Header file: »WScroll.h«

Widget XwCreateScroll ( Widget parent , char *name , ArgList arg, Cardinal argcount);

XwCreateScroll creates a widgetinstance of class XwScroll and returns the widget-id. The argumentlist follows the general standard.

Name: XwScrollAddcurve

long int XwScrollAddcurve ( Widget scroll , Pixel colour);

This defines a curve to plot (allocates storage and sets the colour). The id of the allocated curve is returned and must be specified for each access to this curve.

Parameters: scroll The Widget-id of the scrolling
Widget colour The pixel value for the colour of this diagramline

Name: XwScrollcurve

void XwScrollcurve (Widget scroll , long int ID , float xy[2] , int pushflag);

calling XwScrollcurve will add the next point to the given curve. It will be connected to the previous point using linear interpolation in thin linestyle using the colour, defined for this curve ID. The pushflag, if set to TRUE forces the update of the vis ible area to synchronize update in case of multiple curves. If only one curve is defined, the flag is always assumed to be TRUE.

Parameters: scroll The Widget id of the scrolling widget.
ID The curve id to be accessed
xy a two value array, first value is abscissa
pushflag if set to zero, don't update if multiple curves
else forced update

Name: XwScrollchangecolor

void XwScrollchangecolor (Widget scroll , int ID , Pixel color);

This will change the used colour for the given curve id immediately for all following points.

Parameters: scroll The Widget id of the scrolling widget.
ID The curve id to be accessed
color The pixel value of requested colour



Name: XwScrollvaluedisplay

void XwScrollvaluedisplay ( Widget scroll , int ID , int onoff);

If the global resource XwNscrollAddvalue is not set, this function will control displaying actual value on a per curve basis. If the global resource is set, the function is ignored.

Parameters: scroll The Widget id of the scrolling widget.
ID The curve id to be accessed
onoff if set to zero, no valuedisplay , else display value



Name: XwScrollSettext

void XwScrollSettext ( Widget scroll , int ID , char *text);

To display an additional text (describing the curve parameter) at the left side of the visible area, this function should be used. The text is displayed a line below the previous, it's colour is the same as the curvecolour. If the parameter for text is eit her NULL or empty, text displaying for this curve is switched off.

Parameters: scroll The Widget id of the scrolling widget.
ID The curve id to be accessed
text a textstring to be displayed
if empty or zero, no text display



Name: XwScrollhistory

void XwScrollhistory (Widget scroll , lont int ID , float **x , float **y , int *size);

Retrieves the history from the visible part of the widget.It is up to the user to free (using free()) the returned arrays after use. To get all curves, a call to this function is neded for each curve..

Parameters: scroll The Widget id of the scrolling widget.
ID The curve id to be accessed
x , y returned address of history arrays (abscissa/ordinate)

size returned size of arrays



Name: XwScrollGetValue

float XwScrollGetValue ( Widget scroll , long int ID , float x);

For a given abscissavalue, the history of the curve, identified by ID, is searched and the corresponding ordinate value interpolated. If no history is active, returned value is zero, if the abscissavalue can't be found, (outside of history) a value of 9999 99. Is returned.

Parameters: scroll The Widget id of the scrolling widget.
ID The curve id to be accessed
x abscissa value,



Table of Contents

Description: 1

Resources: 1

Detailed Description of special Resources 2

Callbacks: 2

Scaling: 3

Direction and placement: 3

Annotation and grid layout: 3

Colours: 4

Text and values: 4

History: 4

Convenience Functions: 4