Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - how to make zoom in PtTrend: (7 Items)
   
how to make zoom in PtTrend  
Hi!

I am trying to make zoom in Y axis in PtTrend by getting maximum and minimum value of PtTrend and then setting those 
values anew. Unfortunately I cannot get them properly(their values displayed in console are wrong). I use PtGetResource 
function a lot and it's working well but not in this case. Could you tell me why is it hapening?

Secondly, I would like to zoom in X axis also, but I do not know how to send table with trend data from feeding callback
 to other callback which will make zoom(I plan to make zoom X by displaying only part of all data on whole PtTrend). 
Could you tell me how to do it?

Lastly, could you give me some advice about which widget is the best for activate zoom callback? For now I use buttons. 
I am a beginner so forgive me those questions.

Thank you for your patience and your help in advance.
 Catherine

Re: how to make zoom in PtTrend  
It is difficult to tell what is wrong without seeing the source code. Sample code would be a good start.

You need to change the number of data points, and re-load your data when your 'X' scale changes. I can't tell if PtTrend
 supports it, but PtMTrend supports this for sure. 
PtMTrend also supports min/max for the 'Y'.

I am not sure what you mean by 'zoom' callback. Please advise.
Re: how to make zoom in PtTrend  
> It is difficult to tell what is wrong without seeing the source code. Sample 
> code would be a good start.
> 
> You need to change the number of data points, and re-load your data when your 
> 'X' scale changes. I can't tell if PtTrend supports it, but PtMTrend supports 
> this for sure. 
> PtMTrend also supports min/max for the 'Y'.
> 
> I am not sure what you mean by 'zoom' callback. Please advise.
Thank you for your response.
This is the code of callback which is activated by button "START". This callback is named start.c.

int
start( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )

	{
int i;
int b, *c, d, e, max, min;

	/* eliminate 'unreferenced' warnings */
	widget = widget, apinfo = apinfo, cbinfo = cbinfo;
PtGetResource(ABW_numericinteger, Pt_ARG_NUMERIC_VALUE, &c, 0);//getting the number of samples from user
printf("numeric value is %d\n", *c);
d= *c;
printf("d=%d\n", d);//printing the number of samples

int x[d], max, min;
srand(time(0));
	printf("figures:\n");
	for(i=0; i<d; i++){
	x[i]= -50 + rand() % 100;//this is the table with data which will be displayed on graph
	printf("%d | ", x[i]);
	}

max=x[0];
min=x[0];

for(i=1;i<d;i++){
		if(max-x[i]>=0){
			max=max;
		}else{
			max=x[i];
		}
	}//searching for biggest datum
printf("\n\nbiggest datum %d", max);

if(max>0){
PtSetResource(ABW_trend, Pt_ARG_TREND_MAX, 1.1*max, 0);//setting max value of trend
}else{
PtSetResource(ABW_trend, Pt_ARG_TREND_MAX, 0.9*max, 0);//setting max value of trend
}
for(i=1;i<d;i++){
			if(min-x[i]<=0){
				min=min;
			}else{
				min=x[i];
			}
		}//serching for smallest datum
	printf("\n\nsmallest datum %d", min);

if(min>0){
PtSetResource(ABW_trend, Pt_ARG_TREND_MIN,0.9*min, 0);//setting min value of trend
}else{
PtSetResource(ABW_trend, Pt_ARG_TREND_MIN, 1.1*min, 0);//setting min value of trend


e=700/d;//PtTrend widget is 700pixels of width
printf("\ne=%d\n", e);//increment
PtSetResource(ABW_trend, Pt_ARG_TREND_INC, e, 0);//setting increment

PtSetResource(ABW_trend, Pt_ARG_TREND_DATA, x, d); // displaying graph 

	return( Pt_CONTINUE);
             }

This is the code of callback which is activated by "ZOOM IN" button. The callback is called zoom.c and zooms Y axis.


int
zoom( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )

	{
int *a,*b,*c, d,e,a1,b1;
	/* eliminate 'unreferenced' warnings */
	widget = widget, apinfo = apinfo, cbinfo = cbinfo;

PtGetResource(ABW_trend, Pt_ARG_TREND_MAX, &b, 0);//getting the max value of trend
PtGetResource(ABW_trend, Pt_ARG_TREND_MIN, &a, 0);/getting the min value of trend

printf("\na=%d\nb=%d\n",*a,*b);
a1= *a;
b1= *b;
printf("\na=%d\nb=%d\n",a1,b1);//printing min and max(it goes wrong, it prints wrong values, so the rest of the code is 
not working)

e=(b1-a1)/5;//counting the width of areas beetween lines of grid(I set 4 lines so 5 areas)
printf("e=%d\n",e);
// if i want to zoom the area at the bottom i set the parameters like below
PtSetResource(ABW_trend, Pt_ARG_TREND_MAX, a1+e, 0);//setting max value of trend
PtSetResource(ABW_trend, Pt_ARG_TREND_MIN, a1, 0);//setting min value of trend
	return( Pt_CONTINUE );
          }

About zooming in Xaxis i do not know how to send table x from callback start.c to callback zoom.c(i called it in earlier
 post 'zoom callback').

I will try with mtrend. I hope I can make it. I will tell you if it work.
Thank you very much.

Catherine
Re: how to make zoom in PtTrend  
This is a start. The MIN and MAX are NOT 'int's they are 'short's. They are also not floating values.
Re: how to make zoom in PtTrend  
Thank you Misha it is finally working:) eh such a stupid mistake...shame on me. Remains only zooming X axis...
Re: how to make zoom in PtTrend  
Some suggestions (some a better than others):
-- use a global for your array
-- allocate your array and pass it around by using Pt_ARG_POINTER on your window..
Re: how to make zoom in PtTrend  
I do not know how to make global variable which is a array. I made a library globals.h and write in it #define X[2000]. 
Then I attached globals.h to all callbacks, but when the program was compiled, errors came up. It seems that it cant see
 X in source code. For example code: 
int x[20];
for(i=0;i<20;i++){
X[i]=x[i];
}
Error:
C:/ide-4.6-workspace/vib1/src/start.c: In function 'start':
C:/ide-4.6-workspace/vib1/src/start.c:89: error: expected expression before '[' token

Please help.