Skip to content

Commit 71a1288

Browse files
committed
Format around return in core.mjs
1 parent c5765db commit 71a1288

File tree

1 file changed

+79
-42
lines changed

1 file changed

+79
-42
lines changed

modules/core.mjs

Lines changed: 79 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const version_id = 'dev',
44

55
/** @summary version date
66
* @desc Release date in format day/month/year like '14/04/2022' */
7-
version_date = '24/09/2025',
7+
version_date = '25/09/2025',
88

99
/** @summary version id and date
1010
* @desc Produced by concatenation of {@link version_id} and {@link version_date}
@@ -142,7 +142,8 @@ if ((typeof document !== 'undefined') && (typeof window !== 'undefined') && (typ
142142
* @return {Number} 0 - not array, 1 - regular array, 2 - typed array
143143
* @private */
144144
function isArrayProto(proto) {
145-
if ((proto.length < 14) || proto.indexOf('[object ')) return 0;
145+
if ((proto.length < 14) || proto.indexOf('[object '))
146+
return 0;
146147
const p = proto.indexOf('Array]');
147148
if ((p < 0) || (p !== proto.length - 6))
148149
return 0;
@@ -165,9 +166,12 @@ const constants = {
165166
/** @summary Use SVG rendering, slow, imprecise and not interactive, not recommended */
166167
SVG: 3,
167168
fromString(s) {
168-
if ((s === 'webgl') || (s === 'gl')) return this.WebGL;
169-
if (s === 'img') return this.WebGLImage;
170-
if (s === 'svg') return this.SVG;
169+
if ((s === 'webgl') || (s === 'gl'))
170+
return this.WebGL;
171+
if (s === 'img')
172+
return this.WebGLImage;
173+
if (s === 'svg')
174+
return this.SVG;
171175
return this.Default;
172176
}
173177
},
@@ -186,8 +190,10 @@ const constants = {
186190
EmbedSVG: 3,
187191
/** @summary Convert string values into number */
188192
fromString(s) {
189-
if (s === 'embed') return this.Embed;
190-
if (s === 'overlay') return this.Overlay;
193+
if (s === 'embed')
194+
return this.Embed;
195+
if (s === 'overlay')
196+
return this.Overlay;
191197
return this.Default;
192198
}
193199
},
@@ -577,13 +583,15 @@ function BIT(n) { return 1 << n; }
577583
* @return {object} cloned object
578584
* @private */
579585
function clone(src, map, nofunc) {
580-
if (!src) return null;
586+
if (!src)
587+
return null;
581588

582589
if (!map)
583590
map = { obj: [], clones: [], nofunc };
584591
else {
585592
const i = map.obj.indexOf(src);
586-
if (i >= 0) return map.clones[i];
593+
if (i >= 0)
594+
return map.clones[i];
587595
}
588596

589597
const arr_kind = isArrayProto(Object.prototype.toString.apply(src));
@@ -639,7 +647,8 @@ let addMethods = null;
639647
* @param {object|string} json object where references will be replaced
640648
* @return {object} parsed object */
641649
function parse(json) {
642-
if (!json) return null;
650+
if (!json)
651+
return null;
643652

644653
const obj = isStr(json) ? JSON.parse(json) : json, map = [];
645654
let newfmt;
@@ -771,7 +780,8 @@ function parse(json) {
771780
* @param {string} json string to parse
772781
* @return {Array} array of parsed elements */
773782
function parseMulti(json) {
774-
if (!json) return null;
783+
if (!json)
784+
return null;
775785
const arr = JSON.parse(json);
776786
if (arr?.length) {
777787
for (let i = 0; i < arr.length; ++i)
@@ -793,13 +803,16 @@ function parseMulti(json) {
793803
* obj.fTitle = 'New histogram title';
794804
* let json = toJSON(obj); */
795805
function toJSON(obj, spacing) {
796-
if (!isObject(obj)) return '';
806+
if (!isObject(obj))
807+
return '';
797808

798809
const map = [], // map of stored objects
799810
copy_value = value => {
800-
if (isFunc(value)) return undefined;
811+
if (isFunc(value))
812+
return undefined;
801813

802-
if ((value === undefined) || (value === null) || !isObject(value)) return value;
814+
if ((value === undefined) || (value === null) || !isObject(value))
815+
return value;
803816

804817
// typed array need to be converted into normal array, otherwise looks strange
805818
if (isArrayProto(Object.prototype.toString.apply(value)) > 0) {
@@ -811,7 +824,8 @@ function toJSON(obj, spacing) {
811824

812825
// this is how reference is code
813826
const refid = map.indexOf(value);
814-
if (refid >= 0) return { $ref: refid };
827+
if (refid >= 0)
828+
return { $ref: refid };
815829

816830
const ks = Object.keys(value), len = ks.length, tgt = {};
817831

@@ -857,13 +871,15 @@ function decodeUrl(url) {
857871
};
858872

859873
if (!url || !isStr(url)) {
860-
if (settings.IgnoreUrlOptions || (typeof document === 'undefined')) return res;
874+
if (settings.IgnoreUrlOptions || (typeof document === 'undefined'))
875+
return res;
861876
url = document.URL;
862877
}
863878
res.url = url;
864879

865880
const p1 = url.indexOf('?');
866-
if (p1 < 0) return res;
881+
if (p1 < 0)
882+
return res;
867883
url = decodeURI(url.slice(p1+1));
868884

869885
while (url) {
@@ -899,8 +915,10 @@ function decodeUrl(url) {
899915
/** @summary Find function with given name
900916
* @private */
901917
function findFunction(name) {
902-
if (isFunc(name)) return name;
903-
if (!isStr(name)) return null;
918+
if (isFunc(name))
919+
return name;
920+
if (!isStr(name))
921+
return null;
904922
const names = name.split('.');
905923
let elem = globalThis;
906924

@@ -1537,11 +1555,15 @@ function create(typename, target) {
15371555
* h1.fXaxis.fLabelSize = 0.02; */
15381556
function createHistogram(typename, nbinsx, nbinsy, nbinsz) {
15391557
const histo = create(typename);
1540-
if (!histo.fXaxis || !histo.fYaxis || !histo.fZaxis) return null;
1558+
if (!histo.fXaxis || !histo.fYaxis || !histo.fZaxis)
1559+
return null;
15411560
histo.fName = 'hist'; histo.fTitle = 'title';
1542-
if (nbinsx) extend(histo.fXaxis, { fNbins: nbinsx, fXmin: 0, fXmax: nbinsx });
1543-
if (nbinsy) extend(histo.fYaxis, { fNbins: nbinsy, fXmin: 0, fXmax: nbinsy });
1544-
if (nbinsz) extend(histo.fZaxis, { fNbins: nbinsz, fXmin: 0, fXmax: nbinsz });
1561+
if (nbinsx)
1562+
extend(histo.fXaxis, { fNbins: nbinsx, fXmin: 0, fXmax: nbinsx });
1563+
if (nbinsy)
1564+
extend(histo.fYaxis, { fNbins: nbinsy, fXmin: 0, fXmax: nbinsy });
1565+
if (nbinsz)
1566+
extend(histo.fZaxis, { fNbins: nbinsz, fXmin: 0, fXmax: nbinsz });
15451567
switch (parseInt(typename[2])) {
15461568
case 1: if (nbinsx) histo.fNcells = nbinsx+2; break;
15471569
case 2: if (nbinsx && nbinsy) histo.fNcells = (nbinsx+2) * (nbinsy+2); break;
@@ -1573,9 +1595,12 @@ function setHistogramTitle(histo, title) {
15731595
else {
15741596
const arr = title.split(';');
15751597
histo.fTitle = arr[0];
1576-
if (arr.length > 1) histo.fXaxis.fTitle = arr[1];
1577-
if (arr.length > 2) histo.fYaxis.fTitle = arr[2];
1578-
if (arr.length > 3) histo.fZaxis.fTitle = arr[3];
1598+
if (arr.length > 1)
1599+
histo.fXaxis.fTitle = arr[1];
1600+
if (arr.length > 2)
1601+
histo.fYaxis.fTitle = arr[2];
1602+
if (arr.length > 3)
1603+
histo.fZaxis.fTitle = arr[3];
15791604
}
15801605
}
15811606

@@ -1660,7 +1685,8 @@ const methodsCache = {};
16601685
function getMethods(typename, obj) {
16611686
let m = methodsCache[typename];
16621687
const has_methods = (m !== undefined);
1663-
if (!has_methods) m = {};
1688+
if (!has_methods)
1689+
m = {};
16641690

16651691
// Due to binary I/O such TObject methods may not be set for derived classes
16661692
// Therefore when methods requested for given object, check also that basic methods are there
@@ -1672,7 +1698,8 @@ function getMethods(typename, obj) {
16721698
}
16731699
}
16741700

1675-
if (has_methods) return m;
1701+
if (has_methods)
1702+
return m;
16761703

16771704
if ((typename === clTList) || (typename === clTHashList)) {
16781705
m.Clear = function() {
@@ -1728,10 +1755,11 @@ function getMethods(typename, obj) {
17281755
return (this.fNames && this.fNames[n]) ? this.fNames[n] : `p${n}`;
17291756
};
17301757
m.GetParValue = function(n) {
1731-
if (this.fParams?.fParameters) return this.fParams.fParameters[n];
1732-
if (this.fFormula?.fClingParameters) return this.fFormula.fClingParameters[n];
1733-
if (this.fParams) return this.fParams[n];
1734-
return undefined;
1758+
if (this.fParams?.fParameters)
1759+
return this.fParams.fParameters[n];
1760+
if (this.fFormula?.fClingParameters)
1761+
return this.fFormula.fClingParameters[n];
1762+
return this.fParams ? this.fParams[n] : undefined;
17351763
};
17361764
m.GetParError = function(n) {
17371765
return this.fParErrors ? this.fParErrors[n] : undefined;
@@ -1820,11 +1848,12 @@ function getMethods(typename, obj) {
18201848
m.Divide = function(nx, ny, xmargin = 0.01, ymargin = 0.01, color = 0) {
18211849
if (!ny) {
18221850
const ndiv = nx;
1823-
if (ndiv < 2) return this;
1851+
if (ndiv < 2)
1852+
return this;
18241853
nx = ny = Math.round(Math.sqrt(ndiv));
18251854
if (nx * ny < ndiv) nx += 1;
18261855
}
1827-
if (nx*ny < 2)
1856+
if (nx * ny < 2)
18281857
return 0;
18291858
this.fPrimitives.Clear();
18301859
const dy = 1/ny, dx = 1/nx;
@@ -1873,7 +1902,8 @@ function getMethods(typename, obj) {
18731902
m.getBin = function(x, y, z) { return (x + (this.fXaxis.fNbins+2) * (y + (this.fYaxis.fNbins+2) * z)); };
18741903
m.getBinContent = function(x, y, z) {
18751904
const bin = this.getBin(x, y, z);
1876-
if (bin < 0 || bin >= this.fNcells || this.fBinEntries[bin] < 1e-300) return 0;
1905+
if (bin < 0 || bin >= this.fNcells || this.fBinEntries[bin] < 1e-300)
1906+
return 0;
18771907
return this.fArray ? this.fArray[bin]/this.fBinEntries[bin] : 0;
18781908
};
18791909
m.getBinEntries = function(x, y, z) {
@@ -1884,7 +1914,8 @@ function getMethods(typename, obj) {
18841914
m.getBin = function(x, y) { return (x + (this.fXaxis.fNbins+2) * y); };
18851915
m.getBinContent = function(x, y) {
18861916
const bin = this.getBin(x, y);
1887-
if (bin < 0 || bin >= this.fNcells || this.fBinEntries[bin] < 1e-300) return 0;
1917+
if (bin < 0 || bin >= this.fNcells || this.fBinEntries[bin] < 1e-300)
1918+
return 0;
18881919
return this.fArray ? this.fArray[bin]/this.fBinEntries[bin] : 0;
18891920
};
18901921
m.getBinEntries = function(x, y) {
@@ -1894,15 +1925,17 @@ function getMethods(typename, obj) {
18941925
} else {
18951926
m.getBin = function(x) { return x; };
18961927
m.getBinContent = function(bin) {
1897-
if (bin < 0 || bin >= this.fNcells || this.fBinEntries[bin] < 1e-300) return 0;
1928+
if (bin < 0 || bin >= this.fNcells || this.fBinEntries[bin] < 1e-300)
1929+
return 0;
18981930
return this.fArray ? this.fArray[bin]/this.fBinEntries[bin] : 0;
18991931
};
19001932
m.getBinEntries = function(bin) {
19011933
return (bin < 0) || (bin >= this.fNcells) ? 0 : this.fBinEntries[bin];
19021934
};
19031935
}
19041936
m.getBinEffectiveEntries = function(bin) {
1905-
if (bin < 0 || bin >= this.fNcells) return 0;
1937+
if (bin < 0 || bin >= this.fNcells)
1938+
return 0;
19061939
const sumOfWeights = this.fBinEntries[bin];
19071940
if (!this.fBinSumw2 || this.fBinSumw2.length !== this.fNcells)
19081941
// this can happen when reading an old file
@@ -1911,28 +1944,32 @@ function getMethods(typename, obj) {
19111944
return (sumOfWeightsSquare > 0) ? sumOfWeights * sumOfWeights / sumOfWeightsSquare : 0;
19121945
};
19131946
m.getBinError = function(bin) {
1914-
if (bin < 0 || bin >= this.fNcells) return 0;
1947+
if (bin < 0 || bin >= this.fNcells)
1948+
return 0;
19151949
const cont = this.fArray[bin], // sum of bin w *y
19161950
sum = this.fBinEntries[bin], // sum of bin weights
19171951
err2 = this.fSumw2[bin], // sum of bin w * y^2
19181952
neff = this.getBinEffectiveEntries(bin); // (sum of w)^2 / (sum of w^2)
1919-
if (sum < 1e-300) return 0; // for empty bins
1953+
if (sum < 1e-300)
1954+
return 0; // for empty bins
19201955
const EErrorType = { kERRORMEAN: 0, kERRORSPREAD: 1, kERRORSPREADI: 2, kERRORSPREADG: 3 };
19211956
// case the values y are gaussian distributed y +/- sigma and w = 1/sigma^2
19221957
if (this.fErrorMode === EErrorType.kERRORSPREADG)
19231958
return 1.0/Math.sqrt(sum);
19241959
// compute variance in y (eprim2) and standard deviation in y (eprim)
19251960
const contsum = cont/sum, eprim = Math.sqrt(Math.abs(err2/sum - contsum**2));
19261961
if (this.fErrorMode === EErrorType.kERRORSPREADI) {
1927-
if (eprim) return eprim / Math.sqrt(neff);
1962+
if (eprim)
1963+
return eprim / Math.sqrt(neff);
19281964
// in case content y is an integer (so each my has an error +/- 1/sqrt(12)
19291965
// when the std(y) is zero
19301966
return 1.0 / Math.sqrt(12*neff);
19311967
}
19321968
// if approximate compute the sums (of w, wy and wy2) using all the bins
19331969
// when the variance in y is zero
19341970
// case option 'S' return standard deviation in y
1935-
if (this.fErrorMode === EErrorType.kERRORSPREAD) return eprim;
1971+
if (this.fErrorMode === EErrorType.kERRORSPREAD)
1972+
return eprim;
19361973
// default case : fErrorMode = kERRORMEAN
19371974
// return standard error on the mean of y
19381975
return eprim/Math.sqrt(neff);

0 commit comments

Comments
 (0)