Skip to content

Commit

Permalink
highlight mode for histogram or graph objects (#1839)
Browse files Browse the repository at this point in the history
* highlight mode for histogram or graph objects

* add animated gifs

* add doc for highlight mode

* renew hlHisto3_top.gif
  • Loading branch information
musinsky authored and couet committed May 15, 2018
1 parent 6bcb242 commit e4d37e8
Show file tree
Hide file tree
Showing 28 changed files with 85,274 additions and 4 deletions.
Binary file added documentation/doxygen/images/hlGraph1.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/doxygen/images/hlHisto3_top.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/doxygen/images/hlgerrors2.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/doxygen/images/hlsimple.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/doxygen/images/hlsimple_nofun.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions graf2d/gpad/inc/TCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ friend class TInterpreter;
{wtopx=GetWindowTopX(); wtopy=fWindowTopY; ww=fWindowWidth; wh=fWindowHeight;}
virtual void HandleInput(EEventType button, Int_t x, Int_t y);
Bool_t HasMenuBar() const { return TestBit(kMenuBar); }
virtual void HighlightConnect(const char *slot);
void Iconify() { if (fCanvasImp) fCanvasImp->Iconify(); }
Bool_t IsBatch() const { return fBatch; }
Bool_t IsDrawn() { return fDrawn; }
Expand All @@ -186,6 +187,7 @@ friend class TInterpreter;
virtual TPad *Pick(Int_t px, Int_t py, TObjLink *&pickobj) { return TPad::Pick(px, py, pickobj); }
virtual TPad *Pick(Int_t px, Int_t py, TObject *prevSelObj);
virtual void Picked(TPad *selpad, TObject *selected, Int_t event); // *SIGNAL*
virtual void Highlighted(TVirtualPad *pad, TObject *obj, Int_t x, Int_t y); // *SIGNAL*
virtual void ProcessedEvent(Int_t event, Int_t x, Int_t y, TObject *selected); // *SIGNAL*
virtual void Selected(TVirtualPad *pad, TObject *obj, Int_t event); // *SIGNAL*
virtual void Cleared(TVirtualPad *pad); // *SIGNAL*
Expand Down
32 changes: 32 additions & 0 deletions graf2d/gpad/src/TCanvas.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,38 @@ void TCanvas::Picked(TPad *pad, TObject *obj, Int_t event)
Emit("Picked(TPad*,TObject*,Int_t)", args);
}

////////////////////////////////////////////////////////////////////////////////
/// Emit Highlighted() signal.
///
/// - pad is pointer to pad with highlighted histogram or graph
/// - obj is pointer to highlighted histogram or graph
/// - x is highlighted x bin for 1D histogram or highlighted x-th point for graph
/// - y is highlighted y bin for 2D histogram (for 1D histogram or graph not in use)

void TCanvas::Highlighted(TVirtualPad *pad, TObject *obj, Int_t x, Int_t y)
{
Long_t args[4];

args[0] = (Long_t) pad;
args[1] = (Long_t) obj;
args[2] = x;
args[3] = y;

Emit("Highlighted(TVirtualPad*,TObject*,Int_t,Int_t)", args);
}

////////////////////////////////////////////////////////////////////////////////
/// This is "simplification" for function TCanvas::Connect with Highlighted
/// signal for specific slot.
///
/// Slot has to be defined "UserFunction(TVirtualPad *pad, TObject *obj, Int_t x, Int_t y)"
/// all parameters of UserFunction are taken from TCanvas::Highlighted

void TCanvas::HighlightConnect(const char *slot)
{
Connect("Highlighted(TVirtualPad*,TObject*,Int_t,Int_t)", 0, 0, slot);
}

////////////////////////////////////////////////////////////////////////////////
/// Emit Selected() signal.

Expand Down
1 change: 1 addition & 0 deletions graf3d/gl/inc/TGLHistPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class TGLHistPainter : public TVirtualHistPainter {
void Paint(Option_t *option);
void PaintStat(Int_t dostat, TF1 *fit);
void ProcessMessage(const char *message, const TObject *obj);
void SetHighlight();
void SetHistogram(TH1 *hist);
void SetStack(TList *stack);
Int_t MakeCuts(char *cutsOpt);
Expand Down
9 changes: 9 additions & 0 deletions graf3d/gl/src/TGLHistPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,15 @@ void TGLHistPainter::ProcessMessage(const char *m, const TObject *o)
fDefaultPainter->ProcessMessage(m, o);
}

////////////////////////////////////////////////////////////////////////////////
/// Set highlight mode

void TGLHistPainter::SetHighlight()
{
if (fDefaultPainter.get())
fDefaultPainter->SetHighlight();
}

////////////////////////////////////////////////////////////////////////////////
/// Set histogram.

Expand Down
5 changes: 4 additions & 1 deletion hist/hist/inc/TGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class TGraph : public TNamed, public TAttLine, public TAttFill, public TAttMarke
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
kIsSortedX = BIT(19) ///< graph is sorted in X points
kIsSortedX = BIT(19), ///< graph is sorted in X points
kIsHighlight = BIT(20) ///< bit set if graph is highlight
};

