Skip to content

Commit 0ef4977

Browse files
committed
Fix - properly adjust size of stats box
Depending from histogram type and showing fit parameters, different algorithm is used to adjust size of the stats box. Make it maximally the same as in ROOT
1 parent 0e6aeb6 commit 0ef4977

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

modules/hist/TPavePainter.mjs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,22 @@ class TPavePainter extends ObjectPainter {
196196
// we take statistic from main painter
197197
if (main.fillStatistic(this, dostat, dofit)) {
198198
// adjust the size of the stats box with the number of lines
199-
const nlines = pt.fLines?.arr.length || 0;
200-
if ((nlines > 0) && !this.moved_interactive && ((gStyle.fStatFontSize <= 0) || (gStyle.fStatFont % 10 === 3)))
201-
pt.fY1NDC = Math.max(0.02, pt.fY2NDC - ((nlines < 8) ? nlines * 0.25 * gStyle.fStatH : nlines * 0.025));
199+
let nlines = pt.fLines?.arr.length || 0;
200+
if ((nlines > 0) && !this.moved_interactive) {
201+
// in ROOT TH2 and TH3 always add full statsh for fit parameters
202+
const extrah = this._has_fit && (this._fit_dim > 1) ? gStyle.fStatH : 0;
203+
// but fit parameters not used in full size calculations
204+
if (extrah) nlines -= this._fit_cnt;
205+
let stath = gStyle.fStatH, statw = gStyle.fStatW;
206+
if (this._has_fit)
207+
statw = 1.8 * gStyle.fStatW;
208+
if ((gStyle.fStatFontSize <= 0) || (gStyle.fStatFont % 10 === 3))
209+
stath = nlines * 0.25 * gStyle.fStatH;
210+
else if (gStyle.fStatFontSize < 1)
211+
stath = nlines * gStyle.fStatFontSize;
212+
pt.fX1NDC = Math.max(0.02, pt.fX2NDC - statw);
213+
pt.fY1NDC = Math.max(0.02, pt.fY2NDC - stath - extrah);
214+
}
202215
}
203216
}
204217
}
@@ -1174,17 +1187,27 @@ class TPavePainter extends ObjectPainter {
11741187

11751188
/** @summary Fill function parameters */
11761189
fillFunctionStat(f1, dofit, ndim = 1) {
1190+
this._has_fit = false;
1191+
11771192
if (!dofit || !f1) return false;
11781193

1194+
this._has_fit = true;
1195+
this._fit_dim = ndim;
1196+
this._fit_cnt = 0;
1197+
11791198
const print_fval = (ndim === 1) ? dofit % 10 : 1,
11801199
print_ferrors = (ndim === 1) ? Math.floor(dofit/10) % 10 : 1,
11811200
print_fchi2 = (ndim === 1) ? Math.floor(dofit/100) % 10 : 1,
11821201
print_fprob = (ndim === 1) ? Math.floor(dofit/1000) % 10 : 0;
11831202

1184-
if (print_fchi2)
1203+
if (print_fchi2) {
11851204
this.addText('#chi^{2} / ndf = ' + this.format(f1.fChisquare, 'fit') + ' / ' + f1.fNDF);
1186-
if (print_fprob)
1205+
this._fit_cnt++;
1206+
}
1207+
if (print_fprob) {
11871208
this.addText('Prob = ' + this.format(Prob(f1.fChisquare, f1.fNDF)));
1209+
this._fit_cnt++;
1210+
}
11881211
if (print_fval) {
11891212
for (let n = 0; n < f1.GetNumPars(); ++n) {
11901213
const parname = f1.GetParName(n);
@@ -1201,9 +1224,11 @@ class TPavePainter extends ObjectPainter {
12011224
this.addText(`${parname} = ${parvalue} #pm ${parerr}`);
12021225
else
12031226
this.addText(`${parname} = ${parvalue}`);
1227+
this._fit_cnt++;
12041228
}
12051229
}
12061230

1231+
12071232
return true;
12081233
}
12091234

0 commit comments

Comments
 (0)