CwGraph

CwGraph — A Cogent graph widget.

Synopsis

class CwGraph PtBasic
{
    graph_flags;                   // flag
    graph_traces;                  // long
    graph_x_axis_color;            // color
    graph_x_axis_width;            // integer 
    graph_x_font;                  // string  
    graph_x_label;                 // string  
    graph_x_label_color;           // color  
    graph_x_major_length;          // integer 
    graph_x_major_tick;            // double array
    graph_x_minor_length;          // integer  
    graph_x_minor_tick;            // double array
    graph_xmax;                    // double array
    graph_xmin;                    // double array
    graph_y_axis_color_left;       // color 
    graph_y_axis_color_right;      // color 
    graph_y_axis_width_left;       // integer
    graph_y_axis_width_right;      // integer
    graph_y_font_left;             // string 
    graph_y_font_right;            // string 
    graph_y_label_color_left;      // color 
    graph_y_label_color_right;     // color 
    graph_y_label_left;            // string
    graph_y_label_right;           // string
    graph_y_major_length_left;     // integer
    graph_y_major_length_right;    // integer
    graph_y_major_tick_left;       // double array 
    graph_y_major_tick_right;      // double array 
    graph_y_minor_length_left;     // integer 
    graph_y_minor_length_right;    // integer 
    graph_y_minor_tick_left;       // double array
    graph_y_minor_tick_right;      // double array
    graph_ymax_left;               // double array
    graph_ymax_right;              // double array
    graph_ymin_left;               // double array
    graph_ymin_right;              // double array
}
		

Base Classes

PtWidget <-- PtBasic <-- CwGraph

Description

This widget is a graph that allows plotting multiple curves of arbitrary length, with options for one x-axis display, and two independent y-axis displays (left and right). It uses floating-point numbers in any scale, with independent scaling for each curve.

[Note]

This widget does not appear in the Photon documentation.

Instance Variables

graph_flags

This instance variable may be a combination of zero or more of the following flags. Most of these flags correspond to instance variables in the widget. Unsetting a flag here overrides the assignment of any corresponding instance variables.

ConstantDescription
Cw_GRAPH_X_AXISShow the x-axis on the graph. Default is set.
Cw_GRAPH_X_AXIS_DATENot currently implemented.
Cw_GRAPH_X_AXIS_LABELShow numbers on the x-axis. Default is set.
Cw_GRAPH_X_MAJOR_TICKShow major tick marks on the x-axis. Default is set. Unsetting this variable will make the major tick marks appear as minor tick marks if Cw_GRAPH_X_MINOR_TICK is set, otherwise the major tick marks will not appear at all.
Cw_GRAPH_X_MINOR_TICKShow minor tick marks on the x-axis. Default is set.
Cw_GRAPH_X_AXIS_TIMEShow the graph_major_ticks on the x-axis label as times. Default is not set.
Cw_GRAPH_X_AXIS_TITLEShow the graph_x_label string on the x-axis label. Default is set.
Cw_GRAPH_Y_AXIS_LEFT, Cw_GRAPH_Y_AXIS_RIGHTShow the left or right y-axis on the graph. Default is set.
Cw_GRAPH_Y_AXIS_LABEL_LEFT, Cw_GRAPH_Y_AXIS_LABEL_RIGHTShow numbers on the left or right y-axis. Default is set.
Cw_GRAPH_Y_MAJOR_TICK_LEFT, Cw_GRAPH_Y_MAJOR_TICK_RIGHTShow major tick marks on the left or right y-axis. Default is set. Unsetting this variable will make the major tick marks appear as minor tick marks if either of the Cw_GRAPH_Y_MINOR_TICK flags are set, otherwise the major tick marks will not appear at all.
Cw_GRAPH_Y_MINOR_TICK_LEFT, Cw_GRAPH_Y_MINOR_TICK_RIGHTShow minor tick marks on the left or right y-axis. Default is set.
Cw_GRAPH_Y_AXIS_TITLE_LEFT, Cw_GRAPH_Y_AXIS_TITLE_RIGHTShow the graph_x_label string on the left or right y-axis label. Default is set.

graph_traces

A positive integer specifying how many traces the widget will use. The traces are identified by consecutive integers starting with 0.