TGraph();
Expand Down Expand Up @@ -151,6 +152,7 @@ class TGraph : public TNamed, public TAttLine, public TAttFill, public TAttMarke
virtual void InsertPointBefore(Int_t ipoint, Double_t x, Double_t y);
virtual Double_t Integral(Int_t first=0, Int_t last=-1) const;
virtual Bool_t IsEditable() const {return !TestBit(kNotEditable);}
virtual Bool_t IsHighlight() const { return TestBit(kIsHighlight); }
virtual Int_t IsInside(Double_t x, Double_t y) const;
virtual void LeastSquareFit(Int_t m, Double_t *a, Double_t xmin=0, Double_t xmax=0);
virtual void LeastSquareLinearFit(Int_t n, Double_t &a0, Double_t &a1, Int_t &ifail, Double_t xmin=0, Double_t xmax=0);
Expand All @@ -165,6 +167,7 @@ class TGraph : public TNamed, public TAttLine, public TAttFill, public TAttMarke
virtual Int_t RemovePoint(Int_t ipoint);
virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
virtual void SetEditable(Bool_t editable=kTRUE); // *TOGGLE* *GETTER=GetEditable
virtual void SetHighlight(Bool_t set = kTRUE); // *TOGGLE* *GETTER=IsHighlight
virtual void SetHistogram(TH1F *h) {fHistogram = h;}
virtual void SetMaximum(Double_t maximum=-1111); // *MENU*
virtual void SetMinimum(Double_t minimum=-1111); // *MENU*
Expand Down
5 changes: 4 additions & 1 deletion hist/hist/inc/TH1.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
kIsAverage = BIT(18), ///< Bin contents are average (used by Add)
kIsNotW = BIT(19), ///< Histogram is forced to be not weighted even when the histogram is filled with weighted
/// different than 1.
kAutoBinPTwo = BIT(20) ///< Use Power(2)-based algorithm for autobinning
kAutoBinPTwo = BIT(20), ///< Use Power(2)-based algorithm for autobinning
kIsHighlight = BIT(21) ///< bit set if histo is highlight
};
// size of statistics data (size of array used in GetStats()/ PutStats )
// s[0] = sumw s[1] = sumw2
Expand Down Expand Up @@ -326,6 +327,7 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
virtual Double_t Interpolate(Double_t x, Double_t y, Double_t z);
Bool_t IsBinOverflow(Int_t bin, Int_t axis = 0) const;
Bool_t IsBinUnderflow(Int_t bin, Int_t axis = 0) const;
virtual Bool_t IsHighlight() const { return TestBit(kIsHighlight); }
virtual Double_t AndersonDarlingTest(const TH1 *h2, Option_t *option="") const;
virtual Double_t AndersonDarlingTest(const TH1 *h2, Double_t &advalue) const;
virtual Double_t KolmogorovTest(const TH1 *h2, Option_t *option="") const;
Expand Down Expand Up @@ -377,6 +379,7 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
virtual void SetDirectory(TDirectory *dir);
virtual void SetEntries(Double_t n) {fEntries = n;};
virtual void SetError(const Double_t *error);
virtual void SetHighlight(Bool_t set = kTRUE); // *TOGGLE* *GETTER=IsHighlight
virtual void SetLabelColor(Color_t color=1, Option_t *axis="X");
virtual void SetLabelFont(Style_t font=62, Option_t *axis="X");
virtual void SetLabelOffset(Float_t offset=0.005, Option_t *axis="X");
Expand Down
1 change: 1 addition & 0 deletions hist/hist/inc/TVirtualGraphPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TVirtualGraphPainter : public TObject {
virtual void PaintGraph(TGraph *theGraph, Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt) = 0;
virtual void PaintGrapHist(TGraph *theGraph, Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt) = 0;
virtual void PaintStats(TGraph *theGraph, TF1 *fit) = 0;
virtual void SetHighlight(TGraph *theGraph) = 0;

static TVirtualGraphPainter *GetPainter();
static void SetPainter(TVirtualGraphPainter *painter);
Expand Down
1 change: 1 addition & 0 deletions hist/hist/inc/TVirtualHistPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class TVirtualHistPainter : public TObject {
virtual void Paint(Option_t *option="") = 0;
virtual void PaintStat(Int_t dostat, TF1 *fit) = 0;
virtual void ProcessMessage(const char *mess, const TObject *obj) = 0;
virtual void SetHighlight() = 0;
virtual void SetHistogram(TH1 *h) = 0;
virtual void SetStack(TList *stack) = 0;
virtual Int_t MakeCuts(char *cutsopt) = 0;
Expand Down
14 changes: 14 additions & 0 deletions hist/hist/src/TGraph.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,20 @@ void TGraph::SetEditable(Bool_t editable)
else SetBit(kNotEditable);
}

////////////////////////////////////////////////////////////////////////////////
/// Set highlight (enable/disble) mode for the graph
/// by default highlight mode is disable

void TGraph::SetHighlight(Bool_t set)
{
if (IsHighlight() == set) return;

TVirtualGraphPainter *painter = TVirtualGraphPainter::GetPainter();
if (!painter) return;
SetBit(kIsHighlight, set);
painter->SetHighlight(this);
}

////////////////////////////////////////////////////////////////////////////////
/// Set the maximum of the graph.

Expand Down
20 changes: 20 additions & 0 deletions hist/hist/src/TH1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4217,6 +4217,26 @@ Double_t TH1::GetEffectiveEntries() const
return (s[1] ? s[0]*s[0]/s[1] : TMath::Abs(s[0]) );
}

