CalcXPos and XScreenToValue
Posted: Tue Oct 11, 2005 8:20 pm
What is the difference between CalcXPos and XScreenToValue?
I am using DrawZoomRectangle to draw a boxes on the screen (TColorGridSereis) and want to remember where the box is so that when the screen is resized (or Zoomed), I can redraw it in the correct position.
As an example, in the Chart1MouseDown and Up events, I have the following code to grab the Top, Left, Bottom and Right points of the box...
// Calculate the left x index.
ind := Chart1.Series[0].XScreenToValue(X);
fIERRecList[Len].iX0 := ind;
fIERRecList[Len].Left := -1;
for i := 0 to High(DblImageData[0]) do
if Abs(xScaleOff + (xScaleMul * i)) -
Abs(ind) < 0.00000001 then
begin
fIERRecList[Len].Left := Max(i-1, 0);
break;
end;
// Similar code as above for Right, Top and Bottom
Then when the form is resized, I have code like this...
// Calculate X and Y positions on the new resized screen.
fIERRecList.zX0 :=
Chart1.Series[0].CalcXPosValue(fIERRecList.iX0);
fIERRecList.zX1 :=
Chart1.Series[0].CalcXPosValue(fIERRecList.iX1);
fIERRecList.zY0 :=
Chart1.Series[0].CalcYPosValue(fIERRecList.iY0);
fIERRecList.zY1 :=
Chart1.Series[0].CalcYPosValue(fIERRecList.iY1);
// Calculate the Left x index.
for j := 0 to High(DblImageData[0]) do
if Abs(xScaleOff + (xScaleMul * j)) -
Abs(fIERRecList.iX0) < 0.00000001 then
begin
fIERRecList.Left := Max(j-1, 0);
break;
end;
// Similar code as above for Right, Top and Bottom
// Now I can redraw the box.
What I am doing here is working, but seems very inefficient and slow. Since I use an axis offset and multiplier, I do not know how to calculate the information I need directly without the For Loop. Is there I better way to do this? Is my explanation clear?
I am using DrawZoomRectangle to draw a boxes on the screen (TColorGridSereis) and want to remember where the box is so that when the screen is resized (or Zoomed), I can redraw it in the correct position.
As an example, in the Chart1MouseDown and Up events, I have the following code to grab the Top, Left, Bottom and Right points of the box...
// Calculate the left x index.
ind := Chart1.Series[0].XScreenToValue(X);
fIERRecList[Len].iX0 := ind;
fIERRecList[Len].Left := -1;
for i := 0 to High(DblImageData[0]) do
if Abs(xScaleOff + (xScaleMul * i)) -
Abs(ind) < 0.00000001 then
begin
fIERRecList[Len].Left := Max(i-1, 0);
break;
end;
// Similar code as above for Right, Top and Bottom
Then when the form is resized, I have code like this...
// Calculate X and Y positions on the new resized screen.
fIERRecList.zX0 :=
Chart1.Series[0].CalcXPosValue(fIERRecList.iX0);
fIERRecList.zX1 :=
Chart1.Series[0].CalcXPosValue(fIERRecList.iX1);
fIERRecList.zY0 :=
Chart1.Series[0].CalcYPosValue(fIERRecList.iY0);
fIERRecList.zY1 :=
Chart1.Series[0].CalcYPosValue(fIERRecList.iY1);
// Calculate the Left x index.
for j := 0 to High(DblImageData[0]) do
if Abs(xScaleOff + (xScaleMul * j)) -
Abs(fIERRecList.iX0) < 0.00000001 then
begin
fIERRecList.Left := Max(j-1, 0);
break;
end;
// Similar code as above for Right, Top and Bottom
// Now I can redraw the box.
What I am doing here is working, but seems very inefficient and slow. Since I use an axis offset and multiplier, I do not know how to calculate the information I need directly without the For Loop. Is there I better way to do this? Is my explanation clear?