From 26e69ec4ba0a8584e114cca0bcdc071245e6ddfd Mon Sep 17 00:00:00 2001 From: Olivier Couet <Olivier.Couet@cern.ch> Date: Tue, 20 Mar 2012 13:02:53 +0000 Subject: [PATCH] New method DivideSquare a canvas in to n sub-pads. The number of sub-pads along the X and Y axis are computed according to the square root of n. git-svn-id: http://root.cern.ch/svn/root/trunk@43408 27541ba8-7e3a-0410-8455-c3a389f83636 --- graf2d/gpad/inc/TPad.h | 3 ++- graf2d/gpad/src/TPad.cxx | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/graf2d/gpad/inc/TPad.h b/graf2d/gpad/inc/TPad.h index 5ba1423f61e..d288550f97b 100644 --- a/graf2d/gpad/inc/TPad.h +++ b/graf2d/gpad/inc/TPad.h @@ -173,6 +173,7 @@ public: virtual void CopyPixmaps(); virtual void DeleteExec(const char *name); virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0); // *MENU* + virtual void DivideSquare(Int_t n, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0); virtual void Draw(Option_t *option=""); virtual void DrawClassObject(const TObject *obj, Option_t *option=""); static void DrawColorTable(); @@ -373,7 +374,7 @@ public: virtual TVirtualViewer3D *GetViewer3D(Option_t * type = ""); virtual Bool_t HasViewer3D() const { return (fViewer3D); } virtual void ReleaseViewer3D(Option_t * type = ""); - + virtual void RecordPave(const TObject *obj); // *SIGNAL* virtual void RecordLatex(const TObject *obj); // *SIGNAL* virtual void EventPave() { Emit("EventPave()"); } // *SIGNAL* diff --git a/graf2d/gpad/src/TPad.cxx b/graf2d/gpad/src/TPad.cxx index f8d2bb355ff..496096d86c2 100644 --- a/graf2d/gpad/src/TPad.cxx +++ b/graf2d/gpad/src/TPad.cxx @@ -1180,6 +1180,28 @@ void TPad::Divide(Int_t nx, Int_t ny, Float_t xmargin, Float_t ymargin, Int_t co } +//______________________________________________________________________________ +void TPad::DivideSquare(Int_t n, Float_t xmargin, Float_t ymargin, Int_t color) +{ + // "n" is the total number of sub-pads. The number of sub-pads along the X + // and Y axis are computed according to the square root of n. + + Int_t w = 1, h = 1; + + if (fCanvas->GetWindowWidth() > fCanvas->GetWindowHeight()) { + w = TMath::Ceil(TMath::Sqrt(n)); + h = TMath::Floor(TMath::Sqrt(n)); + if (w*h < n) w++; + } else { + h = TMath::Ceil(TMath::Sqrt(n)); + w = TMath::Floor(TMath::Sqrt(n)); + if (w*h < n) h++; + } + + Divide( w, h, xmargin, ymargin, color); +} + + //______________________________________________________________________________ void TPad::Draw(Option_t *option) { -- GitLab