Page 1 of 1
3D Zoom Fit
Posted: Fri Jul 18, 2014 12:24 pm
by 10554786
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.
Re: 3D Zoom Fit
Posted: Fri Jul 18, 2014 2:24 pm
by narcis
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.
Re: 3D Zoom Fit
Posted: Mon Jul 21, 2014 1:10 pm
by 10554786
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.
Re: 3D Zoom Fit
Posted: Mon Jul 21, 2014 2:50 pm
by 10554786
I wonder, if Calc3DPoint can be done by using other functions
-> FourPointsFromRect works.