Skip to content

Commit fc08522

Browse files
committed
Fix - when draw histogram as markers or line
Due to optimization not all points may be visible. But at least show minimal and maximal value for each graphical point
1 parent 25b83b2 commit fc08522

File tree

1 file changed

+59
-50
lines changed

1 file changed

+59
-50
lines changed

scripts/JSRootPainter.hist.js

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3646,7 +3646,7 @@
36463646
xaxis = histo.fXaxis,
36473647
pthis = this,
36483648
res = "", lastbin = false,
3649-
startx, currx, curry, x, grx, y, gry, curry_min, curry_max, prevy, prevx, i, besti,
3649+
startx, currx, curry, x, grx, y, gry, curry_min, curry_max, prevy, prevx, i, bestimin, bestimax,
36503650
exclude_zero = !this.options.Zero,
36513651
show_errors = this.options.Error,
36523652
show_markers = this.options.Mark,
@@ -3721,6 +3721,56 @@
37213721

37223722
if (draw_any_but_hist) use_minmax = true;
37233723

3724+
function draw_bin(besti) {
3725+
bincont = histo.getBinContent(besti+1);
3726+
if (!exclude_zero || (bincont!==0)) {
3727+
mx1 = Math.round(pmain.grx(xaxis.GetBinLowEdge(besti+1)));
3728+
mx2 = Math.round(pmain.grx(xaxis.GetBinLowEdge(besti+2)));
3729+
midx = Math.round((mx1+mx2)/2);
3730+
my = Math.round(pmain.gry(bincont));
3731+
yerr1 = yerr2 = 20;
3732+
if (show_errors) {
3733+
binerr = histo.getBinError(besti+1);
3734+
yerr1 = Math.round(my - pmain.gry(bincont + binerr)); // up
3735+
yerr2 = Math.round(pmain.gry(bincont - binerr) - my); // down
3736+
}
3737+
3738+
if (show_text) {
3739+
var cont = text_profile ? histo.fBinEntries[besti+1] : bincont;
3740+
3741+
if (cont!==0) {
3742+
var lbl = (cont === Math.round(cont)) ? cont.toString() : JSROOT.FFormat(cont, JSROOT.gStyle.fPaintTextFormat);
3743+
3744+
if (text_angle)
3745+
pthis.DrawText({ align: 12, x: midx, y: Math.round(my - 2 - text_size/5), width: 0, height: 0, rotate: text_angle, text: lbl, color: text_col, latex: 0 });
3746+
else
3747+
pthis.DrawText({ align: 22, x: Math.round(mx1 + (mx2-mx1)*0.1), y: Math.round(my-2-text_size), width: Math.round((mx2-mx1)*0.8), height: text_size, text: lbl, color: text_col, latex: 0 });
3748+
}
3749+
}
3750+
3751+
if (show_line && (path_line !== null))
3752+
path_line += ((path_line.length===0) ? "M" : "L") + midx + "," + my;
3753+
3754+
if (draw_markers) {
3755+
if ((my >= -yerr1) && (my <= height + yerr2)) {
3756+
if (path_fill !== null)
3757+
path_fill += "M" + mx1 +","+(my-yerr1) +
3758+
"h" + (mx2-mx1) + "v" + (yerr1+yerr2+1) + "h-" + (mx2-mx1) + "z";
3759+
if (path_marker !== null)
3760+
path_marker += pthis.markeratt.create(midx, my);
3761+
if (path_err !== null) {
3762+
if (pthis.options.errorX > 0) {
3763+
var mmx1 = Math.round(midx - (mx2-mx1)*pthis.options.errorX),
3764+
mmx2 = Math.round(midx + (mx2-mx1)*pthis.options.errorX);
3765+
path_err += "M" + (mmx1+dend) +","+ my + endx + "h" + (mmx2-mmx1-2*dend) + endx;
3766+
}
3767+
path_err += "M" + midx +"," + (my-yerr1+dend) + endy + "v" + (yerr1+yerr2-2*dend) + endy;
3768+
}
3769+
}
3770+
}
3771+
}
3772+
}
3773+
37243774
for (i = left; i <= right; ++i) {
37253775

37263776
x = xaxis.GetBinLowEdge(i+1);
@@ -3739,65 +3789,24 @@
37393789
}
37403790

