3D Zoom Fit

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
to2
Newbie
Newbie
Posts: 25
Joined: Thu Dec 03, 2009 12:00 am

3D Zoom Fit

Post by to2 » Fri Jul 18, 2014 12:24 pm

I'd like to draw waterfall series and allow the user to change rotation and elevation. Depending on rotation, elevation, zoom and Chart3DPercent corners of the chart may be positioned outside of the visible area. After every change of rotation, elevation and Chart3DPercent I'd like to zoom the chart in a way that it fits best into the visible area. How can I do that?

p.s. I'm using TeeChart 8.08.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: 3D Zoom Fit

Post by Narcís » Fri Jul 18, 2014 2:24 pm

Hi to2,

It's a little bit complicated but can be achieved using the "Protected Hack" with the TTeeCanvas3D class and the code below. Find also attached the complete project:

Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TeeGDIPlus, TeEngine, TeeComma, ExtCtrls, TeeProcs, Chart, TeCanvas;

type
  TForm1 = class(TForm)
    TeeCommander1: TTeeCommander;
    Chart1: TChart;
    procedure FormCreate(Sender: TObject);
    procedure Chart1AfterDraw(Sender: TObject);
  private
    { Private declarations }
    Procedure RectangleWithZ(Const Rect:TRect; var FPoints: TFourPoints; Z:Integer);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Series, TeeSurfa, TeeTools;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AddSeries(TSurfaceSeries.Create(Self)).FillSampleValues();
  Chart1.Chart3DPercent:=100;
  Chart1.Aspect.Orthogonal:=False;

  Chart1.Tools.Add(TRotateTool.Create(Self));
  //(Chart1.Tools.Items[0] as TRotateTool).Pen.Visible:=True;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var
  FourPoints : TFourPoints;
  FourPointsZ : TFourPoints;
begin
  RectangleWithZ(Chart1.ChartRect, FourPoints, 0);
  RectangleWithZ(Chart1.ChartRect, FourPointsZ, Chart1.Width3D);

  if not PointInRect(Chart1.ChartBounds, FourPoints[0].X, FourPoints[0].Y) or
      not PointInRect(Chart1.ChartBounds, FourPoints[1].X, FourPoints[1].Y) or
      not PointInRect(Chart1.ChartBounds, FourPoints[2].X, FourPoints[2].Y)  or
      not PointInRect(Chart1.ChartBounds, FourPoints[3].X, FourPoints[3].Y) or
      not PointInRect(Chart1.ChartBounds, FourPointsZ[0].X, FourPoints[0].Y) or
      not PointInRect(Chart1.ChartBounds, FourPointsZ[1].X, FourPoints[1].Y) or
      not PointInRect(Chart1.ChartBounds, FourPointsZ[2].X, FourPoints[2].Y)  or
      not PointInRect(Chart1.ChartBounds, FourPointsZ[3].X, FourPoints[3].Y) then
  begin
    Chart1.Aspect.Zoom:=Chart1.Aspect.Zoom - 10;
  end;
end;

type
  TCanvas3DAccess=class(TTeeCanvas3D);

Procedure TForm1.RectangleWithZ(Const Rect:TRect; var FPoints: TFourPoints; Z:Integer);
begin
  With Rect, TCanvas3DAccess(Chart1.Canvas) do
  begin
    Calc3DPoint(FPoints[0],Left,Top,Z);
    Calc3DPoint(FPoints[1],Right,Top,Z);
    Calc3DPoint(FPoints[2],Right,Bottom,Z);
    Calc3DPoint(FPoints[3],Left,Bottom,Z);
  end;
end;

end.
Attachments
RotateZoom.zip
(2.8 KiB) Downloaded 437 times
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

to2
Newbie
Newbie
Posts: 25
Joined: Thu Dec 03, 2009 12:00 am

Re: 3D Zoom Fit

Post by to2 » Mon Jul 21, 2014 1:10 pm

can be achieved using the "Protected Hack"
Thank you very much, Narcís. While trying it I've realized, it is not that simple to do the Protected Hack in BCB. I wonder, if Calc3DPoint can be done by using other functions like Calculate3DPosition.

to2
Newbie
Newbie
Posts: 25
Joined: Thu Dec 03, 2009 12:00 am

Re: 3D Zoom Fit

Post by to2 » Mon Jul 21, 2014 2:50 pm

I wonder, if Calc3DPoint can be done by using other functions
-> FourPointsFromRect works.

Post Reply