////////////////////////////////////////////////////////////////////////////////
/// Set highlight (enable/disable) mode for the histogram
/// by default highlight mode is disable

void TH1::SetHighlight(Bool_t set)
{
if (IsHighlight() == set) return;
if (fDimension > 2) {
Info("SetHighlight", "Supported only 1-D or 2-D histograms");
return;
}

if (!fPainter) {
Info("SetHighlight", "Need to draw histogram first");
return;
}
SetBit(kIsHighlight, set);
fPainter->SetHighlight();
}

////////////////////////////////////////////////////////////////////////////////
/// Redefines TObject::GetObjectInfo.
/// Displays the histogram info (bin number, contents, integral up to bin
Expand Down
4 changes: 4 additions & 0 deletions hist/histpainter/inc/TGraphPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class TGraphPainter : public TVirtualGraphPainter {
virtual void DrawPanelHelper(TGraph *theGraph);
virtual void ExecuteEventHelper(TGraph *theGraph, Int_t event, Int_t px, Int_t py);
virtual char *GetObjectInfoHelper(TGraph *theGraph, Int_t px, Int_t py) const;
virtual Int_t GetHighlightPoint(TGraph *theGraph) const;
virtual void HighlightPoint(TGraph *theGraph, Int_t hpoint, Int_t distance);
virtual void PaintHighlightPoint(TGraph *theGraph, Option_t *option);
void PaintHelper(TGraph *theGraph, Option_t *option);
virtual void PaintGraph(TGraph *theGraph, Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt);
virtual void PaintGrapHist(TGraph *theGraph, Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt);
Expand All @@ -51,6 +54,7 @@ class TGraphPainter : public TVirtualGraphPainter {
void PaintGraphSimple(TGraph *theGraph, Option_t *option);
void PaintPolyLineHatches(TGraph *theGraph, Int_t n, const Double_t *x, const Double_t *y);
void PaintStats(TGraph *theGraph, TF1 *fit);
virtual void SetHighlight(TGraph *theGraph);
void Smooth(TGraph *theGraph, Int_t npoints, Double_t *x, Double_t *y, Int_t drawtype);
static void SetMaxPointsPerLine(Int_t maxp=50);

Expand Down
7 changes: 7 additions & 0 deletions hist/histpainter/inc/THistPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class THistPainter : public TVirtualHistPainter {
TList *fStack; //Pointer to stack of histograms (if any)
Int_t fShowProjection; //True if a projection must be drawn
TString fShowOption; //Option to draw the projection
Int_t fXHighlightBin; //X highlight bin
Int_t fYHighlightBin; //Y highlight bin

public:
THistPainter();
Expand All @@ -74,6 +76,9 @@ class THistPainter : public TVirtualHistPainter {
virtual TList *GetContourList(Double_t contour) const;
virtual char *GetObjectInfo(Int_t px, Int_t py) const;
virtual TList *GetStack() const {return fStack;}
virtual Int_t GetXHighlightBin() const { return fXHighlightBin; }
virtual Int_t GetYHighlightBin() const { return fYHighlightBin; }
virtual void HighlightBin(Int_t px, Int_t py);
virtual Bool_t IsInside(Int_t x, Int_t y);
virtual Bool_t IsInside(Double_t x, Double_t y);
virtual Int_t MakeChopt(Option_t *option);
Expand Down Expand Up @@ -101,6 +106,7 @@ class THistPainter : public TVirtualHistPainter {
virtual void Paint2DErrors(Option_t *option);
virtual void PaintFrame();
virtual void PaintFunction(Option_t *option);
virtual void PaintHighlightBin(Option_t *option="");
virtual void PaintHist(Option_t *option);
virtual void PaintH3(Option_t *option="");
virtual void PaintH3Box(Int_t iopt);
Expand Down Expand Up @@ -128,6 +134,7 @@ class THistPainter : public TVirtualHistPainter {
static Int_t ProjectParabolic2xy(Double_t l, Double_t b, Double_t &Al, Double_t &Ab);
virtual void RecalculateRange();
virtual void RecursiveRemove(TObject *) {;}
virtual void SetHighlight();
virtual void SetHistogram(TH1 *h);
virtual void SetStack(TList *stack) {fStack = stack;}
virtual void SetShowProjection(const char *option,Int_t nbins);
Expand Down

0 comments on commit e4d37e8

Please sign in to comment.