diff --git a/graf2d/graf/inc/TGaxis.h b/graf2d/graf/inc/TGaxis.h index b0dccdcdaf3e1..8226f2eae6f69 100644 --- a/graf2d/graf/inc/TGaxis.h +++ b/graf2d/graf/inc/TGaxis.h @@ -47,6 +47,7 @@ class TGaxis : public TLine, public TAttText { TF1 *fFunction; ///GetFunction(funcname); @@ -795,6 +795,7 @@ TGaxis::TGaxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax, TGaxis::TGaxis(const TGaxis& ax) : TLine(ax), TAttText(ax), + fRefLength(ax.fRefLength), fWmin(ax.fWmin), fWmax(ax.fWmax), fGridLength(ax.fGridLength), @@ -830,6 +831,7 @@ TGaxis& TGaxis::operator=(const TGaxis& ax) if(this!=&ax) { TLine::operator=(ax); TAttText::operator=(ax); + fRefLength = ax.fRefLength; fWmin=ax.fWmin; fWmax=ax.fWmax; fGridLength=ax.fGridLength; @@ -977,6 +979,7 @@ void TGaxis::ImportAxisAttributes(TAxis *axis) SetBit(TAxis::kMoreLogLabels, axis->TestBit(TAxis::kMoreLogLabels)); if (axis->GetDecimals()) SetBit(TAxis::kDecimals); //the bit is in TAxis::fAxis2 SetTimeFormat(axis->GetTimeFormat()); + SetRefLength(axis->GetRefLength()); } //////////////////////////////////////////////////////////////////////////////// @@ -1082,6 +1085,43 @@ void TGaxis::PaintAxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t yma Double_t rwmi = wmin; Double_t rwma = wmax; + + struct AttributeRestorer { + TGaxis *fAxis; + Float_t fLabelSize, fTitleSize, fTickSize, fLabelOffset, fTitleOffset; + AttributeRestorer(TGaxis *ax) : fAxis(ax), + fLabelSize(ax->GetLabelSize()), fTitleSize(ax->GetTitleSize()), + fTickSize(ax->GetTickSize()), fLabelOffset(ax->GetLabelOffset()), + fTitleOffset(ax->GetTitleOffset()) {} + ~AttributeRestorer() { + fAxis->SetLabelSize(fLabelSize); + fAxis->SetTitleSize(fTitleSize); + fAxis->SetTickSize(fTickSize); + fAxis->SetLabelOffset(fLabelOffset); + fAxis->SetTitleOffset(fTitleOffset); + } + }; + AttributeRestorer restorer(this); + + Double_t scale = 1.0; + + if (fRefLength > 0 && gPad) { + Double_t curH = gPad->GetWh() * gPad->GetAbsHNDC(); + if (curH > 0) scale = fRefLength / curH; + } + + if (scale != 1.0) { + // Only scale if precision is 2 (relative sizing). Precision 3 (pixels) ignores this. + if (GetLabelFont()%10 < 3) fLabelSize *= scale; + if (GetTextFont()%10 < 3) fTitleSize *= scale; + + fTickSize *= scale; + fLabelOffset *= scale; + // fTitleOffset *= scale; // REVERTED: Causes quadratic scaling, pushing title off pad + } + + + chtemp = &kchtemp[0]; label = &chlabel[0]; diff --git a/hist/hist/inc/TAxis.h b/hist/hist/inc/TAxis.h index 69c8b59806892..92c24ae7b4010 100644 --- a/hist/hist/inc/TAxis.h +++ b/hist/hist/inc/TAxis.h @@ -26,6 +26,7 @@ #include "TArrayD.h" #include +class TVirtualPad; class THashList; class TAxisModLab; @@ -44,6 +45,7 @@ class TAxis : public TNamed, public TAttAxis { TObject *fParent = nullptr; ///GetWh() * pad->GetAbsHNDC(); +} + + //////////////////////////////////////////////////////////////////////////////// /// Choose a reasonable time format from the coordinates in the active pad @@ -223,6 +240,7 @@ void TAxis::Copy(TObject &obj) const axis.fTimeFormat = fTimeFormat; axis.fTimeDisplay = fTimeDisplay; axis.fParent = fParent; + axis.fRefLength = fRefLength; if (axis.fLabels) { axis.fLabels->Delete(); delete axis.fLabels;