Skip to content

Commit fe8f6d2

Browse files
committed
Use promises in v7 rh3 scatter plot
1 parent 311f08a commit fe8f6d2

File tree

1 file changed

+44
-43
lines changed

1 file changed

+44
-43
lines changed

scripts/JSRoot.v7hist3d.js

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,52 +2498,55 @@ JSROOT.define(['d3', 'base3d', 'painter', 'latex', 'v7hist'], (d3, THREE, jsrp,
24982498
}
24992499
}
25002500

2501-
let color = this.v7EvalColor("fill_color", "red");
2502-
let mesh = pnts.createPoints(color);
2503-
main.toplevel.add(mesh);
2504-
2505-
mesh.bins = bins;
2506-
mesh.painter = this;
2507-
mesh.tip_color = 0x00FF00;
2508-
2509-
mesh.tooltip = function(intersect) {
2510-
if (!Number.isInteger(intersect.index)) {
2511-
console.error('intersect.index not provided, check three.js version', THREE.REVISION, 'expected r127');
2512-
return null;
2513-
}
2501+
return pnts.createPoints({ color: this.v7EvalColor("fill_color", "red"), promise: true }).then(mesh => {
2502+
main.toplevel.add(mesh);
25142503

2515-
let indx = Math.floor(intersect.index / this.nvertex);
2516-
if ((indx<0) || (indx >= this.bins.length)) return null;
2504+
mesh.bins = bins;
2505+
mesh.painter = this;
2506+
mesh.tip_color = 0x00FF00;
25172507

2518-
let p = this.painter,
2519-
main = p.getFramePainter(),
2520-
tip = p.get3DToolTip(this.bins[indx]);
2508+
mesh.tooltip = function(intersect) {
2509+
if (!Number.isInteger(intersect.index)) {
2510+
console.error('intersect.index not provided, check three.js version', THREE.REVISION, 'expected r127');
2511+
return null;
2512+
}
25212513

2522-
tip.x1 = main.grx(p.getAxis("x").GetBinLowEdge(tip.ix));
2523-
tip.x2 = main.grx(p.getAxis("x").GetBinLowEdge(tip.ix+di));
2524-
tip.y1 = main.gry(p.getAxis("y").GetBinLowEdge(tip.iy));
2525-
tip.y2 = main.gry(p.getAxis("y").GetBinLowEdge(tip.iy+dj));
2526-
tip.z1 = main.grz(p.getAxis("z").GetBinLowEdge(tip.iz));
2527-
tip.z2 = main.grz(p.getAxis("z").GetBinLowEdge(tip.iz+dk));
2528-
tip.color = this.tip_color;
2529-
tip.opacity = 0.3;
2514+
let indx = Math.floor(intersect.index / this.nvertex);
2515+
if ((indx < 0) || (indx >= this.bins.length)) return null;
25302516

2531-
return tip;
2532-
};
2517+
let p = this.painter,
2518+
main = p.getFramePainter(),
2519+
tip = p.get3DToolTip(this.bins[indx]);
2520+
2521+
tip.x1 = main.grx(p.getAxis("x").GetBinLowEdge(tip.ix));
2522+
tip.x2 = main.grx(p.getAxis("x").GetBinLowEdge(tip.ix+di));
2523+
tip.y1 = main.gry(p.getAxis("y").GetBinLowEdge(tip.iy));
2524+
tip.y2 = main.gry(p.getAxis("y").GetBinLowEdge(tip.iy+dj));
2525+
tip.z1 = main.grz(p.getAxis("z").GetBinLowEdge(tip.iz));
2526+
tip.z2 = main.grz(p.getAxis("z").GetBinLowEdge(tip.iz+dk));
2527+
tip.color = this.tip_color;
2528+
tip.opacity = 0.3;
25332529

2534-
return true;
2530+
return tip;
2531+
};
2532+
2533+
return true;
2534+
});
25352535
}
25362536

25372537
/** @summary Drawing of 3D histogram
25382538
* @private */
25392539
RH3Painter.prototype.draw3DBins = function() {
25402540

2541-
if (!this.draw_content) return;
2541+
if (!this.draw_content)
2542+
return false;
25422543

25432544
let handle = this.prepareDraw({ only_indexes: true, extra: -0.5, right_extra: -1 });
25442545

2545-
if (this.options.Scatter)
2546-
if (this.draw3DScatter(handle)) return;
2546+
if (this.options.Scatter) {
2547+
let res = this.draw3DScatter(handle);
2548+
if (res !== false) return res;
2549+
}
25472550

25482551
let fillcolor = this.v7EvalColor("fill_color", "red"),
25492552
main = this.getFramePainter(),
@@ -2623,7 +2626,8 @@ JSROOT.define(['d3', 'base3d', 'painter', 'latex', 'v7hist'], (d3, THREE, jsrp,
26232626
this.createContour(main, palette);
26242627
}
26252628

2626-
if ((i2<=i1) || (j2<=j1) || (k2<=k1)) return;
2629+
if ((i2 <= i1) || (j2 <= j1) || (k2 <= k1))
2630+
return true;
26272631

26282632
let xaxis = this.getAxis("x"), yaxis = this.getAxis("y"), zaxis = this.getAxis("z"),
26292633
scalex = (main.grx(xaxis.GetBinCoord(i2)) - main.grx(xaxis.GetBinCoord(i1))) / (i2 - i1) * di,
@@ -2768,7 +2772,7 @@ JSROOT.define(['d3', 'base3d', 'painter', 'latex', 'v7hist'], (d3, THREE, jsrp,
27682772
}
27692773
}
27702774

2771-
for(let ncol=0;ncol<cols_size.length;++ncol) {
2775+
for (let ncol = 0; ncol < cols_size.length; ++ncol) {
27722776
if (!cols_size[ncol]) continue; // ignore dummy colors
27732777

27742778
let nseq = cols_sequence[ncol];
@@ -2860,15 +2864,12 @@ JSROOT.define(['d3', 'base3d', 'painter', 'latex', 'v7hist'], (d3, THREE, jsrp,
28602864
main.set3DOptions(this.options);
28612865
main.drawXYZ(main.toplevel, { zoom: JSROOT.settings.Zooming, ndim: 3 });
28622866

2863-
this.drawingBins(reason).then(() => {
2864-
// called when bins received from server, must be reentrant
2865-
2866-
let main = this.getFramePainter();
2867-
2868-
this.draw3DBins();
2869-
main.render3D();
2870-
main.addKeysHandler();
2871-
});
2867+
this.drawingBins(reason)
2868+
.then(() => this.draw3DBins()) // called when bins received from server, must be reentrant
2869+
.then(() => {
2870+
main.render3D();
2871+
main.addKeysHandler();
2872+
});
28722873
}
28732874

28742875
/** @summary Fill pad toolbar with RH3-related functions

0 commit comments

Comments
 (0)