From 5b21ce75e68329f618da64d6004711f2a94d3a4a Mon Sep 17 00:00:00 2001 From: Sergey Linev Date: Wed, 18 Oct 2023 17:22:36 +0200 Subject: [PATCH] Build with pad.Divide and custom example --- build/jsroot.js | 97 +++++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 43 deletions(-) diff --git a/build/jsroot.js b/build/jsroot.js index 8f9ec5890..d1cd2a494 100644 --- a/build/jsroot.js +++ b/build/jsroot.js @@ -1621,6 +1621,54 @@ function getMethods(typename, obj) { }; } + if (typename === clTPad || typename === clTCanvas) { + m.Divide = function(nx, ny, xmargin = 0.01, ymargin = 0.01) { + if (!ny) { + const ndiv = nx; + if (ndiv < 2) return this; + nx = ny = Math.round(Math.sqrt(ndiv)); + if (nx * ny < ndiv) nx += 1; + } + if (nx*ny < 2) + return 0; + this.fPrimitives.Clear(); + const dy = 1/ny, dx = 1/nx; + let n = 0; + for (let iy = 0; iy < ny; iy++) { + const y2 = 1 - iy*dy - ymargin; + let y1 = y2 - dy + 2*ymargin; + if (y1 < 0) y1 = 0; + if (y1 > y2) continue; + for (let ix = 0; ix < nx; ix++) { + const x1 = ix*dx + xmargin, + x2 = x1 + dx -2*xmargin; + if (x1 > x2) continue; + n++; + const pad = create$1(clTPad); + pad.fName = pad.fTitle = `${this.fName}_${n}`; + pad.fNumber = n; + if (this._typename !== clTCanvas) { + pad.fAbsWNDC = (x2-x1) * this.fAbsWNDC; + pad.fAbsHNDC = (y2-y1) * this.fAbsHNDC; + pad.fAbsXlowNDC = this.fAbsXlowNDC + x1 * this.fAbsWNDC; + pad.fAbsYlowNDC = this.fAbsYlowNDC + y1 * this.fAbsWNDC; + } else { + pad.fAbsWNDC = x2 - x1; + pad.fAbsHNDC = y2 - y1; + pad.fAbsXlowNDC = x1; + pad.fAbsYlowNDC = y1; + } + + this.fPrimitives.Add(pad); + } + } + return nx * ny; + }; + m.GetPad = function(number) { + return this.fPrimitives.arr.find(elem => { return elem._typename === clTPad && elem.fNumber === number; }); + }; + } + if (typename.indexOf(clTProfile) === 0) { if (typename === clTProfile3D) { m.getBin = function(x, y, z) { return (x + (this.fXaxis.fNbins+2) * (y + (this.fYaxis.fNbins+2) * z)); }; @@ -66790,53 +66838,16 @@ class TPadPainter extends ObjectPainter { * @return {Promise} when finished * @private */ async divide(nx, ny) { - if (!ny) { - const ndiv = nx; - if (ndiv < 2) return this; - nx = ny = Math.round(Math.sqrt(ndiv)); - if (nx*ny < ndiv) nx += 1; - } - - if (nx*ny < 2) return this; - - const xmargin = 0.01, ymargin = 0.01, dy = 1/ny, dx = 1/nx, subpads = []; - let n = 0; - for (let iy = 0; iy < ny; iy++) { - const y2 = 1 - iy*dy - ymargin; - let y1 = y2 - dy + 2*ymargin; - if (y1 < 0) y1 = 0; - if (y1 > y2) continue; - for (let ix = 0; ix < nx; ix++) { - const x1 = ix*dx + xmargin, - x2 = x1 +dx -2*xmargin; - if (x1 > x2) continue; - n++; - const pad = create$1(clTPad); - pad.fName = pad.fTitle = `${this.pad.fName}_${n}`; - pad.fNumber = n; - if (!this.iscan) { - pad.fAbsWNDC = (x2-x1) * this.pad.fAbsWNDC; - pad.fAbsHNDC = (y2-y1) * this.pad.fAbsHNDC; - pad.fAbsXlowNDC = this.pad.fAbsXlowNDC + x1 * this.pad.fAbsWNDC; - pad.fAbsYlowNDC = this.pad.fAbsYlowNDC + y1 * this.pad.fAbsWNDC; - } else { - pad.fAbsWNDC = x2 - x1; - pad.fAbsHNDC = y2 - y1; - pad.fAbsXlowNDC = x1; - pad.fAbsYlowNDC = y1; - } - - subpads.push(pad); - } - } + if (!this.pad.Divide(nx, ny)) + return this; - const drawNext = () => { - if (subpads.length === 0) + const drawNext = indx => { + if (indx >= this.pad.fPrimitives.arr.length) return this; - return this.drawObject(this.getDom(), subpads.shift()).then(drawNext); + return this.drawObject(this.getDom(), this.pad.fPrimitives.arr[indx]).then(() => drawNext(indx + 1)); }; - return drawNext(); + return drawNext(0); } /** @summary Return sub-pads painter, only direct childs are checked