ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  X & Y Axis Auto-Scaling Perspective
Posted by Chuck Willette on Feb-10-2012 22:49
I am generating XY Charts, Contour Charts and a Surface Chart whose X & Y axis'
represent the width and height of a surface. The surface dimensions can be anything from
square to rectilinear (e.g. 40W" x 80H" or 80W" x 40H"). The charts generated with auto-
scaling will draw equal pixel-length axis' for each dimension. That is, the 40" axis is
displayed as the same length as the 80" axis. The result is a distorted perspective. How
can I get the rendering to be the correct perspective?

Regards,
Chuck

  Re: X & Y Axis Auto-Scaling Perspective
Posted by Peter Kwan on Feb-11-2012 03:27
Hi Chuck,

The axes pixel lengths are the width and height of the plot area for an XYChart (or the plot region for a SurfaceChart), which are specified by your code. If your code knows the ratio it wants to use, it can always set the axis pixel lengths to the proper ratio, and the axis to the proper scale.

Do you want ChartDirector to automatically scale the axes (instead of your code specifying the scale to use), and to automatically modify the plot area size based on the auto-scaling result so that the aspect ratio is 1:1?

In XYChart, this can be achieved using something like:

... create chart as usual ...

c->layoutAxes(); //auto-scale axis

//These are the axis range as determined by ChartDirector auto-scaling
double xRange = c->xAxis()->getMaxValue() - c->xAxis()->getMinValue();
double yRange = c->yAxis()->getMaxValue() - c->yAxis()->getMinValue();

//The original plot area size set by your code
double newPlotAreaWidth = c->getPlotArea()->getWidth();
double newPlotAreaHeight = c->getPlotArea()->getHeight();

//Extend either the width or height of the plot area to match with the aspect ratio of the scale
if (xRange / newPlotAreaWidth < yRange / newPlotAreaHeight)
    newPlotAreaHeight = yRange * newPlotAreaWidth / xRange;
else
    newPlotAreaWidth = xRange * newPlotAreaHeight / yRange;

c->setPlotArea(c->getPlotArea()->getLeftX(), c->getPlotArea()->getTopY(), newPlotAreaWidth, newPlotAreaHeight);

For a SurfaceChart, it is more compilcated, because there is no "layoutAxes" method. The easiest method I can think of is to create a dummy "staging chart". It is like:

SurfaceChart *c = .......;  //same size as the actual chart
c->setPlotRegion = .......; //suggested plot area size - to be adjusted later for aspect ratio

//pass the min/max value of the data range to ChartDirector
c->xAxis()->setLinearScale(minX, maxX);
c->yAxis()->setLinearScale(minY, maxY);

//performs auto-scaling based on the data range and suggested plot area size
c->layout();

.... now you can get the axis range like in the XYChart case, and compute the
.... newPlotAreaWidth and newPlotAreaHeight. You can use these lengths to plot your
.... real SurfaceChart, and use Axis.setLinearScale to set the x and y axis scale to the
.... scale as determined in the "staging chart".


Hope this can help.

Regards
Peter Kwan