graph_x_axis_color

A number specifying the color of the x-axis. Default is 0x0 (black).

graph_x_axis_width

An integer specifying the width in pixels of the x-axis line. Default is 1.

graph_x_font

A string specifying the font for the x-axis display. Default is "helv12".

graph_x_label

A string specifying the label to use for the x-axis. Default is "X".

graph_x_label_color

A number specifying the color to use for the x-axis line. Default is 0x0 (black).

graph_x_major_length

An integer specifying the length of the major tick marks of the x-axis, in pixels. Default is 5.

graph_x_major_tick

A number specifying the interval of the major tick marks on the x-axis.

graph_x_minor_length

An integer specifying the length of the minor tick marks of the x-axis, in pixels. Default is 2.

graph_x_minor_tick

A number specifying the interval of the minor tick marks on the x-axis.

graph_xmax

A number specifying the maximum value on the x-axis. This number determines the upper limit of x values to be displayed.

graph_xmin

A number specifying the minimum value on the x-axis. This number determines the lower limit of x values to be displayed.

graph_y_axis_color_left, graph_y_axis_color_right

A number specifying the color of the left or right y-axis. Default is 0x0 (black).

graph_y_axis_width_left, graph_y_axis_width_right

An integer specifying the width in pixels of the left or right y-axis line. Default is 1.

graph_y_font_left, graph_y_font_right

A string specifying the font for the left or right y-axis display. Default is "helv12".

graph_y_label_color_left, graph_y_label_color_right

A number specifying the color to use for the left or right y-axis line. Default is 0x0 (black).

graph_y_label_left, graph_y_label_right

A string specifying the label to use for the left or right y-axis. Default is "Y".

graph_y_major_length_left, graph_y_major_length_right

An integer specifying the length of the major tick marks of the left or right y-axis, in pixels. Default is 5.

graph_y_major_tick_left, graph_y_major_tick_right

A number specifying the interval of the major tick marks on the left or right y-axis.

graph_y_minor_length_left, graph_y_minor_length_right

An integer specifying the length of the minor tick marks of the left or right y-axis, in pixels. Default is 2.

graph_y_minor_tick_left, graph_y_minor_tick_right

A number specifying the interval of the minor tick marks on the left or right y-axis.

graph_ymax_left, graph_ymax_right

A number specifying the maximum value on the left or right y-axis. This number does not determine the upper limit of y values to be displayed. That value is determined by the CwGraphSetYLimits function.

graph_ymin_left, graph_ymin_right

A number specifying the minimum value on the left or right y-axis. This number does not determine the lower limit of y values to be displayed. That value is determined by the CwGraphSetYLimits function.

Convenience Functions

Arguments

These arguments are used in the functions listed below.

bufferA buffer containing pairs of doubles in binary form, used by CwGraphAddRawPoints.
colorA number specifying a color.
countThe number of pairs to read, used by CwGraphAddRawPoints.
npointsA number of points.
onoffAn integer: 0 or nil = disable, all other values = enable. Used by CwGraphEnableTrace.
pointnoThe number of the point in the trace. Points are numbered by consecutive integers, starting at 0.
pointsA number specifying the number of points desired.
startThe starting point for reading the buffer, used by CwGraphAddRawPoints.
traceThe trace number.
widgetA CwGraph widget.
xA list of the x coordinates of the trace.
yA list of the y coordinates of the trace
ymaxA number specifying the upper limit of y values to be displayed.
yminA number specifying the lower limit of y values to be displayed.

Functions

CwGraphAddRawPoints (widget, trace, buffer, start, count) -- adds points as pairs of double-precision 8-bit numbers.

Returns t on success, else error.

CwGraphAddXYPoints (widget, trace, x, y) -- adds multiple points, using lists of x and y coordinates.

Returns t on success, else error.

CwGraphClearTrace (widget, trace) -- removes a trace.

Returns t on success, else error.

CwGraphEnableTrace (widget, trace, onoff) -- hides or displays a trace on the graph.

Returns t on success, else error.

CwGraphGetScreenData (widget, trace, pointno, npoints) -- gets screen data about specified points in the trace, expressed as a pointer to a binary file.

