Page 1 of 1

Shape Series depens on calling sequence

Posted: Fri Apr 13, 2012 5:25 pm
by 16559114
// This draws a correct shape
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.Clear;
Chart1.LeftAxis.SetMinMax( 0.0, 100.0 );
Chart1.BottomAxis.SetMinMax( 0.0, 100.0 );
Series1.X1 := 60;
Series1.Y1 := 50;
Series1.X0 := 20;
Series1.Y0 := 30;
end;


// Different sequence , draws an incorrect shape, see attached images
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.Clear;
Chart1.LeftAxis.SetMinMax( 0.0, 100.0 );
Chart1.BottomAxis.SetMinMax( 0.0, 100.0 );
Series1.X0 := 20;
Series1.Y0 := 30;
Series1.X1 := 60;
Series1.Y1 := 50;
end;

I use the shape series for reason that the rectangle tool does not size with zoom, which i need.
The shape series does size, but a shape is not movable or sizable with the mouse, which i need too.
Is there another way to honor both requirements ?

Regards
Gerhard

Re: Shape Series depens on calling sequence

Posted: Mon Apr 16, 2012 12:29 pm
by yeray
Hi Gerhard,

I think the easiest way to do this would be using a TRectangleTool. To zoom&scroll it with the chart, you could save the rectangle coordinates transformed to axes values (ie P0X, P0Y, P1X, P1Y) and redraw the tool with the reconverted values at OnZoom/OnUndoZoom/OnScroll events:

Code: Select all

uses Series, TeeTools, Math;

var P0X, P0Y, P1X, P1Y: Double;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AddSeries(TFastLineSeries);

  Chart1.Axes.Bottom.SetMinMax(0,100);
  Chart1.Axes.Left.SetMinMax(0,100);

  with Chart1.Tools.Add(TRectangleTool) as TRectangleTool do
  begin
    Text:='my rectangle Tool';
    PositionUnits:=muPixels;
    OnDragged:=RectToolDragged;
    OnResized:=RectToolResized;
  end;

  P0X:=20;
  P0Y:=30;
  P1X:=60;
  P1Y:=50;

  redrawRectangleTool;
end;

procedure TForm1.redrawRectangleTool;
begin
  Chart1.Draw;
  with Chart1.Tools[0] as TRectangleTool do
  begin
    Left:=Chart1.Axes.Bottom.CalcPosValue(min(P0X,P1X));
    Top:=Chart1.Axes.Left.CalcPosValue(max(P0Y,P1Y));
    Width:=Chart1.Axes.Bottom.CalcSizeValue(abs(P1X-P0X));
    Height:=Chart1.Axes.Left.CalcSizeValue(abs(P1Y-P0Y));
  end;
end;

procedure TForm1.recalcRectangleTool(tool: TObject);
begin
  with tool as TRectangleTool do
  begin
    P0X:=Chart1.Axes.Bottom.CalcPosPoint(Left);
    P0Y:=Chart1.Axes.Left.CalcPosPoint(Top);
    P1X:=Chart1.Axes.Bottom.CalcPosPoint(Left+Width);
    P1Y:=Chart1.Axes.Left.CalcPosPoint(Top+Height);
  end;
end;

procedure TForm1.RectToolDragged(Sender: TObject);
begin
  recalcRectangleTool(Sender);
end;

procedure TForm1.RectToolResized(Sender: TObject);
begin
  recalcRectangleTool(Sender);
end;

procedure TForm1.Chart1Zoom(Sender: TObject);
begin
  redrawRectangleTool;
end;

procedure TForm1.Chart1UndoZoom(Sender: TObject);
begin
  redrawRectangleTool;
end;

procedure TForm1.Chart1Scroll(Sender: TObject);
begin
  redrawRectangleTool;
end;

Re: Shape Series depens on calling sequence

Posted: Tue Apr 17, 2012 3:51 pm
by 16559114
Hello Yeray,

thank you for the information.
I will change the Shape series to a rectangle tool.

But there is still the behaviour where the displayed shape depends on the parameter sequence.
For me, it is clear now.
But maybe other people would save some investigation time if such behaviour is documented.

Regards
Gerhard Sachs