Re: [ROOT] Aspect Ratio of Graphics in TPad

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Oct 23 2001 - 17:54:27 MEST


Hi Thomas,

You may get some inspiration from the simple macro below.
do .x ortho.C

//file ortho.C
void makeOrtho() {
   Double_t w = gPad->GetWw()*gPad->GetAbsWNDC();
   Double_t h = gPad->GetWh()*gPad->GetAbsHNDC();
   //we fix the x range between 0 and 100 for example
   //let's compute the y range to get an orthonormal view
   Double_t xmin = 0;
   Double_t xmax = 100;
   Double_t ymin = 0;
   Double_t ymax = xmax*h/w;
   gPad->Range(xmin,ymin,xmax,ymax); 
}

void ortho() {
   TCanvas *c1 = new TCanvas("c1");
   TExec *exe = new TExec("ex","makeOrtho()");
   exe->Draw();
   TArc *arc = new TArc(50,50,10);
   arc->Draw();
}


The trick is to draw a TExec object. The function referenced by the TExec
object,
here makeOrtho, is called for every mouse event and it will recompute
the pad size to be orthonormal. TPostScript output will also be OK (I suppose
this is important for you).
Something along this line could be made automatic within TPad. One needs a 
convention to freeze either X or Y ranges.

Rene Brun

Thomas Bretz wrote:
> 
> Hello Fons,
> 
> this is not the behaviour I want to have. Using Options/Auto Resize
> Canvas doesn't resize anything if I resize the canvas, but I want the
> canvas to be resized. My point is, that I want that width gets changed
> in the same ratio than the height and vice versa.
> 
> Think about drawing a detector layout. If you change the size of the
> canvas you don't want to distort the layout, but if you change width and
> height you may want to zoom it.
> 
> This can be solved easily by a function in TCanvas which fixes the
> width/height ratio at a given time (FixAspectRatio()) and resizes
> width/height according to the resizement of the other one.
> 
> Or, this would be more convinient: The graphic elemts don't distort and
> get resized only if the zoomed graphic would fit again in the resized
> pad Pad.
> (If you make only width or height longer the graphic elemenst would stay
> the same, if you would make only width or height shorter the element
> would become smaller)
> 
> Would be a really nice feature (and maybe it is not so difficult to
> implement than it looks like)
> 
> Thanks a lot,
> Thomas.
> 
> Fons Rademakers wrote:
> > You can do that now if in the canvas menu you turn off the
> > option: Options/Auto Resize Canvas. In that case the canvas
> > stays fixed when changing the window size. The API to this
> > feature is not yet easily accessable but I can expose it.
> > >
> > > I have a question and maybe a suggestion:
> > > Is it possible to fix the aspect ratio of a graphic in a TPad or to fix
> > > the aspect ratio of a canvas. So that if I change only the width the
> > > graphic stays the same, but if I change the width and height, the
> > > graphic is resized. If this is not yet implemented it would be a really
> > > nice feature. (Easier to implement is fixing the aspect ratio of a
> > > canvas, Iguess) This would help when displaing detector geometries.



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:04 MET