1 #ifndef CanvasHelper_HH_
2 #define CanvasHelper_HH_
4 #include <RtypesCore.h>
7 #include <TVirtualPad.h>
9 #include <TPaveStats.h>
26 std::pair<double, double> valueError(
const double value,
const double error);
27 void paveTextValueErrors(TPaveText *pave);
35 kPaveAlignLeft = BIT(14),
36 kPaveAlignRight = BIT(15),
37 kPaveAlignTop = BIT(16),
38 kPaveAlignBottom = BIT(17)
48 enum ECanvasFormatBits {
51 kFormatROOT = BIT(16),
64 TNamedLine(
const char *name, Double_t x1, Double_t y1, Double_t x2, Double_t y2);
67 const char *GetName()
const override {
return fName.Data(); }
113 static void addSubtitle(TVirtualPad *pad,
const char *text);
173 static void addTextToStats(
const char *text, TPaveStats *stats, TVirtualPad *pad);
181 static void addMultiCanvasTitle(TCanvas *canvas,
const char *title,
const char *subtitle =
"");
190 static void saveCanvas(TCanvas *canvas, UInt_t format);
210 HelveticaBoldItalic = 7,
214 CourierBoldItalic = 11,
222 static const Int_t FONT_SIZE_NORMAL;
223 static const Int_t FONT_SIZE_SMALL;
224 static const Int_t FONT_SIZE_SMALLER;
225 static const Int_t FONT_SIZE_LARGE;
226 static const Int_t FONT_SIZE_LARGER;
227 static const Int_t FONT_SIZE_HUGE;
229 static const Double_t LINE_HEIGHT;
232 static const Int_t AXIS_LABEL_OFFSET;
233 static const Int_t AXIS_TICK_LENGTH;
235 static const Int_t MARGIN_LEFT;
236 static const Int_t MARGIN_TOP;
237 static const Int_t MARGIN_RIGHT;
238 static const Int_t MARGIN_BOTTOM;
240 static const Int_t TITLE_VSPACE;
241 static const Int_t SUBTITLE_VSPACE;
242 static const Int_t PAVELINE_VSPACE;
243 static const Int_t AXISTITLE_VSPACE;
245 static Style_t getFont(EFontFace fontFace = EFontFace::Helvetica);
246 static UInt_t getPaveLines(TPave *pave);
247 static UInt_t getPaveTextWidthPx(TPaveText *paveText);
248 static UInt_t getLegendWidthPx(TLegend *paveText);
251 static std::pair<Double_t, Double_t> getSubtitleYNDCCoordinates(TVirtualPad *pad);
253 std::map<TCanvas*, std::pair<unsigned int, unsigned int>> registeredCanvases;
257 static TObject* findObjectOnPad(TClass *c, TVirtualPad *pad);
260 static void alignChildPad(TVirtualPad *pad);
262 static Int_t getFrameLeftMarginPx(TVirtualPad *pad);
263 static Int_t getFrameRightMarginPx();
264 static Int_t getFrameTopMarginPx(TVirtualPad *pad);
265 static Int_t getFrameBottomMarginPx(TVirtualPad *pad);
267 static Bool_t hasXAxisTitle(TVirtualPad *pad);
268 static Bool_t hasYAxisTitle(TVirtualPad *pad);
270 static Bool_t isChildPad(TVirtualPad *pad);
272 static void alignTitle(TVirtualPad *pad);
273 static void alignSubtitle(TVirtualPad *pad);
274 static void alignSubtitle(TPaveText *subtitle, TVirtualPad *pad);
275 static void alignAllPaves(TVirtualPad *pad);
278 void processCanvas(TCanvas *canvas);
279 void processPad(TVirtualPad *pad);
280 static void setPadMargins(TVirtualPad *pad);
282 static void setPadNDivisions(TVirtualPad *pad);
283 void convertAxisToPxSize(TAxis *axis,
const char type, TVirtualPad *pad);
285 static void setPadCustomFrameBorder(TVirtualPad *pad);
287 static Double_t getPadWidthPx(TVirtualPad *pad);
288 static Double_t getPadHeightPx(TVirtualPad *pad);
290 static std::pair<TAxis*, TAxis*> getPadXYAxis(TVirtualPad *pad);
291 static Double_t getYAxisMaxLabelWidthPx(TVirtualPad *pad);
294 static Double_t pxToNdcHorizontal(Int_t px, TVirtualPad *pad);
295 static Double_t pxToNdcVertical(Int_t py, TVirtualPad *pad);
297 static constexpr
char subtitleObjectName[] =
"subtitle";
299 static TFrame* getPadFrame(TVirtualPad *pad);
303 void onCanvasResized();
Definition: CanvasHelper.h:76
virtual ~CanvasHelper()
Class destructor.
Definition: CanvasHelper.cpp:126
static void addMultiCanvasTitle(TCanvas *canvas, const char *title, const char *subtitle="")
Adding a multi-pad canvas title. Optionally supprts subtitle too.
Definition: CanvasHelper.cpp:1119
static void addSubtitle(TVirtualPad *pad, const char *text)
Add subtitle to the canvas. lololo.
Definition: CanvasHelper.cpp:415
static void setPaveAlignment(TPave *pave, UInt_t align)
Used to specify TPave's alignment on the ROOT canvas. Emum variables can be combined:
Definition: CanvasHelper.cpp:789
static void saveCanvas(TCanvas *canvas, UInt_t format)
Definition: CanvasHelper.cpp:812
static CanvasHelper * getInstance()
Obtain an instance of the CanvasHelper class.
Definition: CanvasHelper.cpp:131
static void addTextToStats(const char *text, TVirtualPad *pad)
Used to add a line to the default canvas (pad) statistics box.
Definition: CanvasHelper.cpp:916
static TPaveStats * getDefaultPaveStats(TVirtualPad *pad)
Used to obtain default ROOT statistics box from a canvas with histogram, graph etc....
Definition: CanvasHelper.cpp:858
void addCanvas(TCanvas *canvas)
Register your canvas for processing. Canvas needs to be added after all the primitives are drawn on i...
Definition: CanvasHelper.cpp:295
static TLegend * getDefaultLegend(TVirtualPad *pad)
Used to obtain default ROOT legend from a canvas.
Definition: CanvasHelper.cpp:910
Definition: CanvasHelper.h:59
Definition: CanvasHelper.cpp:42