Anybody out there using the PtTrend widget? Need help.

I am having several problems with the PtTrend widget:

  1. I set Pt_ARG_TREND_MAX and Pt_ARG_TREND_MIN to 75 and -75 in PhAB
    (Version 2), then did a PtGetResource in my code - they are still set to
    the default values (32767 and -32767). How come?

  2. I try to set Pt_ARG_TREND_FLAGS as follows:

PtSetResource(ABW_widgetname, Pt_ARG_TREND_FLAGS, Pt_TRUE,
Pt_TREND_HORIZONTAL|Pt_TREND_LEFT_TO_RIGHT);

if I do this nothing is plotted; if I dont try to set
Pt_ARG_TREND_FLAGS, it plots the data from right to left (the default).
How come I can’t set this resource?

  1. I don’t see anything in the documentation about how to set the
    number of points that are displayed in a PtTrend widget - what is the
    default (looks like around 500?) and how do I change it?

Thanks for your help.

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

  1. initialize the widget
  2. set the minimum and maximum trend values
  3. 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();
}

Thanks for your response. I’ll give this a try. Regarding the number of points plotted, are you
saying that there are x points plotted per pixel width of the widget? This seems odd to me - what
if you want to plot 100 points (say) and you want it to fill the screen? No can do?

Steven Faludi wrote:

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

  1. initialize the widget
  2. set the minimum and maximum trend values
  3. 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();
}