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

Message ListMessage List     Post MessagePost Message

  Is there a way to add a layer with an arbitrary PNG file to import from it?
Posted by DC Kelley on Aug-17-2011 03:47
My need is to load in a pre drawn base image in between certain layers and then add other layer details over that for the final chart.  By "in between " I mean on top of the charts plot area and axis (the import will be mostly transparent) but before I start loading up data layers (typical XY scatter in this use).  Offset and centering alignment are also questions, but I do not see a layer call to load a PNG/GIF/JPG etc file anywhere.

Can this be done?
Ideally the imported file would also get drawn/created by CD, but that is another thread.

  Re: Is there a way to add a layer with an arbitrary PNG file to import from it?
Posted by Peter Kwan on Aug-17-2011 21:16
Hi DC Kelley,

Yes. It can be done.

You may create a new DrawArea object, and draw the symbol or shape on it, or you may use it to load an existing image (DrawArea.load). Then you can create a scatter layer with one data point, and use DataSet.setDataSymbol3 to set the DrawArea as the scatter symbol. In this way, the DrawArea object will be inserted as a layer into the chart, and can be ordered relative to other layers using Layer.moveFront and Layer.moveBack.

For alignment, with the scatter layer method above, the scatter point is aligned with the center of the DrawArea. Is this suitable for your case?

Regards
Peter Kwan

  Re: Is there a way to add a layer with an arbitrary PNG file to import from it?
Posted by DC Kelley on Aug-18-2011 02:57
I am not sure but will try it as best I can.

Before I do, three thoughts,

Will the use of the shapes limit me to the 1000x1000 canvas for the imported object?

Does "center" here mean coor point 0,0 or some sort of center of mass for what is draw?

Is the basic drawing area coor system general in that respect or only in a the positive quadrant?   When I have tired to draw directly to it before, I recall issues with an inability to place the origin where I wanted it to be.

  Re: Is there a way to add a layer with an arbitrary PNG file to import from it?
Posted by Peter Kwan on Aug-19-2011 00:10
Hi DC Kelley,

I think my response to your other thread below should address what you actually want to do:

http://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_support&thread=1308004424

For your enquiry, in brief:

(A) The drawarea is not limited to 1000 x 1000. It can be much bigger in size.

(B) When you insert a DrawArea (whatever its size) somewhere in an XYChart, you need to tell ChartDirector where to insert the DrawArea.

A DrawArea is like a rectangle. Let's say it is 1800 x 900 pixels in size. If one say "put this 1800 x 900 pixels rectangle at position (45, 24) in the XYChart", what does it really mean? (A rectangle is not a single point - how is it possible to put a rectangle at a point?) In the addScatterLayer method, it means to put the center of the rectangle at (45, 24), in which (45, 24) is in data coordinates (the scale in the axes). ChartDirector can then figure out where to put the entire rectangle.

(C) The DrawArea coordinate system is always using (0, 0) at the top-left corner, just like the computer screen coordinate system. This should not be an issue because you can always convert one coordinate system to another coordinate system. (So if your shape is defined in another coordinate system, you just need to convert it to the DrawArea coordinate system before drawing it.) In particular, if the coordinate system you want to use is the data coordinate system of an XYChart object, you may use XYChart.getXCoor and XYChart.getYCoor to convert to the pixel coordinate system used by DrawArea.

Hope this can help.

Regards
Peter Kwan

  Re: Is there a way to add a layer with an arbitrary PNG file to import from it?
Posted by DC Kelley on Aug-25-2011 01:52
Between this and your other helpful post, I have it now.  Once I get my scatter rendering refined (issues of placement into data sets and layers today) I believe we can PNG a complex static image then only re-calc the image when the need arises and we will have this settled.  Hopefully all this will reduce what is becoming a rather slow render when huge PNGs (~4k on a side) are needed for details (yes I know I should rework all this to use a render more suitable for the screen size).