The PtTrend widge is known to have problems.
It is however able to plot trend graphs from right to left.
The following complete program demonstrates how to
- initialize the widget
- set the minimum and maximum trend values
- scroll a sine curve into view from right to left
Note that the number of trend-points depends on the width
of the widget.
//-------------------------------------------------------
//
// trend.c
//
// This complete program demonstrates the PtTrend widget.
//
// Compile and link as follows:
//
// $gcc -lph -lm trend.c
//
//-------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include <Pt.h>
#include <Ph.h>
int main()
{
PhDim_t dim;
PhPoint_t pos;
int i, n;
short x;
const double pi = 3.1415926;
PtArg_t args[10];
PtWidget_t *window, *trend;
// Initialize the widget library
if ( PtInit(NULL) ) {
fprintf( stderr, “\nPtInit() failed!\n” );
exit ( -1 );
}
// Create the base window
n = 0;
dim.w = dim.h = 400;
PtSetArg( &args[n++], Pt_ARG_DIM, &dim, 0 );
if ( NULL == (window = PtCreateWidget( PtWindow, NULL, n, args ) )) {
fprintf( stderr, “\nFailed to create PtWindow widget.”);
exit( -1 );
}
// Create a PtTrend widget
n = 0;
pos.x = pos.y = 15;
dim.w = dim.h = 360;
PtSetArg( &args[n++], Pt_ARG_DIM, &dim, 0 );
PtSetArg( &args[n++], Pt_ARG_POS, &pos, 0 );
PtSetArg( &args[n++], Pt_ARG_TREND_MIN, -1050, 0 );
PtSetArg( &args[n++], Pt_ARG_TREND_MAX, 1050, 0 );
PtSetArg( &args[n++], Pt_ARG_TREND_DATA, NULL, 0 ); // Clear the graph
PtSetArg( &args[n++], Pt_ARG_TREND_FLAGS, Pt_GRID_FORCE|Pt_PIXEL, Pt_GRID_FORCE|Pt_PIXEL );
if ( NULL == (trend = PtCreateWidget( PtTrend, window, n, args ) ) ) {
fprintf( stderr, “\nFailed to create PtTrend widget” );
PtExit( -1 );
}
// Realize the base window.
PtRealizeWidget( window );
// Scroll a sine curve into view
for( i=0; i<360; i++ ) {
x = 1000.0 * sin( i * pi / 180.0 );
delay(10);
PtSetResource( trend, Pt_ARG_TREND_DATA, &x, 1 );
}
// Wait for events
PtMainLoop();
}