37413791
if (res.length === 0) {
3742-
besti = i;
3792+
bestimin = bestimax = i;
37433793
prevx = startx = currx = grx;
37443794
prevy = curry_min = curry_max = curry = gry;
37453795
res = "M"+currx+","+curry;
37463796
} else if (use_minmax) {
37473797
if ((grx === currx) && !lastbin) {
3748-
if (gry < curry_min) besti = i;
3798+
if (gry < curry_min) bestimax = i; else
3799+
if (gry > curry_max) bestimin = i;
3800+
37493801
curry_min = Math.min(curry_min, gry);
37503802
curry_max = Math.max(curry_max, gry);
37513803
curry = gry;
37523804
} else {
37533805

37543806
if (draw_any_but_hist) {
3755-
bincont = histo.getBinContent(besti+1);
3756-
if (!exclude_zero || (bincont!==0)) {
3757-
mx1 = Math.round(pmain.grx(xaxis.GetBinLowEdge(besti+1)));
3758-
mx2 = Math.round(pmain.grx(xaxis.GetBinLowEdge(besti+2)));
3759-
midx = Math.round((mx1+mx2)/2);
3760-
my = Math.round(pmain.gry(bincont));
3761-
yerr1 = yerr2 = 20;
3762-
if (show_errors) {
3763-
binerr = histo.getBinError(besti+1);
3764-
yerr1 = Math.round(my - pmain.gry(bincont + binerr)); // up
3765-
yerr2 = Math.round(pmain.gry(bincont - binerr) - my); // down
3766-
}
3767-
3768-
if (show_text) {
3769-
var cont = text_profile ? histo.fBinEntries[besti+1] : bincont;
3770-
3771-
if (cont!==0) {
3772-
var lbl = (cont === Math.round(cont)) ? cont.toString() : JSROOT.FFormat(cont, JSROOT.gStyle.fPaintTextFormat);
3773-
3774-
if (text_angle)
3775-
this.DrawText({ align: 12, x: midx, y: Math.round(my - 2 - text_size/5), width: 0, height: 0, rotate: text_angle, text: lbl, color: text_col, latex: 0 });
3776-
else
3777-
this.DrawText({ align: 22, x: Math.round(mx1 + (mx2-mx1)*0.1), y: Math.round(my-2-text_size), width: Math.round((mx2-mx1)*0.8), height: text_size, text: lbl, color: text_col, latex: 0 });
3778-
}
3779-
}
3780-
3781-
if (show_line && (path_line !== null))
3782-
path_line += ((path_line.length===0) ? "M" : "L") + midx + "," + my;
3783-
3784-
if (draw_markers) {
3785-
if ((my >= -yerr1) && (my <= height + yerr2)) {
3786-
if (path_fill !== null)
3787-
path_fill += "M" + mx1 +","+(my-yerr1) +
3788-
"h" + (mx2-mx1) + "v" + (yerr1+yerr2+1) + "h-" + (mx2-mx1) + "z";
3789-
if (path_marker !== null)
3790-
path_marker += this.markeratt.create(midx, my);
3791-
if (path_err !== null) {
3792-
if (this.options.errorX > 0) {
3793-
var mmx1 = Math.round(midx - (mx2-mx1)*this.options.errorX),
3794-
mmx2 = Math.round(midx + (mx2-mx1)*this.options.errorX);
3795-
path_err += "M" + (mmx1+dend) +","+ my + endx + "h" + (mmx2-mmx1-2*dend) + endx;
3796-
}
3797-
path_err += "M" + midx +"," + (my-yerr1+dend) + endy + "v" + (yerr1+yerr2-2*dend) + endy;
3798-
}
3799-
}
3800-
}
3807+
if (bestimin === bestimax) { draw_bin(bestimin); } else
3808+
if (bestimin < bestimax) { draw_bin(bestimin); draw_bin(bestimax); } else {
3809+
draw_bin(bestimax); draw_bin(bestimin);
38013810
}
38023811
}
38033812

@@ -3828,7 +3837,7 @@
38283837
if (lastbin && (prevx !== grx))
38293838
res += "h"+(grx-prevx);
38303839

3831-
besti = i;
3840+
bestimin = bestimax = i;
38323841
curry_min = curry_max = curry = gry;
38333842
currx = grx;
38343843
}

0 commit comments

Comments
 (0)