Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check that the BIT(9) doesn't conflict in the parent class(es)? I.e. BIT(9) could already be used by any of the TNamed, TAttLine, TAttFill, TAttMarker classes

@couet couet Jun 22, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I checked it is used in TH1 for exactly the same thing

@couet couet Jun 22, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked in TGraph.cxx the other bits are not initialised in the constructors. There is only two calls to ResetBit and that's not in the constructors.:

hist/src/TGraph.cxx:         const_cast <TGraph*>(this)->ResetBit(kResetHisto);
hist/src/TGraph.cxx:   if (editable) ResetBit(kNotEditable);

I guess the BIT are initialised elsewhere. The behaviour I get is correct.i It is backward compatible.

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