Skip to content
Open
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
4 changes: 4 additions & 0 deletions graf2d/graf/inc/TGaxis.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class TGaxis : public TLine, public TAttText {
TF1 *fFunction; ///<! Pointer to function computing axis values
TAxis *fAxis; ///<! Pointer to original TAxis axis (if any)
TList *fModLabs; ///< List of modified labels.
Float_t fRefLength; ///<! Reference length for automatic scaling (not saved to file)

TGaxis(const TGaxis&);
TGaxis& operator=(const TGaxis&);
Expand Down Expand Up @@ -137,6 +138,9 @@ class TGaxis : public TLine, public TAttText {

void SetLabelColor(TColorNumber lcolor);

void SetRefLength(Float_t len) { fRefLength = len; }
Float_t GetRefLength() const { return fRefLength; }

ClassDefOverride(TGaxis,6) //Graphics axis
};

Expand Down
46 changes: 43 additions & 3 deletions graf2d/graf/src/TGaxis.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ End_Macro
////////////////////////////////////////////////////////////////////////////////
/// TGaxis default constructor.

TGaxis::TGaxis(): TLine(), TAttText(11,0,1,62,0.040)
TGaxis::TGaxis(): TLine(), TAttText(11,0,1,62,0.040), fRefLength(0)
{

fGridLength = 0.;
Expand Down Expand Up @@ -721,7 +721,7 @@ TGaxis::TGaxis(): TLine(), TAttText(11,0,1,62,0.040)
TGaxis::TGaxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax,
Double_t wmin, Double_t wmax, Int_t ndiv, Option_t *chopt,
Double_t gridlength)
: TLine(xmin,ymin,xmax,ymax), TAttText(11,0,1,62,0.040)
: TLine(xmin,ymin,xmax,ymax), TAttText(11,0,1,62,0.040), fRefLength(0)
{

fWmin = wmin;
Expand Down Expand Up @@ -758,7 +758,7 @@ TGaxis::TGaxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax,
TGaxis::TGaxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax,
const char *funcname, Int_t ndiv, Option_t *chopt,
Double_t gridlength)
: TLine(xmin,ymin,xmax,ymax), TAttText(11,0,1,62,0.040)
: TLine(xmin,ymin,xmax,ymax), TAttText(11,0,1,62,0.040), fRefLength(0)
{

fFunction = (TF1*)gROOT->GetFunction(funcname);
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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];

Expand Down
5 changes: 5 additions & 0 deletions hist/hist/inc/TAxis.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "TArrayD.h"
#include <vector>

class TVirtualPad;
class THashList;
class TAxisModLab;

Expand All @@ -44,6 +45,7 @@ class TAxis : public TNamed, public TAttAxis {
TObject *fParent = nullptr; ///<! Object owning this axis
THashList *fLabels = nullptr; ///< List of labels
TList *fModLabs = nullptr; ///< List of modified labels
Float_t fRefLength = 0; ///<! Reference length for automatic scaling (not saved to file)

/// TAxis extra status bits (stored in fBits2)
enum {
Expand Down Expand Up @@ -176,6 +178,9 @@ class TAxis : public TNamed, public TAttAxis {
virtual void UnZoom(); // *MENU*
virtual void ZoomOut(Double_t factor=0, Double_t offset=0); // *MENU*

void SetRefPad(TVirtualPad *pad);
Float_t GetRefLength() const { return fRefLength; }

ClassDefOverride(TAxis,10) //Axis class
};

Expand Down
18 changes: 18 additions & 0 deletions hist/hist/src/TAxis.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ TAxis::TAxis()
fLast = 0;
fBits2 = 0;
fTimeDisplay = false;
fRefLength = 0;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -103,6 +104,7 @@ TAxis::TAxis(const TAxis &axis) : TNamed(axis), TAttAxis(axis)
fParent = nullptr;
fLabels = nullptr;
fModLabs = nullptr;
fRefLength = 0;

axis.TAxis::Copy(*this);
}
Expand All @@ -117,6 +119,21 @@ TAxis& TAxis::operator=(const TAxis &axis)
return *this;
}

////////////////////////////////////////////////////////////////////////////////
/// Set the reference pad for automatic axis sizing.
/// The axis will store the absolute pixel height of this pad and use it
/// to scale its attributes when drawn in other pads.

void TAxis::SetRefPad(TVirtualPad *pad)
{
if (!pad) {
fRefLength = 0;
return;
}
fRefLength = pad->GetWh() * pad->GetAbsHNDC();
}



////////////////////////////////////////////////////////////////////////////////
/// Choose a reasonable time format from the coordinates in the active pad
Expand Down Expand Up @@ -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;
Expand Down