06-23-2008 03:58 AM
06-23-2008 07:48 AM
06-23-2008 09:19 AM
To get you started, here is some code that I have used to set a 1:1 aspect ratio for a graph:
// Reset the aspect ratio of a graph - which may have been autoscaled - to 1:1
// Assume panel handle is held in 'pMain' and the graph control is 'MAIN_GRAPH'.
{
double xmin, xmax, ymin, ymax;
int dum1, dum2;
double ratio1;
double ratio2;
// Find the current axis ranges
GetAxisScalingMode(pMain,MAIN_GRAPH,VAL_BOTTOM_XAXIS,&dum1,&xmin,&xmax);
GetAxisScalingMode(pMain,MAIN_GRAPH,VAL_LEFT_YAXIS,&dum1,&ymin,&ymax);
// Add a bit to the graph to ensure there is white space around the plots
xmax+=1.0;
ymax+=1.0;
xmin-=1.0;
ymin-=1.0;
// Now work out the ratio of x axis to y axis
ratio1 = (xmax-xmin)/(ymax-ymin);
// Now find out how big the plot area of the graph is in X and Y directions
GetCtrlAttribute(pMain,MAIN_GRAPH,ATTR_PLOT_AREA_WIDTH,&dum1);
GetCtrlAttribute(pMain,MAIN_GRAPH,ATTR_PLOT_AREA_HEIGHT,&dum2);
ratio2 = ((double)dum1)/((double)dum2);
// Need to make ratio1 = ratio2 by adjusting ranges
if (ratio1<ratio2)
{
// Need to expand X area
double expandval = 0.5*((ratio2/ratio1)-1.0)*(xmax-xmin);
xmin -= expandval;
xmax += expandval;
}
else
{
// Need to expand Y area
double expandval = 0.5*((ratio1/ratio2)-1.0)*(ymax-ymin);
ymin -= expandval;
ymax += expandval;
}
// Finally, set the new axis ranges
SetAxisScalingMode(pMain,MAIN_GRAPH,VAL_BOTTOM_XAXIS,VAL_MANUAL,xmin,xmax);
SetAxisScalingMode(pMain,MAIN_GRAPH,VAL_LEFT_YAXIS,VAL_MANUAL,ymin,ymax);
}
06-24-2008 05:29 AM - edited 06-24-2008 05:31 AM