|
DrawArea Rotate |
Posted by Max on Oct-16-2009 22:31 |
|
Hi Peter,
How do i rotate a draw area in perl? Just looking for the syntax.
$ellipse = $c->makeChart3();
$ellipse->rotate(45);
This seems to rotate the whole chart not the ellipse i drew...
any ideas?
Max |
Re: DrawArea Rotate |
Posted by Max on Oct-16-2009 22:44 |
|
The ellipse is draw by:
$ellipse->circle($c->getXCoor(50),$c->getYCoor(50), $c->getXCoor(90)-
$c->getXCoor(50),$c->getYCoor(50)-$c->getYCoor(75),0x80ff0000, 0x80ff0000); |
Re: DrawArea Rotate |
Posted by Peter Kwan on Oct-17-2009 00:30 |
|
Hi Max,
The variable called "$ellipse" in your code is actually the entire chart. So if you call $ellipse->rotate, it rotates the entire chart.
There is currently no API in ChartDirector to rotate a part of the image. The DrawArea API is a direct draw API. It means when you call DrawArea.circle, the ellipse is drawn immediately onto the image surface, and any pixels that overlap with the filled region of the ellipse will be overwritten. It is no longer possible to distinguish the ellipse from the other pixels of the chart. If you rotate the ellipitical part, you will leave a "hole" behind.
To rotate just the ellipse, there are two methods:
(a) You would need to rotate the ellipse before your ask ChartDirector to draw it. Because there is no API for a rotated ellipse in ChartDirector, you would need to approximate the rotated ellipse with a polygon and ask ChartDirector to draw the polygon.
For your information, all shapes in computer graphics are polygons. Internally, ChartDirector will convert an ellipse to a polygon before drawing it. So converting an ellipse to a polygon yourself will not make the ellipse look ugly if it is coverted properly.
(b) Create a separate drawarea with a transparent background, and just draw an ellipse on it. Then rotate the entire drawarea. Then "merge" the drawarea onto your chart (using DrawArea.merge).
Hope this can help.
Regards
Peter Kwan |
Re: DrawArea Rotate |
Posted by Max on Oct-17-2009 00:47 |
|
How do i create a new drawarea in perl? (part b) |
Re: DrawArea Rotate |
Posted by Peter Kwan on Oct-17-2009 01:00 |
|
Hi Max,
It is like:
$d = new DrawArea();
$d->setSize(200, 200, $perlchartdir::Transparent);
$d->ellipse(....);
$d->rotate(....);
$chart->getDrawArea()->merge($d, 75, 44, $perlchartdir::TopLeft, 0);
Hope this can help.
Regards
Peter Kwan |
Re: DrawArea Rotate |
Posted by Max on Oct-17-2009 01:39 |
|
One more question. How do i move it to the front of the chart? |
Re: DrawArea Rotate |
Posted by Peter Kwan on Oct-17-2009 16:00 |
|
Hi Max,
If you "make" the chart first, then draw the ellipse, then the ellipse will be in front of the chart.
In ChartDirector, there is even an API to "make" the chart and return the resulting draw area object. It is:
$chartDrawArea = $c->makeChart3();
Hope this can help.
Regards
Peter Kwan |
Re: DrawArea Rotate |
Posted by Max on Oct-17-2009 23:05 |
|
Hi Peter,
There are white spots on the chart i attached. I thought I had made everything
transparent but apparently not. Can you tell me what i'm missing?
Also, the ellipse is not centered where i thought it should be. Am i getting the
coordinates correctly?
Thanks!
$arrx = [50];
$arry = [50];
$x = 50;
$y = 50;
$a = 15;
$b = 25;
$f = 0x80ff0000;
$e = 0xffff0000;
my $c = new XYChart(1200, 1200);
$c->setPlotArea(95, 100, 1000, 1000, 0xffffff, -1, 0xc0c0c0, 0xc0c0c0, -1);
$c->addLegend(95, 45, 0, "timesbi.ttf", 16)->setBackground($perlchartdir::Transparent);
$title = "Ellipse";
$c->addTitle("$title", "timesbi.ttf", 24);
$c->yAxis()->setTitle("Y-Axis", "arialbi.ttf", 18);
$c->yAxis()->setWidth(2);
$c->xAxis()->setTitle("X-Axis", "arialbi.ttf", 18);
$c->xAxis()->setWidth(2);
$c->xAxis()->setLinearScale(0, 100, 10);
$c->yAxis()->setLinearScale(0, 100, 10);
$c->xAxis()->setLabelStyle("arialbi.ttf", 12, 0x000000, 0);
$c->yAxis()->setLabelStyle("arialbi.ttf", 12, 0x000000, 0);
$c->setClipping(0);
my $layer1 = $c->addScatterLayer($arrx, $arry, "Center", $perlchartdir::DiamondSymbol,
6, 0xff9933);
$chart = $c->makeChart3();
$ellipse = new DrawArea();
$ellipse->setSize(1000, 1000, $perlchartdir::Transparent);
$ellipse->circle($c->getXCoor($x),$c->getYCoor($y), $c->getXCoor($x+$a)-$c-
>getXCoor($x),$c->getYCoor($y)-$c->getYCoor($y+$b),$e,$f);
$ellipse->rotate(45);
$chart->merge($ellipse, 0, 0, $perlchartdir::TopLeft, 0);
$outname = "ellipse.png";
$c->makeChart($outname);
|
Re: DrawArea Rotate |
Posted by Peter Kwan on Oct-18-2009 12:34 |
|
Hi Max,
When your code rotates something, it will leave a "hole" behind. The color of the hole is determined by the second argument to the "rotate" function, and is white by default (if the argument is not specified). The white region in your image is the "hole" left by rotating the image.
To solve the problem, you may specify "Transparent" as the "hole" color when rotating the image.
$ellipse->rotate(45, $perlchartdir::Transparent);
Hope this can help.
Regards
Peter Kwan |
Re: DrawArea Rotate |
Posted by Robert on Nov-18-2009 02:06 |
|
Hi Peter,
I have found that the workaround you give above does not seem to work for SVGs. Is there another work around which allows you to rotate an ellipse which will work for SVGs?
Thanks,
Robert |
Re: DrawArea Rotate |
Posted by Peter Kwan on Nov-18-2009 17:45 |
|
Hi Robert,
Unluckily, currently, not all low level graphics functions are supported in SVG. ChartDirector currently can only output chart objects (all objects derived from BaseChart, such as PieChart, XYChart, PolarChart, AngularMeter, LinearMeter, PyramidChart, SurfaceChart), but does not fully support DrawArea.
I think you can draw the ellipse with DrawArea in SVG, not cannot rotate it (the DrawArea.rotate is not supported in SVG).
If you would like to draw a rotated ellipse, the suggested method is to draw a polygon instead. If the polygon has sufficient number of sides, it will look like an ellipse.
(Whereas I am not sure how the SVG viewer is implemented, I think internally it will change the ellipse into a polygon with many sides before rendering it. This is also how ChartDirector render the ellipse internally in raster graphics mode. So the polygon method should be acceptable.)
Hope this can help.
Regards
Peter Kwan |
Re: DrawArea Rotate |
Posted by Max on Dec-06-2010 22:41 |
|
Hi Peter,
I'm back with yet another question about the DrawArea rotation methods. This time it's in
java. I've implemented zoom and scrolling for a desktop application. I've added the ellipses
and that works perfectly. However, when I zoom in, the DrawArea clipping rectangle
appears to have rotated also, and is clipping the ellipse when zoomed in.
I attached a picture of it. I've noticed the DrawArea.setClipRect method, but can't quite
seem to get it to work. Any help would be appreciated.
Thanks again!
Max
|
Re: DrawArea Rotate |
Posted by Peter Kwan on Dec-07-2010 00:09 |
|
Hi Max,
Is your code drawing the ellipse in a DrawArea, then rotate the DrawArea. the merge the DrawArea into the chart?
If this is the case, is it possible that your DrawArea is too small, so that it cannot contain the original non-rotated ellipse? For example, if your DrawArea is 500 x 500 pixels, but your ellipse is 800 x300 pixels wide, then it is not possible for the DrawArea to contain the ellipse, and part of the ellipse must be clipped even before rotation.
If the above is the cause of the problem, to solve the problem, please use a bigger DrawArea.
Regards
Peter Kwan |
|