Skip to content
Snippets Groups Projects
Commit a4db7e9f authored by Olivier Couet's avatar Olivier Couet
Browse files

- From Guido Volpi:

  * Cleanup in TPie and TPieSlice in the methods that evaluates if the pointer
    is the slice area or in the area.

  * The labels now are not printed over the pie area.

  * Added the SetAngle3D() and GetAngle3D() method to change the perspecive
    angle if the 3d option is used.


git-svn-id: http://root.cern.ch/svn/root/trunk@19029 27541ba8-7e3a-0410-8455-c3a389f83636
parent 5ec62a62
No related branches found
No related tags found
No related merge requests found
// @(#)root/graf:$Name: $:$Id: TPie.h,v 1.5 2006/12/11 11:00:27 couet Exp $ // @(#)root/graf:$Name: $:$Id: TPie.h,v 1.6 2007/01/24 17:06:21 couet Exp $
// Author: Guido Volpi, Olivier Couet 03/11/2006 // Author: Guido Volpi, Olivier Couet 03/11/2006
/************************************************************************* /*************************************************************************
...@@ -51,6 +51,7 @@ protected: ...@@ -51,6 +51,7 @@ protected:
TPieSlice **fPieSlices; //[fNvals] Slice array of this pie-chart TPieSlice **fPieSlices; //[fNvals] Slice array of this pie-chart
Bool_t fIs3D; //! true if the pseudo-3d is enabled Bool_t fIs3D; //! true if the pseudo-3d is enabled
Double_t fHeight; // Pheight height of the slice in pixel Double_t fHeight; // Pheight height of the slice in pixel
Float_t fAngle3D; // The angle of the pseudo-3d view
public: public:
TPie(); TPie();
...@@ -65,6 +66,7 @@ public: ...@@ -65,6 +66,7 @@ public:
Int_t DistancetoSlice(Int_t,Int_t); Int_t DistancetoSlice(Int_t,Int_t);
virtual void Draw(Option_t *option="l"); // *MENU* virtual void Draw(Option_t *option="l"); // *MENU*
virtual void ExecuteEvent(Int_t,Int_t,Int_t); virtual void ExecuteEvent(Int_t,Int_t,Int_t);
Float_t GetAngle3D() { return fAngle3D; }
Double_t GetAngularOffset() { return fAngularOffset; } Double_t GetAngularOffset() { return fAngularOffset; }
Int_t GetEntryFillColor(Int_t); Int_t GetEntryFillColor(Int_t);
Int_t GetEntryFillStyle(Int_t); Int_t GetEntryFillStyle(Int_t);
...@@ -89,6 +91,7 @@ public: ...@@ -89,6 +91,7 @@ public:
void MakeSlices(Bool_t force=kFALSE); void MakeSlices(Bool_t force=kFALSE);
virtual void Paint(Option_t *); virtual void Paint(Option_t *);
void SavePrimitive(ostream &out, Option_t *opts=""); void SavePrimitive(ostream &out, Option_t *opts="");
void SetAngle3D(Float_t val = 30.); // *MENU*
void SetAngularOffset(Double_t); void SetAngularOffset(Double_t);
void SetCircle(Double_t x=.5, Double_t y=.5, Double_t rad=.4); void SetCircle(Double_t x=.5, Double_t y=.5, Double_t rad=.4);
void SetEntryLabel(Int_t, const char *text="Slice"); void SetEntryLabel(Int_t, const char *text="Slice");
......
...@@ -31,8 +31,6 @@ class TPieSlice : public TNamed, public TAttFill, public TAttLine { ...@@ -31,8 +31,6 @@ class TPieSlice : public TNamed, public TAttFill, public TAttLine {
private: private:
Bool_t fIsActive; //! True if is the slice under the mouse pointer Bool_t fIsActive; //! True if is the slice under the mouse pointer
Int_t fX[6]; //! The x coordinates, in pixel value, of this slice
Int_t fY[6]; //! The y coordinates, in pixel value, of this slice
protected: protected:
TPie *fPie; // The TPie object that contain this slice TPie *fPie; // The TPie object that contain this slice
......
// @(#)root/graf:$Name: $:$Id: TPie.cxx,v 1.15 2007/03/16 14:58:17 couet Exp $ // @(#)root/graf:$Name: $:$Id: TPie.cxx,v 1.16 2007/03/16 15:59:16 couet Exp $
// Author: Guido Volpi, Olivier Couet 03/11/2006 // Author: Guido Volpi, Olivier Couet 03/11/2006
/************************************************************************* /*************************************************************************
...@@ -177,7 +177,8 @@ Int_t TPie::DistancetoPrimitive(Int_t px, Int_t py) ...@@ -177,7 +177,8 @@ Int_t TPie::DistancetoPrimitive(Int_t px, Int_t py)
Int_t dist = 9999; Int_t dist = 9999;
if ( (gCurrent_slice = DistancetoSlice(px,py))>=0 ) { gCurrent_slice = DistancetoSlice(px,py);
if ( gCurrent_slice>=0 ) {
if (gCurrent_rad<=fRadius) { if (gCurrent_rad<=fRadius) {
dist = 0; dist = 0;
} }
...@@ -208,13 +209,15 @@ Int_t TPie::DistancetoSlice(Int_t px, Int_t py) ...@@ -208,13 +209,15 @@ Int_t TPie::DistancetoSlice(Int_t px, Int_t py)
Double_t radY = fRadius; Double_t radY = fRadius;
Double_t radXY = 1.; Double_t radXY = 1.;
if (fIs3D==kTRUE) { if (fIs3D==kTRUE) {
radY = .5*radX; radXY = TMath::Sin(fAngle3D/180.*TMath::Pi());
radXY = .5; radY = radXY*radX;
} }
Double_t phimin; Double_t phimin;
Double_t cphi; Double_t cphi;
Double_t phimax; Double_t phimax;
Float_t dPxl = (gPad->PixeltoY(0)-gPad->PixeltoY(1))/radY;
for (Int_t i=0;i<fNvals;++i) { for (Int_t i=0;i<fNvals;++i) {
fPieSlices[i]->SetIsActive(kFALSE); fPieSlices[i]->SetIsActive(kFALSE);
...@@ -230,14 +233,16 @@ Int_t TPie::DistancetoSlice(Int_t px, Int_t py) ...@@ -230,14 +233,16 @@ Int_t TPie::DistancetoSlice(Int_t px, Int_t py)
Double_t dx = (xx-fX-radOffset*TMath::Cos(cphi))/radX; Double_t dx = (xx-fX-radOffset*TMath::Cos(cphi))/radX;
Double_t dy = (yy-fY-radOffset*TMath::Sin(cphi)*radXY)/radY; Double_t dy = (yy-fY-radOffset*TMath::Sin(cphi)*radXY)/radY;
if (TMath::Abs(dy)<dPxl) dy = dPxl;
Double_t ang = TMath::ATan2(dy,dx); Double_t ang = TMath::ATan2(dy,dx);
if (ang<0) ang += TMath::TwoPi(); if (ang<0) ang += TMath::TwoPi();
Double_t dist = TMath::Sqrt(dx*dx+dy*dy); Double_t dist = TMath::Sqrt(dx*dx+dy*dy);
if ( ((ang>=phimin && ang <= phimax) || (phimax>TMath::TwoPi() && if ( ((ang>=phimin && ang <= phimax) || (phimax>TMath::TwoPi() &&
ang+TMath::TwoPi()>=phimin && ang+TMath::TwoPi()<phimax)) && ang+TMath::TwoPi()>=phimin && ang+TMath::TwoPi()<phimax)) &&
dist<=1.) { // if true the pointer is in the slice region dist<=1.) { // if true the pointer is in the slice region
gCurrent_x = dx; gCurrent_x = dx;
gCurrent_y = dy; gCurrent_y = dy;
...@@ -267,7 +272,6 @@ Int_t TPie::DistancetoSlice(Int_t px, Int_t py) ...@@ -267,7 +272,6 @@ Int_t TPie::DistancetoSlice(Int_t px, Int_t py)
break; break;
} }
} }
return result; return result;
} }
...@@ -310,8 +314,8 @@ void TPie::DrawGhost() ...@@ -310,8 +314,8 @@ void TPie::DrawGhost()
Double_t radY = fRadius; Double_t radY = fRadius;
Double_t radXY = 1.; Double_t radXY = 1.;
if (fIs3D) { if (fIs3D) {
radY = .5*radX; radXY = TMath::Sin(fAngle3D/180.*TMath::Pi());
radXY = .5; radY = radXY*radX;
} }
for (Int_t i=0;i<fNvals&&fIs3D==kTRUE;++i) { for (Int_t i=0;i<fNvals&&fIs3D==kTRUE;++i) {
...@@ -406,6 +410,11 @@ void TPie::ExecuteEvent(Int_t event, Int_t px, Int_t py) ...@@ -406,6 +410,11 @@ void TPie::ExecuteEvent(Int_t event, Int_t px, Int_t py)
if (!gPad) return; if (!gPad) return;
if (!gPad->IsEditable() && event != kMouseEnter) return; if (!gPad->IsEditable() && event != kMouseEnter) return;
if (gCurrent_slice<=-10) {
gPad->SetCursor(kCross);
return;
}
MakeSlices(); MakeSlices();
static bool isMovingPie(kFALSE); static bool isMovingPie(kFALSE);
...@@ -436,8 +445,8 @@ void TPie::ExecuteEvent(Int_t event, Int_t px, Int_t py) ...@@ -436,8 +445,8 @@ void TPie::ExecuteEvent(Int_t event, Int_t px, Int_t py)
Double_t radY = fRadius; Double_t radY = fRadius;
Double_t radXY = 1.; Double_t radXY = 1.;
if (fIs3D==kTRUE) { if (fIs3D==kTRUE) {
radY = .5*radX; radXY = TMath::Sin(fAngle3D/180.*TMath::Pi());
radXY = .5; radY = radXY*radX;
} }
Int_t dx, dy; Int_t dx, dy;
...@@ -749,6 +758,7 @@ void TPie::Init(Int_t np, Double_t ao, Double_t x, Double_t y, Double_t r) ...@@ -749,6 +758,7 @@ void TPie::Init(Int_t np, Double_t ao, Double_t x, Double_t y, Double_t r)
fSlices = 0; fSlices = 0;
fLegend = 0; fLegend = 0;
fHeight = 0.08; fHeight = 0.08;
fAngle3D = 30;
fLabelsOffset = gStyle->GetLabelOffset(); fLabelsOffset = gStyle->GetLabelOffset();
...@@ -885,7 +895,7 @@ void TPie::Paint(Option_t *option) ...@@ -885,7 +895,7 @@ void TPie::Paint(Option_t *option)
Double_t radXY = 1.; Double_t radXY = 1.;
if (fIs3D) { if (fIs3D) {
radXY = .5; radXY = TMath::Sin(fAngle3D/180.*TMath::Pi());
radY = fRadius*radXY; radY = fRadius*radXY;
} }
...@@ -957,28 +967,6 @@ void TPie::Paint(Option_t *option) ...@@ -957,28 +967,6 @@ void TPie::Paint(Option_t *option)
arc->PaintEllipse(ax, ay, radX, radY, fSlices[2*i], arc->PaintEllipse(ax, ay, radX, radY, fSlices[2*i],
fSlices[2*i+2], 0.); fSlices[2*i+2], 0.);
// eval the 6 points to delimit the slice
Int_t x[3], y[3];
x[0] = gPad->XtoAbsPixel(ax);
y[0] = gPad->XtoAbsPixel(ay);
x[1] = gPad->XtoAbsPixel(ax+radX*TMath::Cos(fSlices[2*i]/180.*TMath::Pi()));
y[1] = gPad->XtoAbsPixel(ay+radX*TMath::Sin(fSlices[2*i]/180.*TMath::Pi()));
x[2] = gPad->XtoAbsPixel(ax+radX*TMath::Cos(fSlices[2*i+2]/180.*TMath::Pi()));
y[2] = gPad->XtoAbsPixel(ay+radX*TMath::Sin(fSlices[2*i+2]/180.*TMath::Pi()));
fPieSlices[i]->fX[0] = (x[0]+x[1])/2;
fPieSlices[i]->fY[0] = (y[0]+y[1])/2;
fPieSlices[i]->fX[1] = x[1];
fPieSlices[i]->fY[1] = y[1];
fPieSlices[i]->fY[2] = (x[1]+x[2])/2;
fPieSlices[i]->fY[2] = (y[1]+y[2])/2;
fPieSlices[i]->fX[3] = (x[0]+x[2])/2;
fPieSlices[i]->fY[3] = (y[0]+y[2])/2;
fPieSlices[i]->fX[5] = x[2];
fPieSlices[i]->fY[5] = y[2];
fPieSlices[i]->fY[4] = (x[1]+x[2])/2;
fPieSlices[i]->fY[4] = (y[1]+y[2])/2;
} // end loop to draw the slices } // end loop to draw the slices
// Loop to place the labels. // Loop to place the labels.
...@@ -1040,10 +1028,15 @@ void TPie::Paint(Option_t *option) ...@@ -1040,10 +1028,15 @@ void TPie::Paint(Option_t *option)
lblang -= TMath::Pi(); lblang -= TMath::Pi();
} }
} else { // horizontal labels (default direction) } else { // horizontal labels (default direction)
if (aphi>TMath::Pi()/2. && aphi<=TMath::Pi()*3./2.) lx -= w; aphi = TMath::ATan2(TMath::Sin(aphi)*radXY,TMath::Cos(aphi));
if (aphi>=TMath::Pi() && aphi<TMath::TwoPi()) ly -= h; if (aphi>TMath::PiOver2() || aphi<=-TMath::PiOver2()) lx -= w;
if (aphi<0) ly -= h;
} }
Float_t rphi = TMath::ATan2((ly-fY)*radXY,lx-fX);
if (rphi < 0 && fIs3D && label_off>=0.)
ly -= fHeight;
textlabel->PaintLatex(lx,ly, textlabel->PaintLatex(lx,ly,
lblang*180/TMath::Pi()+GetTextAngle(), lblang*180/TMath::Pi()+GetTextAngle(),
GetTextSize(), tmptxt.Data()); GetTextSize(), tmptxt.Data());
...@@ -1179,6 +1172,22 @@ void TPie::SavePrimitive(ostream &out, Option_t *option) ...@@ -1179,6 +1172,22 @@ void TPie::SavePrimitive(ostream &out, Option_t *option)
} }
//______________________________________________________________________________
void TPie::SetAngle3D(Float_t val) {
// Set the value of for the pseudo 3D view angle, in degree.
// The range of the permitted values is: [0,90]
// check if val is in the permitted range
while (val>360.) val -= 360.;
while (val<0) val += 360.;
if (val>=90 && val<180) val = 180-val;
else if (val>=180 && val<=360) val = 360-val;
fAngle3D = val;
}
//______________________________________________________________________________ //______________________________________________________________________________
void TPie::SetAngularOffset(Double_t offset) void TPie::SetAngularOffset(Double_t offset)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment