diff --git a/README/ReleaseNotes/v626/index.md b/README/ReleaseNotes/v626/index.md index b3176680f961c..1f921d8dffda1 100644 --- a/README/ReleaseNotes/v626/index.md +++ b/README/ReleaseNotes/v626/index.md @@ -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 diff --git a/hist/hist/inc/TGraph.h b/hist/hist/inc/TGraph.h index e7e59efa7fae4..879b6266d930b 100644 --- a/hist/hist/inc/TGraph.h +++ b/hist/hist/inc/TGraph.h @@ -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 @@ -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); diff --git a/hist/hist/src/TGraph.cxx b/hist/hist/src/TGraph.cxx index 7eabb07dbaf17..269564cac1427 100644 --- a/hist/hist/src/TGraph.cxx +++ b/hist/hist/src/TGraph.cxx @@ -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). diff --git a/hist/histpainter/src/TGraphPainter.cxx b/hist/histpainter/src/TGraphPainter.cxx index 6912ea8937c66..7098ecfa4401e 100644 --- a/hist/histpainter/src/TGraphPainter.cxx +++ b/hist/histpainter/src/TGraphPainter.cxx @@ -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); } }