Skip to content

Commit

Permalink
Build with pad.Divide and custom example
Browse files Browse the repository at this point in the history
  • Loading branch information
linev committed Oct 18, 2023
1 parent 7f00b2d commit 5b21ce7
Showing 1 changed file with 54 additions and 43 deletions.
97 changes: 54 additions & 43 deletions build/jsroot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)); };
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5b21ce7

Please sign in to comment.