Returns a pointer to a binary file, or error.

CwGraphGetTraceData (widget, trace, pointno, npoints) -- gets data about specified points in the trace, expressed as a pointer to a binary file.

Returns a pointer to a binary file.

CwGraphGetTraceLength (widget, trace) -- gets the total number of points in the trace.

Returns t on success, else error.

CwGraphSetTraceColor (widget, trace, color) -- sets the color of a trace.

Returns t on success, else error.

CwGraphSetYLimits (widget, trace, ymin, ymax) -- sets the upper and lower y-axis limits for the display of traces. These limits are independent of the graph_ymin and graph_ymax instance variable values for the widget.

Returns t on success, else error.

Example

This example, ex_CwGraph.g, included in the product distribution.

#!/usr/cogent/bin/phgamma

/*
 * This example demonstrates a CwGraph.
 */

/*
 * Load the required files, which include two dynamic
 * libraries that are not generally needed for Photon
 * widgets.
 */
if (_os_ == "QNX4")
{
  dyna_add_lib("/usr/cogent/lib/photon_s.dlb");
  dyna_add_lib("/usr/cogent/lib/phwidgets.dlb");
}
require_lisp("PhotonWidgets.lsp");
PtInit(nil);

win = new(PtWindow);
grf = new(CwGraph);

grf.SetDim(400,300);
grf.fill_color = 0xffeeaa;

/*
 * Define the x_axis display.
 */
grf.graph_traces = 3;
grf.graph_x_axis_color = 0x00aaff;
grf.graph_x_axis_width = 2;
grf.graph_x_font = "lu10";
grf.graph_x_label = "X Axis";
grf.graph_x_label_color = 0x0;
grf.graph_x_major_length = 5;
grf.graph_x_major_tick = 20;
grf.graph_x_minor_length = 1;
grf.graph_x_minor_tick = 5;
grf.graph_xmax = 50;
grf.graph_xmin = -50;

/*
 * Define the left y_axis display.  Ignoring the right
 * y_axis will display its default values.
 */
grf.graph_y_axis_color_left = 0x00bbaa;
grf.graph_y_axis_width_left = 2;
//grf.graph_y_font_left = "lu12";
grf.graph_y_font_left = "TextFont10";
grf.graph_y_label_color_left = 0x0;
grf.graph_y_label_left = "Left";
grf.graph_y_major_length_left = 3;
grf.graph_y_major_tick_left = 10.3;
grf.graph_y_minor_length_left = 1;
grf.graph_y_minor_tick_left = 5.3;
grf.graph_ymax_left = 125.3;
grf.graph_ymin_left = -5;

/*
 * Set up the traces.  Each trace has its own
 * y_axis limits, color, and points.
 */
CwGraphSetYLimits(grf,0,-10,10);
CwGraphSetTraceColor(grf,0,0x0);
CwGraphAddXYPoints(grf,0,list(0,13.7,155),list(0,1.3,30));

CwGraphSetYLimits(grf,1,-10,10);
CwGraphSetTraceColor(grf,1,0xaa00aa);
CwGraphAddXYPoints(grf,1,list(-45,-30,0,30,45),list(0,-7,-9,-7,0));

CwGraphSetYLimits(grf,2,-10,10);
CwGraphSetTraceColor(grf,2,0x0000ff);
CwGraphAddXYPoints(grf,2,list(0,20,45,0,-25,-10,0),list(-1.5,-2.5,2.5,3,1.5,0,-1.5));

/*
 * Print the results of various functions as examples.
 */
princ("Trace 0 data: ",CwGraphGetTraceData(grf,0,1,1),"\n");
princ("Trace 0 screen data: ",CwGraphGetScreenData(grf,0,1,1),"\n");
princ("Trace 0 length: ",CwGraphGetTraceLength(grf,0),"\n");
princ("Trace 1 length: ",CwGraphGetTraceLength(grf,1),"\n");
princ("Trace 2 length: ",CwGraphGetTraceLength(grf,2),"\n");

PtRealizeWidget(win);
PtMainLoop();

Also see A CwGraph Rotating Cube in the Sample Code and Cool Stuff chapter of the Programmer's Manual for a more sophisticated example.