Skip to content

Commit

Permalink
Implement SetStats for TGraph. (#8498)
Browse files Browse the repository at this point in the history
  • Loading branch information
couet authored Jun 22, 2021
1 parent 498ad04 commit e1bdaf6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README/ReleaseNotes/v626/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ The following people have contributed to this new version:

## Histogram Libraries

- Implement the `SetStats` method for `TGraph` to turn ON or OFF the statistics box display
for an individual `TGraph`.

## Math Libraries

Expand Down
2 changes: 2 additions & 0 deletions hist/hist/inc/TGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class TGraph : public TNamed, public TAttLine, public TAttFill, public TAttMarke
public:
// TGraph status bits
enum EStatusBits {
kNoStats = BIT(9), ///< Don't draw stats box
kClipFrame = BIT(10), ///< Clip to the frame boundary
kResetHisto = BIT(17), ///< fHistogram must be reset in GetHistogram
kNotEditable = BIT(18), ///< Bit set if graph is non editable
Expand Down Expand Up @@ -182,6 +183,7 @@ class TGraph : public TNamed, public TAttLine, public TAttFill, public TAttMarke
virtual void SetPointY(Int_t i, Double_t y);
virtual void SetName(const char *name=""); // *MENU*
virtual void SetNameTitle(const char *name="", const char *title="");
virtual void SetStats(Bool_t stats=kTRUE); // *MENU*
virtual void SetTitle(const char *title=""); // *MENU*
virtual void Sort(Bool_t (*greater)(const TGraph*, Int_t, Int_t)=&TGraph::CompareX,
Bool_t ascending=kTRUE, Int_t low=0, Int_t high=-1111);
Expand Down
24 changes: 24 additions & 0 deletions hist/hist/src/TGraph.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2362,6 +2362,30 @@ void TGraph::SetNameTitle(const char *name, const char *title)
SetTitle(title);
}

////////////////////////////////////////////////////////////////////////////////
/// Set statistics option on/off.
///
/// By default, the statistics box is drawn.
/// The paint options can be selected via gStyle->SetOptStats.
/// This function sets/resets the kNoStats bit in the graph object.
/// It has priority over the Style option.

void TGraph::SetStats(Bool_t stats)
{
ResetBit(kNoStats);
if (!stats) {
SetBit(kNoStats);
//remove the "stats" object from the list of functions
if (fFunctions) {
TObject *obj = fFunctions->FindObject("stats");
if (obj) {
fFunctions->Remove(obj);
delete obj;
}
}
}
}

////////////////////////////////////////////////////////////////////////////////
/// if size*2 <= fMaxSize allocate new arrays of size points,
/// copy points [0,oend).
Expand Down
2 changes: 1 addition & 1 deletion hist/histpainter/src/TGraphPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ void TGraphPainter::PaintHelper(TGraph *theGraph, Option_t *option)
}
}
}
if (fit) PaintStats(theGraph, fit);
if (fit && !theGraph->TestBit(TGraph::kNoStats)) PaintStats(theGraph, fit);

}
}
Expand Down

0 comments on commit e1bdaf6

Please sign in to comment.