Page 1 of 1

Relating point clicked and axis

Posted: Thu Mar 27, 2008 6:43 pm
by 10545848
I am drawing polygons on the ColorGridSeries chart and am trying to understand the connection between the X/Y values obtained in the Mouse Down event and the X/Z values in the Chart1.Series.AddXYZ method. As I add data points to the plot using the AddXYZ method, I want to change the values of points if I determine they are inside the polygons that I drew earlier…say, set them to zero.

So that you know, I set IrregularGrid = False when initializing the plot. I am setting my own axis labels by calling Chart1.Axes.Left.Items.Clear and Chart1.Axes.Bottom.Items.Clear, then add my own axis labels. I am not sure if this is necessary, but there was a bug in the plot code some time ago that caused zooming and panning to redraw REAL slow. Any ways I do not think that is important right now, just wanted to mention it.

In the Mouse Down event, I use the following code to get the index of the clicked point on the X and Z axis:

// X and Y are from the Chart1MouseDown entry point
k := Chart1.Series[0].Clicked(X, Y);
r := k div Chart1.Series.NumZValues;
c := k mod Chart1.Series.NumZValues;

This seems to work just fine. When I use r and c to calculate my axis values with my ScaleMul and ScaleOff it all works fine. For example:

My_X := r * xScaleMul + xScaleOff;
My_Y := c * zScaleMul + zScaleOff ;


Later in my code I add the data points to the plot as follows:

// DblImageData is a 2D array of points to generate the image.
For i := 0 to High(DblImageData) do
For j := 0 to High(DblImageData[0]) do
begin
p.x := i;
p.y := j
// wn_PnPoly checks to see if point p is inside the polygon formed
// using points in Polygon_Point_List
if (wn_PnPoly(p, Polygon_Point_List) <> 0) then
DblImageData[i,j] := 0;

Chart1.Series.AddXYZ(i, DblImageData[i,j], j);
end;

I can see the polygons appear on the plots, but not in the place I drew them. They appear to be upside down and flipped. It is as if the data is not added using the bottom left point as 0,0.

Can you explain what I am doing wrong?

Thanks in advance.

Posted: Fri Mar 28, 2008 10:10 am
by yeray
Hi dpatch,

Yes, this is a known bug (TV52012634) in the wish list to be fixed as soon as possible.

And note that this can be reproduced the simple code:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var x,z: Integer;
begin
  for x:=0 to 5 do
    for z:=0 to 3 do
    begin
      Series1.AddXYZ(x,random,z);
    end;
end;

Posted: Fri Mar 28, 2008 1:27 pm
by 10545848
Is there a work around? Is there a time line for the fix? Can I be notified when this is fixed is completed?

I am toast...

Posted: Fri Mar 28, 2008 2:09 pm
by narcis
Hi dpatch,
Is there a work around?
Yes, this happens when series rows and columns start at value zero. A workaround is doing something like this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var x,z: Integer;
begin
  for x:=0 to 5 do
    for z:=0 to 3 do
    begin
      Series1.AddXYZ(x+1,random,z+1);
    end;
end;
Is there a time line for the fix?
It's a high priority item in our defect list but we can't give a date for the bug fix at the moment.
Can I be notified when this is fixed is completed?
I recommend you to be aware at this forum or subscribe to our RSS Feed for new release announcements and what's fixed on them.

Posted: Fri Mar 28, 2008 4:34 pm
by 10545848
I tried your fix and it does not properly place the mouse point above the correct row and column. However, when I try to zero out the cells inside the polygon, it stills seems to be flipped both horizontally and backwards.

Is the X/Y numbering of the axis and the same as that reported back from the clicked method when called in the Mouse Down event? It almost seems that this is the issue. For example, the X/Y passed into the Mouse Down event has a (0,0) position at the top right instead of lower left...or maybe the data is put into the series witht he [0,0] element on the lower right of the screen.

Can you tell me if this will still be a problem if I set IrregularGrid = True.

Posted: Mon Mar 31, 2008 8:52 am
by narcis
Hi dpatch,

I'm not sure about which is your exact problem. However, code below works fine for me here. Does it work fine at your end? If this doesn't help could you please give us some more details about your problem?

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var x,z: Integer;
begin
  for x:=0 to 5 do
    for z:=0 to 3 do
    begin
      Series1.AddXYZ(x+1,random,z+1);
    end;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var i: Integer;
begin
  i:=Series1.Clicked(X,Y);

  if i<>-1 then
    Chart1.Title.Text[0]:=FloatToStr(Series1.XValues[i]) + ', ' +
                          FloatToStr(Series1.ZValues[i]);

end;
Please read here what using IrregularGrid property set to true implies.

Thanks in advance.

Posted: Mon Mar 31, 2008 6:40 pm
by 10545848
Very helpful...Thank you!

I was being confused between pixel locations on the screen and x/z axis indices. This solved my problem.

Now, looking at your code below, how do I translate the other way. Given the Series1.XValues anf Series1.YValues values, how do I calculate the pixel location X,Y that was passed into the clicked routine earlier? I would like to re-draw my polygon at a later time.

Thanks in advance

Posted: Tue Apr 01, 2008 7:16 am
by narcis
Hi dpatch,

You need to use Series1.CalcXPos(ValueIndex) and Series1.CalcYPos(ValueIndex) or Series1.CalcXPosValue(XValue) and Series1.CalcYPosValue(YValue). First option returns pixel location of a point index while the second returns the pixel screen coordinate of the specified value.

Hope this helps!