Skip to content

Commit 311f08a

Browse files
committed
Use promise in th3 scatter drawing
1 parent 839065c commit 311f08a

File tree

1 file changed

+94
-82
lines changed

1 file changed

+94
-82
lines changed

scripts/JSRoot.hist3d.js

Lines changed: 94 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,8 @@ JSROOT.define(['d3', 'painter', 'base3d', 'latex', 'hist'], (d3, jsrp, THREE, lt
24642464
k2 = this.getSelectIndex("z", "right", 0),
24652465
i, j, k, bin_content;
24662466

2467-
if ((i2<=i1) || (j2<=j1) || (k2<=k1)) return true;
2467+
if ((i2<=i1) || (j2<=j1) || (k2<=k1))
2468+
return Promise.resolve(true);
24682469

24692470
// scale down factor if too large values
24702471
let coef = (this.gmaxbin > 1000) ? 1000/this.gmaxbin : 1,
@@ -2482,7 +2483,8 @@ JSROOT.define(['d3', 'painter', 'base3d', 'latex', 'hist'], (d3, jsrp, THREE, lt
24822483
}
24832484

24842485
// too many pixels - use box drawing
2485-
if (numpixels > (main.webgl ? 100000 : 30000)) return false;
2486+
if (numpixels > (main.webgl ? 100000 : 30000))
2487+
return false;
24862488

24872489
JSROOT.seed(sumz);
24882490

@@ -2510,49 +2512,53 @@ JSROOT.define(['d3', 'painter', 'base3d', 'latex', 'hist'], (d3, jsrp, THREE, lt
25102512
}
25112513
}
25122514

2513-
let mesh = pnts.createPoints(this.getColor(histo.fMarkerColor));
2514-
main.toplevel.add(mesh);
2515-
2516-
mesh.bins = bins;
2517-
mesh.painter = this;
2518-
mesh.tip_color = (histo.fMarkerColor===3) ? 0xFF0000 : 0x00FF00;
2515+
return pnts.createPoints({ color: this.getColor(histo.fMarkerColor), promise: true }).then(mesh => {
2516+
main.toplevel.add(mesh);
25192517

2520-
mesh.tooltip = function(intersect) {
2521-
if (!Number.isInteger(intersect.index)) {
2522-
console.error('intersect.index not provided, check three.js version', THREE.REVISION, 'expected r127');
2523-
return null;
2524-
}
2518+
mesh.bins = bins;
2519+
mesh.painter = this;
2520+
mesh.tip_color = (histo.fMarkerColor===3) ? 0xFF0000 : 0x00FF00;
25252521

2526-
let indx = Math.floor(intersect.index / this.nvertex);
2527-
if ((indx<0) || (indx >= this.bins.length)) return null;
2522+
mesh.tooltip = function(intersect) {
2523+
if (!Number.isInteger(intersect.index)) {
2524+
console.error('intersect.index not provided, check three.js version', THREE.REVISION, 'expected r127');
2525+
return null;
2526+
}
25282527

2529-
let p = this.painter, histo = p.getHisto(),
2530-
main = p.getFramePainter(),
2531-
tip = p.get3DToolTip(this.bins[indx]);
2528+
let indx = Math.floor(intersect.index / this.nvertex);
2529+
if ((indx<0) || (indx >= this.bins.length)) return null;
25322530

2533-
tip.x1 = main.grx(histo.fXaxis.GetBinLowEdge(tip.ix));
2534-
tip.x2 = main.grx(histo.fXaxis.GetBinLowEdge(tip.ix+1));
2535-
tip.y1 = main.gry(histo.fYaxis.GetBinLowEdge(tip.iy));
2536-
tip.y2 = main.gry(histo.fYaxis.GetBinLowEdge(tip.iy+1));
2537-
tip.z1 = main.grz(histo.fZaxis.GetBinLowEdge(tip.iz));
2538-
tip.z2 = main.grz(histo.fZaxis.GetBinLowEdge(tip.iz+1));
2539-
tip.color = this.tip_color;
2540-
tip.opacity = 0.3;
2531+
let p = this.painter, histo = p.getHisto(),
2532+
main = p.getFramePainter(),
2533+
tip = p.get3DToolTip(this.bins[indx]);
2534+
2535+
tip.x1 = main.grx(histo.fXaxis.GetBinLowEdge(tip.ix));
2536+
tip.x2 = main.grx(histo.fXaxis.GetBinLowEdge(tip.ix+1));
2537+
tip.y1 = main.gry(histo.fYaxis.GetBinLowEdge(tip.iy));
2538+
tip.y2 = main.gry(histo.fYaxis.GetBinLowEdge(tip.iy+1));
2539+
tip.z1 = main.grz(histo.fZaxis.GetBinLowEdge(tip.iz));
2540+
tip.z2 = main.grz(histo.fZaxis.GetBinLowEdge(tip.iz+1));
2541+
tip.color = this.tip_color;
2542+
tip.opacity = 0.3;
25412543

2542-
return tip;
2543-
};
2544+
return tip;
2545+
};
25442546

2545-
return true;
2547+
return true;
2548+
});
25462549
}
25472550

25482551
/** @summary Drawing of 3D histogram
25492552
* @private */
25502553
TH3Painter.prototype.draw3DBins = function() {
25512554

2552-
if (!this.draw_content) return;
2555+
if (!this.draw_content)
2556+
Promise.resolve(false);
25532557

2554-
if (!this.options.Box && !this.options.GLBox && !this.options.GLColor && !this.options.Lego)
2555-
if (this.draw3DScatter()) return;
2558+
if (!this.options.Box && !this.options.GLBox && !this.options.GLColor && !this.options.Lego) {
2559+
let res = this.draw3DScatter();
2560+
if (res !== false) return res;
2561+
}
25562562

25572563
let rootcolor = this.getObject().fFillColor,
25582564
fillcolor = this.getColor(rootcolor),
@@ -2583,7 +2589,7 @@ JSROOT.define(['d3', 'painter', 'base3d', 'latex', 'hist'], (d3, jsrp, THREE, lt
25832589
single_bin_verts = new Float32Array(buffer_size);
25842590
single_bin_norms = new Float32Array(buffer_size);
25852591

2586-
for (let k=0;k<indx.length;++k) {
2592+
for (let k = 0; k < indx.length; ++k) {
25872593
let iii = indx[k]*3;
25882594
single_bin_verts[k*3] = pos[iii];
25892595
single_bin_verts[k*3+1] = pos[iii+1];
@@ -2847,12 +2853,17 @@ JSROOT.define(['d3', 'painter', 'base3d', 'latex', 'hist'], (d3, jsrp, THREE, lt
28472853
main.toplevel.add(lines);
28482854
}
28492855
}
2856+
2857+
return Promise.resolve(true);
28502858
}
28512859

2860+
/** @summary Redraw TH3 histogram
2861+
* @private */
28522862
TH3Painter.prototype.redraw = function(reason) {
28532863

28542864
let main = this.getFramePainter(), // who makes axis and 3D drawing
2855-
histo = this.getHisto();
2865+
histo = this.getHisto(),
2866+
promise = Promise.resolve(true);
28562867

28572868
if (reason == "resize") {
28582869

@@ -2864,13 +2875,14 @@ JSROOT.define(['d3', 'painter', 'base3d', 'latex', 'hist'], (d3, jsrp, THREE, lt
28642875
main.setAxesRanges(histo.fXaxis, this.xmin, this.xmax, histo.fYaxis, this.ymin, this.ymax, histo.fZaxis, this.zmin, this.zmax);
28652876
main.set3DOptions(this.options);
28662877
main.drawXYZ(main.toplevel, { zoom: JSROOT.settings.Zooming, ndim: 3 });
2867-
this.draw3DBins();
2868-
main.render3D();
2869-
this.updateStatWebCanvas();
2870-
main.addKeysHandler();
2878+
promise = this.draw3DBins().then(() => {
2879+
main.render3D();
2880+
this.updateStatWebCanvas();
2881+
main.addKeysHandler();
2882+
});
28712883
}
28722884

2873-
return this.drawHistTitle();
2885+
return promise.then(() => this.drawHistTitle());
28742886
}
28752887

28762888
/** @summary Fill pad toolbar with TH3-related functions
@@ -3320,7 +3332,6 @@ JSROOT.define(['d3', 'painter', 'base3d', 'latex', 'hist'], (d3, jsrp, THREE, lt
33203332
});
33213333

33223334
promises.push(pr);
3323-
33243335
}
33253336
}
33263337

@@ -3377,7 +3388,7 @@ JSROOT.define(['d3', 'painter', 'base3d', 'latex', 'hist'], (d3, jsrp, THREE, lt
33773388
index = new Int32Array(size),
33783389
select = 0, icnt = 0;
33793390

3380-
for (let i=0; i<poly.fP.length; i+=3) {
3391+
for (let i = 0; i < poly.fP.length; i += 3) {
33813392

33823393
if ((poly.fP[i] < fp.scale_xmin) || (poly.fP[i] > fp.scale_xmax) ||
33833394
(poly.fP[i+1] < fp.scale_ymin) || (poly.fP[i+1] > fp.scale_ymax) ||
@@ -3393,53 +3404,54 @@ JSROOT.define(['d3', 'painter', 'base3d', 'latex', 'hist'], (d3, jsrp, THREE, lt
33933404
pnts.addPoint(fp.grx(poly.fP[i]), fp.gry(poly.fP[i+1]), fp.grz(poly.fP[i+2]));
33943405
}
33953406

3396-
let mesh = pnts.createPoints({ color: this.getColor(poly.fMarkerColor),
3397-
style: poly.fMarkerStyle });
3407+
return pnts.createPoints({ color: this.getColor(poly.fMarkerColor), style: poly.fMarkerStyle, promise: true }).then(mesh => {
33983408

3399-
mesh.tip_color = (poly.fMarkerColor === 3) ? 0xFF0000 : 0x00FF00;
3400-
mesh.tip_name = poly.fName || "Poly3D";
3401-
mesh.poly = poly;
3402-
mesh.painter = fp;
3403-
mesh.scale0 = 0.7*pnts.scale;
3404-
mesh.index = index;
3409+
mesh.tip_color = (poly.fMarkerColor === 3) ? 0xFF0000 : 0x00FF00;
3410+
mesh.tip_name = poly.fName || "Poly3D";
3411+
mesh.poly = poly;
3412+
mesh.painter = fp;
3413+
mesh.scale0 = 0.7*pnts.scale;
3414+
mesh.index = index;
34053415

3406-
fp.toplevel.add(mesh);
3416+
fp.toplevel.add(mesh);
34073417

3408-
mesh.tooltip = function(intersect) {
3409-
if (!Number.isInteger(intersect.index)) {
3410-
console.error('intersect.index not provided, check three.js version', THREE.REVISION, 'expected r102');
3411-
return null;
3412-
}
3413-
let indx = Math.floor(intersect.index / this.nvertex);
3414-
if ((indx<0) || (indx >= this.index.length)) return null;
3415-
3416-
indx = this.index[indx];
3417-
3418-
let p = this.painter,
3419-
grx = p.grx(this.poly.fP[indx]),
3420-
gry = p.gry(this.poly.fP[indx+1]),
3421-
grz = p.grz(this.poly.fP[indx+2]);
3422-
3423-
return {
3424-
x1: grx - this.scale0,
3425-
x2: grx + this.scale0,
3426-
y1: gry - this.scale0,
3427-
y2: gry + this.scale0,
3428-
z1: grz - this.scale0,
3429-
z2: grz + this.scale0,
3430-
color: this.tip_color,
3431-
lines: [ this.tip_name,
3432-
"pnt: " + indx/3,
3433-
"x: " + p.axisAsText("x", this.poly.fP[indx]),
3434-
"y: " + p.axisAsText("y", this.poly.fP[indx+1]),
3435-
"z: " + p.axisAsText("z", this.poly.fP[indx+2])
3436-
]
3418+
mesh.tooltip = function(intersect) {
3419+
if (!Number.isInteger(intersect.index)) {
3420+
console.error('intersect.index not provided, check three.js version', THREE.REVISION, 'expected r102');
3421+
return null;
3422+
}
3423+
let indx = Math.floor(intersect.index / this.nvertex);
3424+
if ((indx<0) || (indx >= this.index.length)) return null;
3425+
3426+
indx = this.index[indx];
3427+
3428+
let p = this.painter,
3429+
grx = p.grx(this.poly.fP[indx]),
3430+
gry = p.gry(this.poly.fP[indx+1]),
3431+
grz = p.grz(this.poly.fP[indx+2]);
3432+
3433+
return {
3434+
x1: grx - this.scale0,
3435+
x2: grx + this.scale0,
3436+
y1: gry - this.scale0,
3437+
y2: gry + this.scale0,
3438+
z1: grz - this.scale0,
3439+
z2: grz + this.scale0,
3440+
color: this.tip_color,
3441+
lines: [ this.tip_name,
3442+
"pnt: " + indx/3,
3443+
"x: " + p.axisAsText("x", this.poly.fP[indx]),
3444+
"y: " + p.axisAsText("y", this.poly.fP[indx+1]),
3445+
"z: " + p.axisAsText("z", this.poly.fP[indx+2])
3446+
]
3447+
};
34373448
};
3438-
};
34393449

3440-
fp.render3D(100); // set timeout to be able draw other points
3450+
fp.render3D(100); // set timeout to be able draw other points
34413451

3442-
return Promise.resolve(this);
3452+
return this;
3453+
3454+
});
34433455
}
34443456

34453457
JSROOT.TH3Painter = TH3Painter;

0 commit comments

Comments
 (0)