From d1c338cec5d7940be4a4ca4b9aed3bda9ade782a Mon Sep 17 00:00:00 2001 From: JasMehta08 Date: Thu, 18 Dec 2025 23:44:22 +0530 Subject: [PATCH 1/5] [hist] Add SetRefPad for consistent axis scaling --- graf2d/graf/inc/TGaxis.h | 4 ++++ graf2d/graf/src/TGaxis.cxx | 45 +++++++++++++++++++++++++++++++++++--- hist/hist/inc/TAxis.h | 5 +++++ hist/hist/src/TAxis.cxx | 18 +++++++++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) 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,42 @@ 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; + } + + + 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; From 55409845585c335c23049c73a838df06a3282a08 Mon Sep 17 00:00:00 2001 From: JasMehta08 Date: Mon, 22 Dec 2025 00:50:51 +0530 Subject: [PATCH 2/5] Increment TAxis ClassDef version to 11 to fix build --- hist/hist/inc/TAxis.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hist/hist/inc/TAxis.h b/hist/hist/inc/TAxis.h index 92c24ae7b4010..2375b0296e9da 100644 --- a/hist/hist/inc/TAxis.h +++ b/hist/hist/inc/TAxis.h @@ -181,7 +181,7 @@ class TAxis : public TNamed, public TAttAxis { void SetRefPad(TVirtualPad *pad); Float_t GetRefLength() const { return fRefLength; } - ClassDefOverride(TAxis,10) //Axis class + ClassDefOverride(TAxis,11) //Axis class }; //////////////////////////////////////////////////////////////////////////////// From 1f300cb381eb113d342d95ac5e778e73b26b1e19 Mon Sep 17 00:00:00 2001 From: JasMehta08 Date: Mon, 22 Dec 2025 10:00:04 +0530 Subject: [PATCH 3/5] Revert TAxis ClassDef version to 10 --- graf2d/graf/inc/TPave.h | 7 +- graf2d/graf/src/TGaxis.cxx | 1 + graf2d/graf/src/TLegend.cxx | 11 +++ graf2d/graf/src/TPave.cxx | 13 +++ graf2d/graf/src/TPaveStats.cxx | 44 +++++++++- graf2d/graf/src/TPaveText.cxx | 16 +++- hist/hist/inc/TAxis.h | 2 +- js/modules/gpad/TAxisPainter.mjs | 136 ++++++++++++++++--------------- 8 files changed, 159 insertions(+), 71 deletions(-) diff --git a/graf2d/graf/inc/TPave.h b/graf2d/graf/inc/TPave.h index df266e73947a7..89de0d34193a2 100644 --- a/graf2d/graf/inc/TPave.h +++ b/graf2d/graf/inc/TPave.h @@ -16,6 +16,8 @@ #include "TBox.h" #include "TString.h" +class TVirtualPad; + class TPave : public TBox { protected: @@ -29,6 +31,7 @@ class TPave : public TBox { Double_t fCornerRadius; ///< Corner radius in case of option arc TString fOption; ///< Pave style TString fName; ///< Pave name + Float_t fRefLength{0}; ///< Reference length for scaling (e.g. ref pad height) TString GetSavePaveArgs(const char *extra_arg = nullptr, Bool_t save_option = kTRUE); @@ -62,6 +65,7 @@ class TPave : public TBox { Double_t GetX2NDC() const {return fX2NDC;} Double_t GetY1NDC() const {return fY1NDC;} Double_t GetY2NDC() const {return fY2NDC;} + Float_t GetRefLength() const { return fRefLength; } ULong_t Hash() const override { return fName.Hash(); } Bool_t IsSortable() const override { return kTRUE; } void ls(Option_t *option="") const override; @@ -81,6 +85,7 @@ class TPave : public TBox { virtual void SetName(const char *name="") {fName = name;} // *MENU* virtual void SetOption(Option_t *option="br") {fOption = option;} virtual void SetShadowColor(Int_t color) {fShadowColor=color;} // *MENU* + virtual void SetRefPad(TVirtualPad *pad); virtual void SetX1NDC(Double_t x1) {fX1NDC=x1;} virtual void SetX2NDC(Double_t x2) {fX2NDC=x2;} virtual void SetY1NDC(Double_t y1) {fY1NDC=y1;} @@ -90,7 +95,7 @@ class TPave : public TBox { void SetY1(Double_t y1) override; void SetY2(Double_t y2) override; - ClassDefOverride(TPave,3) //Pave. A box with shadowing + ClassDefOverride(TPave,4) //Pave. A box with shadowing }; #endif diff --git a/graf2d/graf/src/TGaxis.cxx b/graf2d/graf/src/TGaxis.cxx index da21d818f47bb..5d2ce370a62d0 100644 --- a/graf2d/graf/src/TGaxis.cxx +++ b/graf2d/graf/src/TGaxis.cxx @@ -1117,6 +1117,7 @@ void TGaxis::PaintAxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t yma fTickSize *= scale; fLabelOffset *= scale; + // fTitleOffset *= scale; // REVERTED: Causes quadratic scaling, pushing title off pad } diff --git a/graf2d/graf/src/TLegend.cxx b/graf2d/graf/src/TLegend.cxx index 6d3bb698bd386..d10ebc73032f1 100644 --- a/graf2d/graf/src/TLegend.cxx +++ b/graf2d/graf/src/TLegend.cxx @@ -639,6 +639,17 @@ void TLegend::PaintPrimitives() SetTextSize(gStyle->GetLegendTextSize()); textsize = GetTextSize(); } + + // Apply scaling if reference pad is set + Double_t scale = 1.0; + if (fRefLength > 0 && gPad) { + Double_t curH = gPad->GetWh() * gPad->GetAbsHNDC(); + if (curH > 0) scale = fRefLength / curH; + } + if (textsize > 0) { + textsize *= scale; + SetTextSize(textsize); // Set scaled size + } Bool_t autosize = kFALSE; std::vector columnWidths(fNColumns, 0.); diff --git a/graf2d/graf/src/TPave.cxx b/graf2d/graf/src/TPave.cxx index 5a42db1e14fd0..a313402877373 100644 --- a/graf2d/graf/src/TPave.cxx +++ b/graf2d/graf/src/TPave.cxx @@ -741,3 +741,16 @@ void TPave::Streamer(TBuffer &R__b) R__b.WriteClassBuffer(TPave::Class(),this); } } + +//////////////////////////////////////////////////////////////////////////////// +/// Set the reference pad to scale attributes (e.g. text size) +/// This allows consistent sizing across pads of different sizes. + +void TPave::SetRefPad(TVirtualPad *pad) +{ + if (!pad) { + fRefLength = 0; + return; + } + fRefLength = pad->GetWh() * pad->GetAbsHNDC(); +} diff --git a/graf2d/graf/src/TPaveStats.cxx b/graf2d/graf/src/TPaveStats.cxx index 90f1543b67ad9..83a08e050d9f8 100644 --- a/graf2d/graf/src/TPaveStats.cxx +++ b/graf2d/graf/src/TPaveStats.cxx @@ -357,6 +357,45 @@ void TPaveStats::Paint(Option_t *option) Double_t dy = std::abs(fY2 - fY1); Double_t titlesize=0; Double_t textsize = GetTextSize(); + + // Save original attributes for restoration + Double_t textsave = textsize; // This is the Original (unscaled) size + Double_t x1save = fX1, x2save = fX2, y1save = fY1, y2save = fY2; + + // Apply scaling if reference pad is set + 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.0001 || scale < 0.9999) { + // Scale Text + if (textsize > 0) { + textsize *= scale; + SetTextSize(textsize); + } + + // Scale Box Coordinates (centering on anchor points) + // Determine width/height in pad coordinates + Double_t w_box = fX2 - fX1; + Double_t h_box = fY2 - fY1; + Double_t w_new = w_box * scale; + Double_t h_new = h_box * scale; + + // Simple anchor logic: keep corner closest to edge fixed + Double_t midX = (fX1NDC + fX2NDC) * 0.5; + Double_t midY = (fY1NDC + fY2NDC) * 0.5; + + // X Axis + if (midX > 0.5) fX1 = fX2 - w_new; // Anchor Right + else fX2 = fX1 + w_new; // Anchor Left + + // Y Axis + if (midY > 0.5) fY1 = fY2 - h_new; // Anchor Top + else fY2 = fY1 + h_new; // Anchor Bottom + } + Int_t nlines = GetSize(); if (nlines == 0) nlines = 5; Int_t print_name = fOptStat%10; @@ -366,7 +405,7 @@ void TPaveStats::Paint(Option_t *option) Double_t y2 = gPad->GetY2(); Float_t margin = fMargin*dx; Double_t yspace = dy/Double_t(nlines); - Double_t textsave = textsize; + // Double_t textsave = textsize; // Removed, already defined above TIter next(fLines); Double_t longest = 0, titlelength = 0; Double_t w, wtok[2]; @@ -503,6 +542,9 @@ void TPaveStats::Paint(Option_t *option) } } SetTextSize(textsave); + if (scale > 1.0001 || scale < 0.9999) { + fX1 = x1save; fX2 = x2save; fY1 = y1save; fY2 = y2save; + } // if a label create & paint a pavetext title if (fLabel.Length() > 0) { diff --git a/graf2d/graf/src/TPaveText.cxx b/graf2d/graf/src/TPaveText.cxx index b242d0b58f32f..01b176aefa0d9 100644 --- a/graf2d/graf/src/TPaveText.cxx +++ b/graf2d/graf/src/TPaveText.cxx @@ -431,6 +431,20 @@ void TPaveText::PaintPrimitives(Int_t mode) Double_t dx = fX2 - fX1; Double_t dy = fY2 - fY1; Double_t textsize = GetTextSize(); + // Save original text size for restoration at the end + Double_t textsave = textsize; + + // Apply scaling if reference pad is set + Double_t scale = 1.0; + if (fRefLength > 0 && gPad) { + Double_t curH = gPad->GetWh() * gPad->GetAbsHNDC(); + if (curH > 0) scale = fRefLength / curH; + } + if (textsize > 0) { + textsize *= scale; + SetTextSize(textsize); // Temporarily set member so individual lines pick it up + } + Int_t nlines = GetSize(); if (nlines == 0) nlines = 5; @@ -441,7 +455,7 @@ void TPaveText::PaintPrimitives(Int_t mode) y2 = gPad->GetY2(); Float_t margin = fMargin*dx; Double_t yspace = dy/Double_t(nlines); - Double_t textsave = textsize; + // Double_t textsave = textsize; // Removed, already defined above TObject *line; TText *linet; TLatex *latex; diff --git a/hist/hist/inc/TAxis.h b/hist/hist/inc/TAxis.h index 2375b0296e9da..92c24ae7b4010 100644 --- a/hist/hist/inc/TAxis.h +++ b/hist/hist/inc/TAxis.h @@ -181,7 +181,7 @@ class TAxis : public TNamed, public TAttAxis { void SetRefPad(TVirtualPad *pad); Float_t GetRefLength() const { return fRefLength; } - ClassDefOverride(TAxis,11) //Axis class + ClassDefOverride(TAxis,10) //Axis class }; //////////////////////////////////////////////////////////////////////////////// diff --git a/js/modules/gpad/TAxisPainter.mjs b/js/modules/gpad/TAxisPainter.mjs index 218e1d0fd6f79..3d2c456aaac80 100644 --- a/js/modules/gpad/TAxisPainter.mjs +++ b/js/modules/gpad/TAxisPainter.mjs @@ -1,7 +1,9 @@ import { gStyle, settings, constants, clTAxis, clTGaxis, isFunc, isStr } from '../core.mjs'; -import { select as d3_select, drag as d3_drag, timeFormat as d3_timeFormat, utcFormat as d3_utcFormat, - scaleTime as d3_scaleTime, scaleSymlog as d3_scaleSymlog, - scaleLog as d3_scaleLog, scaleLinear as d3_scaleLinear } from '../d3.mjs'; +import { + select as d3_select, drag as d3_drag, timeFormat as d3_timeFormat, utcFormat as d3_utcFormat, + scaleTime as d3_scaleTime, scaleSymlog as d3_scaleSymlog, + scaleLog as d3_scaleLog, scaleLinear as d3_scaleLinear +} from '../d3.mjs'; import { floatToString, makeTranslate, addHighlightStyle } from '../base/BasePainter.mjs'; import { ObjectPainter, EAxisBits, kAxisLabels, kAxisNormal, kAxisFunc, kAxisTime } from '../base/ObjectPainter.mjs'; import { FontHandler } from '../base/FontHandler.mjs'; @@ -41,12 +43,12 @@ function getTimeOffset(axis) { }; // eslint-disable-next-line one-var const year = next('-', 1900, 2900), - month = next('-', 1, 12) - 1, - day = next(' ', 1, 31), - hour = next(':', 0, 23), - min = next(':', 0, 59), - sec = next('s', 0, 59), - msec = next(' ', 0, 999); + month = next('-', 1, 12) - 1, + day = next(' ', 1, 31), + hour = next(':', 0, 23), + min = next(':', 0, 59), + sec = next('s', 0, 59), + msec = next(' ', 0, 999); let offset = Date.UTC(year, month, day, hour, min, sec, msec); @@ -271,7 +273,7 @@ const AxisPainterMethods = { sum2 += diff ** 2; } const mean = sum1 / (arr.length - 1), - dev = sum2 / (arr.length - 1) - mean ** 2; + dev = sum2 / (arr.length - 1) - mean ** 2; if (dev <= 0) return true; @@ -311,13 +313,13 @@ const AxisPainterMethods = { return this.poduceLogTicks(this.func, total); const dom = this.func.domain(), - check = ticks => { - if (ticks.length <= total) - return true; - if (ticks.length > total + 1) - return false; - return (ticks[0] === dom[0]) || (ticks[total] === dom[1]); // special case of N+1 ticks, but match any range - }, res1 = this.func.ticks(total); + check = ticks => { + if (ticks.length <= total) + return true; + if (ticks.length > total + 1) + return false; + return (ticks[0] === dom[0]) || (ticks[total] === dom[1]); // special case of N+1 ticks, but match any range + }, res1 = this.func.ticks(total); if (ndiv2 || check(res1)) return res1; @@ -362,9 +364,9 @@ const AxisPainterMethods = { delta_right *= delta; const lmin = item.min = this.scale_min, - lmax = item.max = this.scale_max, - gmin = this.full_min, - gmax = this.full_max; + lmax = item.max = this.scale_max, + gmin = this.full_min, + gmax = this.full_max; if ((item.min === item.max) && (delta < 0)) { item.min = gmin; @@ -422,7 +424,7 @@ const AxisPainterMethods = { else if (delta_left !== delta_right) { // extra check case when moving left or right if (((item.min < gmin) && (lmin === gmin)) || - ((item.max > gmax) && (lmax === gmax))) + ((item.max > gmax) && (lmax === gmax))) item.min = item.max = undefined; } else { item.min = Math.max(item.min, gmin); @@ -600,8 +602,8 @@ class TAxisPainter extends ObjectPainter { this.nticks = Math.min(this.nticks, 8); const scale_range = this.scale_max - this.scale_min, - idF = axis.fTimeFormat.indexOf('%F'), - tf2 = chooseTimeFormat(scale_range / gr_range, false); + idF = axis.fTimeFormat.indexOf('%F'), + tf2 = chooseTimeFormat(scale_range / gr_range, false); let tf1 = (idF >= 0) ? axis.fTimeFormat.slice(0, idF) : axis.fTimeFormat; if (!tf1 || (scale_range < 0.1 * (this.full_max - this.full_min))) @@ -632,7 +634,7 @@ class TAxisPainter extends ObjectPainter { if (axis?.fNbins && axis?.fLabels) { if ((axis.fNbins !== Math.round(axis.fXmax - axis.fXmin)) || - axis.fXmin || (axis.fXmax !== axis.fNbins)) + axis.fXmin || (axis.fXmax !== axis.fNbins)) this.regular_labels = false; } @@ -739,11 +741,11 @@ class TAxisPainter extends ObjectPainter { } } - handle.reset = function() { + handle.reset = function () { this.nminor = this.nmiddle = this.nmajor = 0; }; - handle.next = function(doround) { + handle.next = function (doround) { if (this.nminor >= this.minor.length) return false; @@ -765,15 +767,15 @@ class TAxisPainter extends ObjectPainter { return true; }; - handle.last_major = function() { + handle.last_major = function () { return (this.kind !== 1) ? false : this.nmajor === this.major.length; }; - handle.next_major_grpos = function() { + handle.next_major_grpos = function () { return this.nmajor >= this.major.length ? null : this.func(this.major[this.nmajor]); }; - handle.get_modifier = function() { + handle.get_modifier = function () { return this.painter.findLabelModifier(this.painter.getObject(), this.nmajor - 1, this.major); }; @@ -786,9 +788,9 @@ class TAxisPainter extends ObjectPainter { if (!optionNoexp && !this.cutLabels()) { const maxtick = Math.max(Math.abs(handle.major.at(0)), Math.abs(handle.major.at(-1))), - mintick = Math.min(Math.abs(handle.major.at(0)), Math.abs(handle.major.at(-1))), - ord1 = (maxtick > 0) ? Math.round(Math.log10(maxtick) / 3) * 3 : 0, - ord2 = (mintick > 0) ? Math.round(Math.log10(mintick) / 3) * 3 : 0; + mintick = Math.min(Math.abs(handle.major.at(0)), Math.abs(handle.major.at(-1))), + ord1 = (maxtick > 0) ? Math.round(Math.log10(maxtick) / 3) * 3 : 0, + ord2 = (mintick > 0) ? Math.round(Math.log10(mintick) / 3) * 3 : 0; exclorder3 = (maxtick < 2e4); // do not show 10^3 for values below 20000 @@ -809,7 +811,7 @@ class TAxisPainter extends ObjectPainter { let lbls = [], indx = 0, totallen = 0; while (indx < handle.major.length) { const v0 = handle.major[indx], - lbl = this.format(v0, true); + lbl = this.format(v0, true); let bad_value = lbls.indexOf(lbl) >= 0; if (!bad_value) { @@ -892,7 +894,7 @@ class TAxisPainter extends ObjectPainter { return; let drag_rect = null, x_0, y_0, i_0, - acc_x, acc_y, new_x, new_y, sign_0, alt_pos, curr_indx, can_indx0 = true; + acc_x, acc_y, new_x, new_y, sign_0, alt_pos, curr_indx, can_indx0 = true; const drag_move = d3_drag().subject(Object); drag_move.on('start', evnt => { @@ -900,7 +902,7 @@ class TAxisPainter extends ObjectPainter { evnt.sourceEvent.stopPropagation(); const box = title_g.node().getBBox(), // check that elements visible, request precise value - title_length = vertical ? box.height : box.width; + title_length = vertical ? box.height : box.width; x_0 = new_x = acc_x = title_g.property('shift_x'); y_0 = new_y = acc_y = title_g.property('shift_y'); @@ -979,13 +981,13 @@ class TAxisPainter extends ObjectPainter { evnt.sourceEvent.stopPropagation(); title_g.property('shift_x', new_x) - .property('shift_y', new_y); + .property('shift_y', new_y); const axis = this.getObject(), axis2 = this.source_axis, - setBit = (bit, on) => { - axis?.SetBit(bit, on); - axis2?.SetBit(bit, on); - }; + setBit = (bit, on) => { + axis?.SetBit(bit, on); + axis2?.SetBit(bit, on); + }; this.titleOffset = (vertical ? new_x : new_y) / offset_k; const offset = this.titleOffset / this.offsetScaling / this.titleSize; @@ -1090,7 +1092,7 @@ class TAxisPainter extends ObjectPainter { } if ((mod.fLabNum === nlabel + 1) || - ((mod.fLabNum < 0) && (nlabel === positions.length + mod.fLabNum))) + ((mod.fLabNum < 0) && (nlabel === positions.length + mod.fLabNum))) return mod; } return null; @@ -1100,12 +1102,12 @@ class TAxisPainter extends ObjectPainter { * @return {Promise} with array label size and max width */ async drawLabels(axis_g, axis, w, h, handle, labelsside, labelsFont, labeloffset, tickSize, ticksPlusMinus, max_text_width, frame_ygap) { const center_lbls = this.isCenteredLabels(), - label_g = [axis_g.append('svg:g').attr('class', 'axis_labels')], - lbl_pos = handle.lbl_pos || handle.major, - tilt_angle = gStyle.AxisTiltAngle ?? 25; + label_g = [axis_g.append('svg:g').attr('class', 'axis_labels')], + lbl_pos = handle.lbl_pos || handle.major, + tilt_angle = gStyle.AxisTiltAngle ?? 25; let rotate_lbls = this.isRotateLabels(), - textscale = 1, flipscale = 1, maxtextlen = 0, applied_scale = 0, - lbl_tilt = false, any_modified = false, max_textwidth = 0, max_tiltsize = 0; + textscale = 1, flipscale = 1, maxtextlen = 0, applied_scale = 0, + lbl_tilt = false, any_modified = false, max_textwidth = 0, max_tiltsize = 0; if (this.lbls_both_sides) label_g.push(axis_g.append('svg:g').attr('class', 'axis_labels').attr('transform', this.vertical ? `translate(${w})` : `translate(0,${-h})`)); @@ -1130,7 +1132,7 @@ class TAxisPainter extends ObjectPainter { textscale = Math.min(textscale, (max_text_width - labeloffset) / textwidth); if ((textscale > 0.0001) && (textscale < 0.7) && !any_modified && - !painter.vertical && !rotate_lbls && (label_g.length === 1) && (lbl_tilt === false)) { + !painter.vertical && !rotate_lbls && (label_g.length === 1) && (lbl_tilt === false)) { if (maxtextlen > 5) lbl_tilt = true; } @@ -1301,7 +1303,7 @@ class TAxisPainter extends ObjectPainter { this._maxlbllen = maxtextlen; // for internal use in palette painter if (lbl_tilt) { - label_g[0].selectAll('text').each(function() { + label_g[0].selectAll('text').each(function () { const txt = d3_select(this), tr = txt.attr('transform'); if (lbl_tilt) txt.attr('transform', `${tr} rotate(${tilt_angle})`).style('text-anchor', 'start'); @@ -1320,10 +1322,10 @@ class TAxisPainter extends ObjectPainter { if (axis.$use_top_pad) pp = pp?.getPadPainter(); // workaround for ratio plot const pad_w = pp?.getPadWidth() || scalingSize || w / 0.8, // use factor 0.8 as ratio between frame and pad size - pad_h = pp?.getPadHeight() || scalingSize || h / 0.8, - // if no external scaling size use scaling as in TGaxis.cxx:1448 - NDC axis length is in the scaling factor - tickScalingSize = scalingSize || (this.vertical ? h / pad_h * pad_w : w / pad_w * pad_h), - bit_plus = axis.TestBit(EAxisBits.kTickPlus), bit_minus = axis.TestBit(EAxisBits.kTickMinus); + pad_h = pp?.getPadHeight() || scalingSize || h / 0.8, + // if no external scaling size use scaling as in TGaxis.cxx:1448 - NDC axis length is in the scaling factor + tickScalingSize = scalingSize || (this.vertical ? h / pad_h * pad_w : w / pad_w * pad_h), + bit_plus = axis.TestBit(EAxisBits.kTickPlus), bit_minus = axis.TestBit(EAxisBits.kTickMinus); let tickSize, titleColor, titleFontId, offset; @@ -1419,7 +1421,7 @@ class TAxisPainter extends ObjectPainter { * @return {Promise} for drawing ready */ async drawAxis(layer, w, h, transform, secondShift, disable_axis_drawing, max_text_width, calculate_position, frame_ygap) { const axis = this.getObject(), - swap_side = this.swap_side || false; + swap_side = this.swap_side || false; let axis_g = layer, draw_lines = true; // shift for second ticks set (if any) @@ -1467,33 +1469,33 @@ class TAxisPainter extends ObjectPainter { if (!disable_axis_drawing && axis_lines && !this.lineatt.empty()) { axis_g.append('svg:path') - .attr('d', axis_lines) - .call(this.lineatt.func); + .attr('d', axis_lines) + .call(this.lineatt.func); } let title_shift_x = 0, title_shift_y = 0, title_g, labelsMaxWidth = 0; // draw labels (sometime on both sides) const labelSize = Math.max(this.labelsFont.size, 5), - pr = (disable_axis_drawing || this.optionUnlab) - ? Promise.resolve(0) - : this.drawLabels(axis_g, axis, w, h, handle, side, this.labelsFont, this.labelsOffset, this.ticksSize, ticksPlusMinus, max_text_width, frame_ygap); + pr = (disable_axis_drawing || this.optionUnlab) + ? Promise.resolve(0) + : this.drawLabels(axis_g, axis, w, h, handle, side, this.labelsFont, this.labelsOffset, this.ticksSize, ticksPlusMinus, max_text_width, frame_ygap); return pr.then(maxw => { labelsMaxWidth = maxw; if (settings.Zooming && !this.disable_zooming && !this.isBatchMode()) { const r = axis_g.append('svg:rect') - .attr('class', 'axis_zoom') - .style('opacity', '0') - .style('cursor', 'crosshair'); + .attr('class', 'axis_zoom') + .style('opacity', '0') + .style('cursor', 'crosshair'); if (this.vertical) { const rw = Math.max(labelsMaxWidth, 2 * labelSize) + 3; r.attr('x', (side > 0) ? -rw : 0).attr('y', 0) - .attr('width', rw).attr('height', h); + .attr('width', rw).attr('height', h); } else { r.attr('x', 0).attr('y', (side > 0) ? 0 : -labelSize - 3) - .attr('width', w).attr('height', labelSize + 3); + .attr('width', w).attr('height', labelSize + 3); } } @@ -1501,10 +1503,10 @@ class TAxisPainter extends ObjectPainter { if (calculate_position) { const node1 = axis_g.node(), - node2 = this.getPadPainter()?.getPadSvg().node(); + node2 = this.getPadPainter()?.getPadSvg().node(); if (isFunc(node1?.getBoundingClientRect) && isFunc(node2?.getBoundingClientRect)) { const rect1 = node1.getBoundingClientRect(), - rect2 = node2.getBoundingClientRect(); + rect2 = node2.getBoundingClientRect(); this.position = rect1.left - rect2.left; // use to control left position of Y scale } if (node1 && !node2) @@ -1522,7 +1524,7 @@ class TAxisPainter extends ObjectPainter { return; const rotate = this.isRotateTitle() ? -1 : 1, - xor_reverse = swap_side ^ this.titleOpposite, myxor = (rotate < 0) ^ xor_reverse; + xor_reverse = swap_side ^ this.titleOpposite, myxor = (rotate < 0) ^ xor_reverse; let title_offest_k = side; @@ -1561,7 +1563,7 @@ class TAxisPainter extends ObjectPainter { title_shift_x = Math.round(-side * ((labelsMaxWidth || labelSize) + 0.7 * this.offsetScaling * this.titleSize)); makeTranslate(title_g, title_shift_x, title_shift_y); title_g.property('shift_x', title_shift_x) - .property('shift_y', title_shift_y); + .property('shift_y', title_shift_y); } return this; From f0556a3cb06a5b72420b2d5b4475208f7fb82cc4 Mon Sep 17 00:00:00 2001 From: JasMehta08 Date: Mon, 22 Dec 2025 10:02:51 +0530 Subject: [PATCH 4/5] Revert unrelated changes in Legend and Pave classes --- graf2d/graf/inc/TPave.h | 7 +----- graf2d/graf/src/TLegend.cxx | 11 --------- graf2d/graf/src/TPave.cxx | 13 ---------- graf2d/graf/src/TPaveStats.cxx | 44 +--------------------------------- graf2d/graf/src/TPaveText.cxx | 16 +------------ 5 files changed, 3 insertions(+), 88 deletions(-) diff --git a/graf2d/graf/inc/TPave.h b/graf2d/graf/inc/TPave.h index 89de0d34193a2..df266e73947a7 100644 --- a/graf2d/graf/inc/TPave.h +++ b/graf2d/graf/inc/TPave.h @@ -16,8 +16,6 @@ #include "TBox.h" #include "TString.h" -class TVirtualPad; - class TPave : public TBox { protected: @@ -31,7 +29,6 @@ class TPave : public TBox { Double_t fCornerRadius; ///< Corner radius in case of option arc TString fOption; ///< Pave style TString fName; ///< Pave name - Float_t fRefLength{0}; ///< Reference length for scaling (e.g. ref pad height) TString GetSavePaveArgs(const char *extra_arg = nullptr, Bool_t save_option = kTRUE); @@ -65,7 +62,6 @@ class TPave : public TBox { Double_t GetX2NDC() const {return fX2NDC;} Double_t GetY1NDC() const {return fY1NDC;} Double_t GetY2NDC() const {return fY2NDC;} - Float_t GetRefLength() const { return fRefLength; } ULong_t Hash() const override { return fName.Hash(); } Bool_t IsSortable() const override { return kTRUE; } void ls(Option_t *option="") const override; @@ -85,7 +81,6 @@ class TPave : public TBox { virtual void SetName(const char *name="") {fName = name;} // *MENU* virtual void SetOption(Option_t *option="br") {fOption = option;} virtual void SetShadowColor(Int_t color) {fShadowColor=color;} // *MENU* - virtual void SetRefPad(TVirtualPad *pad); virtual void SetX1NDC(Double_t x1) {fX1NDC=x1;} virtual void SetX2NDC(Double_t x2) {fX2NDC=x2;} virtual void SetY1NDC(Double_t y1) {fY1NDC=y1;} @@ -95,7 +90,7 @@ class TPave : public TBox { void SetY1(Double_t y1) override; void SetY2(Double_t y2) override; - ClassDefOverride(TPave,4) //Pave. A box with shadowing + ClassDefOverride(TPave,3) //Pave. A box with shadowing }; #endif diff --git a/graf2d/graf/src/TLegend.cxx b/graf2d/graf/src/TLegend.cxx index d10ebc73032f1..6d3bb698bd386 100644 --- a/graf2d/graf/src/TLegend.cxx +++ b/graf2d/graf/src/TLegend.cxx @@ -639,17 +639,6 @@ void TLegend::PaintPrimitives() SetTextSize(gStyle->GetLegendTextSize()); textsize = GetTextSize(); } - - // Apply scaling if reference pad is set - Double_t scale = 1.0; - if (fRefLength > 0 && gPad) { - Double_t curH = gPad->GetWh() * gPad->GetAbsHNDC(); - if (curH > 0) scale = fRefLength / curH; - } - if (textsize > 0) { - textsize *= scale; - SetTextSize(textsize); // Set scaled size - } Bool_t autosize = kFALSE; std::vector columnWidths(fNColumns, 0.); diff --git a/graf2d/graf/src/TPave.cxx b/graf2d/graf/src/TPave.cxx index a313402877373..5a42db1e14fd0 100644 --- a/graf2d/graf/src/TPave.cxx +++ b/graf2d/graf/src/TPave.cxx @@ -741,16 +741,3 @@ void TPave::Streamer(TBuffer &R__b) R__b.WriteClassBuffer(TPave::Class(),this); } } - -//////////////////////////////////////////////////////////////////////////////// -/// Set the reference pad to scale attributes (e.g. text size) -/// This allows consistent sizing across pads of different sizes. - -void TPave::SetRefPad(TVirtualPad *pad) -{ - if (!pad) { - fRefLength = 0; - return; - } - fRefLength = pad->GetWh() * pad->GetAbsHNDC(); -} diff --git a/graf2d/graf/src/TPaveStats.cxx b/graf2d/graf/src/TPaveStats.cxx index 83a08e050d9f8..90f1543b67ad9 100644 --- a/graf2d/graf/src/TPaveStats.cxx +++ b/graf2d/graf/src/TPaveStats.cxx @@ -357,45 +357,6 @@ void TPaveStats::Paint(Option_t *option) Double_t dy = std::abs(fY2 - fY1); Double_t titlesize=0; Double_t textsize = GetTextSize(); - - // Save original attributes for restoration - Double_t textsave = textsize; // This is the Original (unscaled) size - Double_t x1save = fX1, x2save = fX2, y1save = fY1, y2save = fY2; - - // Apply scaling if reference pad is set - 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.0001 || scale < 0.9999) { - // Scale Text - if (textsize > 0) { - textsize *= scale; - SetTextSize(textsize); - } - - // Scale Box Coordinates (centering on anchor points) - // Determine width/height in pad coordinates - Double_t w_box = fX2 - fX1; - Double_t h_box = fY2 - fY1; - Double_t w_new = w_box * scale; - Double_t h_new = h_box * scale; - - // Simple anchor logic: keep corner closest to edge fixed - Double_t midX = (fX1NDC + fX2NDC) * 0.5; - Double_t midY = (fY1NDC + fY2NDC) * 0.5; - - // X Axis - if (midX > 0.5) fX1 = fX2 - w_new; // Anchor Right - else fX2 = fX1 + w_new; // Anchor Left - - // Y Axis - if (midY > 0.5) fY1 = fY2 - h_new; // Anchor Top - else fY2 = fY1 + h_new; // Anchor Bottom - } - Int_t nlines = GetSize(); if (nlines == 0) nlines = 5; Int_t print_name = fOptStat%10; @@ -405,7 +366,7 @@ void TPaveStats::Paint(Option_t *option) Double_t y2 = gPad->GetY2(); Float_t margin = fMargin*dx; Double_t yspace = dy/Double_t(nlines); - // Double_t textsave = textsize; // Removed, already defined above + Double_t textsave = textsize; TIter next(fLines); Double_t longest = 0, titlelength = 0; Double_t w, wtok[2]; @@ -542,9 +503,6 @@ void TPaveStats::Paint(Option_t *option) } } SetTextSize(textsave); - if (scale > 1.0001 || scale < 0.9999) { - fX1 = x1save; fX2 = x2save; fY1 = y1save; fY2 = y2save; - } // if a label create & paint a pavetext title if (fLabel.Length() > 0) { diff --git a/graf2d/graf/src/TPaveText.cxx b/graf2d/graf/src/TPaveText.cxx index 01b176aefa0d9..b242d0b58f32f 100644 --- a/graf2d/graf/src/TPaveText.cxx +++ b/graf2d/graf/src/TPaveText.cxx @@ -431,20 +431,6 @@ void TPaveText::PaintPrimitives(Int_t mode) Double_t dx = fX2 - fX1; Double_t dy = fY2 - fY1; Double_t textsize = GetTextSize(); - // Save original text size for restoration at the end - Double_t textsave = textsize; - - // Apply scaling if reference pad is set - Double_t scale = 1.0; - if (fRefLength > 0 && gPad) { - Double_t curH = gPad->GetWh() * gPad->GetAbsHNDC(); - if (curH > 0) scale = fRefLength / curH; - } - if (textsize > 0) { - textsize *= scale; - SetTextSize(textsize); // Temporarily set member so individual lines pick it up - } - Int_t nlines = GetSize(); if (nlines == 0) nlines = 5; @@ -455,7 +441,7 @@ void TPaveText::PaintPrimitives(Int_t mode) y2 = gPad->GetY2(); Float_t margin = fMargin*dx; Double_t yspace = dy/Double_t(nlines); - // Double_t textsave = textsize; // Removed, already defined above + Double_t textsave = textsize; TObject *line; TText *linet; TLatex *latex; From 0f96d53040af9e144909d89fc1db26b92b678145 Mon Sep 17 00:00:00 2001 From: JasMehta08 Date: Mon, 22 Dec 2025 10:06:39 +0530 Subject: [PATCH 5/5] Revert unrelated changes in TAxisPainter.mjs --- js/modules/gpad/TAxisPainter.mjs | 136 +++++++++++++++---------------- 1 file changed, 67 insertions(+), 69 deletions(-) diff --git a/js/modules/gpad/TAxisPainter.mjs b/js/modules/gpad/TAxisPainter.mjs index 3d2c456aaac80..218e1d0fd6f79 100644 --- a/js/modules/gpad/TAxisPainter.mjs +++ b/js/modules/gpad/TAxisPainter.mjs @@ -1,9 +1,7 @@ import { gStyle, settings, constants, clTAxis, clTGaxis, isFunc, isStr } from '../core.mjs'; -import { - select as d3_select, drag as d3_drag, timeFormat as d3_timeFormat, utcFormat as d3_utcFormat, - scaleTime as d3_scaleTime, scaleSymlog as d3_scaleSymlog, - scaleLog as d3_scaleLog, scaleLinear as d3_scaleLinear -} from '../d3.mjs'; +import { select as d3_select, drag as d3_drag, timeFormat as d3_timeFormat, utcFormat as d3_utcFormat, + scaleTime as d3_scaleTime, scaleSymlog as d3_scaleSymlog, + scaleLog as d3_scaleLog, scaleLinear as d3_scaleLinear } from '../d3.mjs'; import { floatToString, makeTranslate, addHighlightStyle } from '../base/BasePainter.mjs'; import { ObjectPainter, EAxisBits, kAxisLabels, kAxisNormal, kAxisFunc, kAxisTime } from '../base/ObjectPainter.mjs'; import { FontHandler } from '../base/FontHandler.mjs'; @@ -43,12 +41,12 @@ function getTimeOffset(axis) { }; // eslint-disable-next-line one-var const year = next('-', 1900, 2900), - month = next('-', 1, 12) - 1, - day = next(' ', 1, 31), - hour = next(':', 0, 23), - min = next(':', 0, 59), - sec = next('s', 0, 59), - msec = next(' ', 0, 999); + month = next('-', 1, 12) - 1, + day = next(' ', 1, 31), + hour = next(':', 0, 23), + min = next(':', 0, 59), + sec = next('s', 0, 59), + msec = next(' ', 0, 999); let offset = Date.UTC(year, month, day, hour, min, sec, msec); @@ -273,7 +271,7 @@ const AxisPainterMethods = { sum2 += diff ** 2; } const mean = sum1 / (arr.length - 1), - dev = sum2 / (arr.length - 1) - mean ** 2; + dev = sum2 / (arr.length - 1) - mean ** 2; if (dev <= 0) return true; @@ -313,13 +311,13 @@ const AxisPainterMethods = { return this.poduceLogTicks(this.func, total); const dom = this.func.domain(), - check = ticks => { - if (ticks.length <= total) - return true; - if (ticks.length > total + 1) - return false; - return (ticks[0] === dom[0]) || (ticks[total] === dom[1]); // special case of N+1 ticks, but match any range - }, res1 = this.func.ticks(total); + check = ticks => { + if (ticks.length <= total) + return true; + if (ticks.length > total + 1) + return false; + return (ticks[0] === dom[0]) || (ticks[total] === dom[1]); // special case of N+1 ticks, but match any range + }, res1 = this.func.ticks(total); if (ndiv2 || check(res1)) return res1; @@ -364,9 +362,9 @@ const AxisPainterMethods = { delta_right *= delta; const lmin = item.min = this.scale_min, - lmax = item.max = this.scale_max, - gmin = this.full_min, - gmax = this.full_max; + lmax = item.max = this.scale_max, + gmin = this.full_min, + gmax = this.full_max; if ((item.min === item.max) && (delta < 0)) { item.min = gmin; @@ -424,7 +422,7 @@ const AxisPainterMethods = { else if (delta_left !== delta_right) { // extra check case when moving left or right if (((item.min < gmin) && (lmin === gmin)) || - ((item.max > gmax) && (lmax === gmax))) + ((item.max > gmax) && (lmax === gmax))) item.min = item.max = undefined; } else { item.min = Math.max(item.min, gmin); @@ -602,8 +600,8 @@ class TAxisPainter extends ObjectPainter { this.nticks = Math.min(this.nticks, 8); const scale_range = this.scale_max - this.scale_min, - idF = axis.fTimeFormat.indexOf('%F'), - tf2 = chooseTimeFormat(scale_range / gr_range, false); + idF = axis.fTimeFormat.indexOf('%F'), + tf2 = chooseTimeFormat(scale_range / gr_range, false); let tf1 = (idF >= 0) ? axis.fTimeFormat.slice(0, idF) : axis.fTimeFormat; if (!tf1 || (scale_range < 0.1 * (this.full_max - this.full_min))) @@ -634,7 +632,7 @@ class TAxisPainter extends ObjectPainter { if (axis?.fNbins && axis?.fLabels) { if ((axis.fNbins !== Math.round(axis.fXmax - axis.fXmin)) || - axis.fXmin || (axis.fXmax !== axis.fNbins)) + axis.fXmin || (axis.fXmax !== axis.fNbins)) this.regular_labels = false; } @@ -741,11 +739,11 @@ class TAxisPainter extends ObjectPainter { } } - handle.reset = function () { + handle.reset = function() { this.nminor = this.nmiddle = this.nmajor = 0; }; - handle.next = function (doround) { + handle.next = function(doround) { if (this.nminor >= this.minor.length) return false; @@ -767,15 +765,15 @@ class TAxisPainter extends ObjectPainter { return true; }; - handle.last_major = function () { + handle.last_major = function() { return (this.kind !== 1) ? false : this.nmajor === this.major.length; }; - handle.next_major_grpos = function () { + handle.next_major_grpos = function() { return this.nmajor >= this.major.length ? null : this.func(this.major[this.nmajor]); }; - handle.get_modifier = function () { + handle.get_modifier = function() { return this.painter.findLabelModifier(this.painter.getObject(), this.nmajor - 1, this.major); }; @@ -788,9 +786,9 @@ class TAxisPainter extends ObjectPainter { if (!optionNoexp && !this.cutLabels()) { const maxtick = Math.max(Math.abs(handle.major.at(0)), Math.abs(handle.major.at(-1))), - mintick = Math.min(Math.abs(handle.major.at(0)), Math.abs(handle.major.at(-1))), - ord1 = (maxtick > 0) ? Math.round(Math.log10(maxtick) / 3) * 3 : 0, - ord2 = (mintick > 0) ? Math.round(Math.log10(mintick) / 3) * 3 : 0; + mintick = Math.min(Math.abs(handle.major.at(0)), Math.abs(handle.major.at(-1))), + ord1 = (maxtick > 0) ? Math.round(Math.log10(maxtick) / 3) * 3 : 0, + ord2 = (mintick > 0) ? Math.round(Math.log10(mintick) / 3) * 3 : 0; exclorder3 = (maxtick < 2e4); // do not show 10^3 for values below 20000 @@ -811,7 +809,7 @@ class TAxisPainter extends ObjectPainter { let lbls = [], indx = 0, totallen = 0; while (indx < handle.major.length) { const v0 = handle.major[indx], - lbl = this.format(v0, true); + lbl = this.format(v0, true); let bad_value = lbls.indexOf(lbl) >= 0; if (!bad_value) { @@ -894,7 +892,7 @@ class TAxisPainter extends ObjectPainter { return; let drag_rect = null, x_0, y_0, i_0, - acc_x, acc_y, new_x, new_y, sign_0, alt_pos, curr_indx, can_indx0 = true; + acc_x, acc_y, new_x, new_y, sign_0, alt_pos, curr_indx, can_indx0 = true; const drag_move = d3_drag().subject(Object); drag_move.on('start', evnt => { @@ -902,7 +900,7 @@ class TAxisPainter extends ObjectPainter { evnt.sourceEvent.stopPropagation(); const box = title_g.node().getBBox(), // check that elements visible, request precise value - title_length = vertical ? box.height : box.width; + title_length = vertical ? box.height : box.width; x_0 = new_x = acc_x = title_g.property('shift_x'); y_0 = new_y = acc_y = title_g.property('shift_y'); @@ -981,13 +979,13 @@ class TAxisPainter extends ObjectPainter { evnt.sourceEvent.stopPropagation(); title_g.property('shift_x', new_x) - .property('shift_y', new_y); + .property('shift_y', new_y); const axis = this.getObject(), axis2 = this.source_axis, - setBit = (bit, on) => { - axis?.SetBit(bit, on); - axis2?.SetBit(bit, on); - }; + setBit = (bit, on) => { + axis?.SetBit(bit, on); + axis2?.SetBit(bit, on); + }; this.titleOffset = (vertical ? new_x : new_y) / offset_k; const offset = this.titleOffset / this.offsetScaling / this.titleSize; @@ -1092,7 +1090,7 @@ class TAxisPainter extends ObjectPainter { } if ((mod.fLabNum === nlabel + 1) || - ((mod.fLabNum < 0) && (nlabel === positions.length + mod.fLabNum))) + ((mod.fLabNum < 0) && (nlabel === positions.length + mod.fLabNum))) return mod; } return null; @@ -1102,12 +1100,12 @@ class TAxisPainter extends ObjectPainter { * @return {Promise} with array label size and max width */ async drawLabels(axis_g, axis, w, h, handle, labelsside, labelsFont, labeloffset, tickSize, ticksPlusMinus, max_text_width, frame_ygap) { const center_lbls = this.isCenteredLabels(), - label_g = [axis_g.append('svg:g').attr('class', 'axis_labels')], - lbl_pos = handle.lbl_pos || handle.major, - tilt_angle = gStyle.AxisTiltAngle ?? 25; + label_g = [axis_g.append('svg:g').attr('class', 'axis_labels')], + lbl_pos = handle.lbl_pos || handle.major, + tilt_angle = gStyle.AxisTiltAngle ?? 25; let rotate_lbls = this.isRotateLabels(), - textscale = 1, flipscale = 1, maxtextlen = 0, applied_scale = 0, - lbl_tilt = false, any_modified = false, max_textwidth = 0, max_tiltsize = 0; + textscale = 1, flipscale = 1, maxtextlen = 0, applied_scale = 0, + lbl_tilt = false, any_modified = false, max_textwidth = 0, max_tiltsize = 0; if (this.lbls_both_sides) label_g.push(axis_g.append('svg:g').attr('class', 'axis_labels').attr('transform', this.vertical ? `translate(${w})` : `translate(0,${-h})`)); @@ -1132,7 +1130,7 @@ class TAxisPainter extends ObjectPainter { textscale = Math.min(textscale, (max_text_width - labeloffset) / textwidth); if ((textscale > 0.0001) && (textscale < 0.7) && !any_modified && - !painter.vertical && !rotate_lbls && (label_g.length === 1) && (lbl_tilt === false)) { + !painter.vertical && !rotate_lbls && (label_g.length === 1) && (lbl_tilt === false)) { if (maxtextlen > 5) lbl_tilt = true; } @@ -1303,7 +1301,7 @@ class TAxisPainter extends ObjectPainter { this._maxlbllen = maxtextlen; // for internal use in palette painter if (lbl_tilt) { - label_g[0].selectAll('text').each(function () { + label_g[0].selectAll('text').each(function() { const txt = d3_select(this), tr = txt.attr('transform'); if (lbl_tilt) txt.attr('transform', `${tr} rotate(${tilt_angle})`).style('text-anchor', 'start'); @@ -1322,10 +1320,10 @@ class TAxisPainter extends ObjectPainter { if (axis.$use_top_pad) pp = pp?.getPadPainter(); // workaround for ratio plot const pad_w = pp?.getPadWidth() || scalingSize || w / 0.8, // use factor 0.8 as ratio between frame and pad size - pad_h = pp?.getPadHeight() || scalingSize || h / 0.8, - // if no external scaling size use scaling as in TGaxis.cxx:1448 - NDC axis length is in the scaling factor - tickScalingSize = scalingSize || (this.vertical ? h / pad_h * pad_w : w / pad_w * pad_h), - bit_plus = axis.TestBit(EAxisBits.kTickPlus), bit_minus = axis.TestBit(EAxisBits.kTickMinus); + pad_h = pp?.getPadHeight() || scalingSize || h / 0.8, + // if no external scaling size use scaling as in TGaxis.cxx:1448 - NDC axis length is in the scaling factor + tickScalingSize = scalingSize || (this.vertical ? h / pad_h * pad_w : w / pad_w * pad_h), + bit_plus = axis.TestBit(EAxisBits.kTickPlus), bit_minus = axis.TestBit(EAxisBits.kTickMinus); let tickSize, titleColor, titleFontId, offset; @@ -1421,7 +1419,7 @@ class TAxisPainter extends ObjectPainter { * @return {Promise} for drawing ready */ async drawAxis(layer, w, h, transform, secondShift, disable_axis_drawing, max_text_width, calculate_position, frame_ygap) { const axis = this.getObject(), - swap_side = this.swap_side || false; + swap_side = this.swap_side || false; let axis_g = layer, draw_lines = true; // shift for second ticks set (if any) @@ -1469,33 +1467,33 @@ class TAxisPainter extends ObjectPainter { if (!disable_axis_drawing && axis_lines && !this.lineatt.empty()) { axis_g.append('svg:path') - .attr('d', axis_lines) - .call(this.lineatt.func); + .attr('d', axis_lines) + .call(this.lineatt.func); } let title_shift_x = 0, title_shift_y = 0, title_g, labelsMaxWidth = 0; // draw labels (sometime on both sides) const labelSize = Math.max(this.labelsFont.size, 5), - pr = (disable_axis_drawing || this.optionUnlab) - ? Promise.resolve(0) - : this.drawLabels(axis_g, axis, w, h, handle, side, this.labelsFont, this.labelsOffset, this.ticksSize, ticksPlusMinus, max_text_width, frame_ygap); + pr = (disable_axis_drawing || this.optionUnlab) + ? Promise.resolve(0) + : this.drawLabels(axis_g, axis, w, h, handle, side, this.labelsFont, this.labelsOffset, this.ticksSize, ticksPlusMinus, max_text_width, frame_ygap); return pr.then(maxw => { labelsMaxWidth = maxw; if (settings.Zooming && !this.disable_zooming && !this.isBatchMode()) { const r = axis_g.append('svg:rect') - .attr('class', 'axis_zoom') - .style('opacity', '0') - .style('cursor', 'crosshair'); + .attr('class', 'axis_zoom') + .style('opacity', '0') + .style('cursor', 'crosshair'); if (this.vertical) { const rw = Math.max(labelsMaxWidth, 2 * labelSize) + 3; r.attr('x', (side > 0) ? -rw : 0).attr('y', 0) - .attr('width', rw).attr('height', h); + .attr('width', rw).attr('height', h); } else { r.attr('x', 0).attr('y', (side > 0) ? 0 : -labelSize - 3) - .attr('width', w).attr('height', labelSize + 3); + .attr('width', w).attr('height', labelSize + 3); } } @@ -1503,10 +1501,10 @@ class TAxisPainter extends ObjectPainter { if (calculate_position) { const node1 = axis_g.node(), - node2 = this.getPadPainter()?.getPadSvg().node(); + node2 = this.getPadPainter()?.getPadSvg().node(); if (isFunc(node1?.getBoundingClientRect) && isFunc(node2?.getBoundingClientRect)) { const rect1 = node1.getBoundingClientRect(), - rect2 = node2.getBoundingClientRect(); + rect2 = node2.getBoundingClientRect(); this.position = rect1.left - rect2.left; // use to control left position of Y scale } if (node1 && !node2) @@ -1524,7 +1522,7 @@ class TAxisPainter extends ObjectPainter { return; const rotate = this.isRotateTitle() ? -1 : 1, - xor_reverse = swap_side ^ this.titleOpposite, myxor = (rotate < 0) ^ xor_reverse; + xor_reverse = swap_side ^ this.titleOpposite, myxor = (rotate < 0) ^ xor_reverse; let title_offest_k = side; @@ -1563,7 +1561,7 @@ class TAxisPainter extends ObjectPainter { title_shift_x = Math.round(-side * ((labelsMaxWidth || labelSize) + 0.7 * this.offsetScaling * this.titleSize)); makeTranslate(title_g, title_shift_x, title_shift_y); title_g.property('shift_x', title_shift_x) - .property('shift_y', title_shift_y); + .property('shift_y', title_shift_y); } return this;