Skip to content

Commit e6b05d9

Browse files
committed
Improve markers and error bars drawing for TH1/TProfile
In many cases it is better to draw all markers to clearly see distribution
1 parent 21bc297 commit e6b05d9

File tree

2 files changed

+54
-27
lines changed

2 files changed

+54
-27
lines changed

scripts/JSRootCore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696

9797
"use strict";
9898

99-
JSROOT.version = "dev 20/06/2018";
99+
JSROOT.version = "dev 2/07/2018";
100100

101101
JSROOT.source_dir = "";
102102
JSROOT.source_min = false;

scripts/JSRootPainter.hist.js

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3708,7 +3708,8 @@
37083708
show_text = this.options.Text,
37093709
text_profile = show_text && (this.options.TextKind == "E") && this.IsTProfile() && histo.fBinEntries,
37103710
path_fill = null, path_err = null, path_marker = null, path_line = null,
3711-
endx = "", endy = "", dend = 0, my, yerr1, yerr2, bincont, binerr, mx1, mx2, midx,
3711+
do_marker = false, do_err = false,
3712+
endx = "", endy = "", dend = 0, my, yerr1, yerr2, bincont, binerr, mx1, mx2, midx, mmx1, mmx2,
37123713
mpath = "", text_col, text_angle, text_size;
37133714

37143715
if (show_errors && !show_markers && (this.histo.fMarkerStyle > 1))
@@ -3717,8 +3718,10 @@
37173718
if (this.options.ErrorKind === 2) {
37183719
if (this.fillatt.empty()) show_markers = true;
37193720
else path_fill = "";
3720-
} else
3721-
if (this.options.Error) path_err = "";
3721+
} else if (this.options.Error) {
3722+
path_err = "";
3723+
do_err = true;
3724+
}
37223725

37233726
if (show_line) path_line = "";
37243727

@@ -3728,6 +3731,7 @@
37283731
if (this.markeratt.size > 0) {
37293732
// simply use relative move from point, can optimize in the future
37303733
path_marker = "";
3734+
do_marker = true;
37313735
this.markeratt.reset_pos();
37323736
} else {
37333737
show_markers = false;
@@ -3775,22 +3779,36 @@
37753779

37763780
if (draw_any_but_hist) use_minmax = true;
37773781

3778-
function draw_bin(besti) {
3779-
bincont = histo.getBinContent(besti+1);
3780-
if (!exclude_zero || (bincont!==0)) {
3781-
mx1 = Math.round(pmain.grx(xaxis.GetBinLowEdge(besti+1)));
3782-
mx2 = Math.round(pmain.grx(xaxis.GetBinLowEdge(besti+2)));
3783-
midx = Math.round((mx1+mx2)/2);
3784-
my = Math.round(pmain.gry(bincont));
3785-
yerr1 = yerr2 = 20;
3786-
if (show_errors) {
3787-
binerr = histo.getBinError(besti+1);
3788-
yerr1 = Math.round(my - pmain.gry(bincont + binerr)); // up
3789-
yerr2 = Math.round(pmain.gry(bincont - binerr) - my); // down
3790-
}
3782+
// just to get correct values for the specified bin
3783+
function extract_bin(bin) {
3784+
bincont = histo.getBinContent(bin+1);
3785+
if (exclude_zero && (bincont===0)) return false;
3786+
mx1 = Math.round(pmain.grx(xaxis.GetBinLowEdge(bin+1)));
3787+
mx2 = Math.round(pmain.grx(xaxis.GetBinLowEdge(bin+2)));
3788+
midx = Math.round((mx1+mx2)/2);
3789+
my = Math.round(pmain.gry(bincont));
3790+
yerr1 = yerr2 = 20;
3791+
if (show_errors) {
3792+
binerr = histo.getBinError(bin+1);
3793+
yerr1 = Math.round(my - pmain.gry(bincont + binerr)); // up
3794+
yerr2 = Math.round(pmain.gry(bincont - binerr) - my); // down
3795+
}
3796+
return true;
3797+
}
37913798

3799+
function draw_errbin(bin) {
3800+
if (pthis.options.errorX > 0) {
3801+
mmx1 = Math.round(midx - (mx2-mx1)*pthis.options.errorX);
3802+
mmx2 = Math.round(midx + (mx2-mx1)*pthis.options.errorX);
3803+
path_err += "M" + (mmx1+dend) +","+ my + endx + "h" + (mmx2-mmx1-2*dend) + endx;
3804+
}
3805+
path_err += "M" + midx +"," + (my-yerr1+dend) + endy + "v" + (yerr1+yerr2-2*dend) + endy;
3806+
}
3807+
3808+
function draw_bin(bin) {
3809+
if (extract_bin(bin)) {
37923810
if (show_text) {
3793-
var cont = text_profile ? histo.fBinEntries[besti+1] : bincont;
3811+
var cont = text_profile ? histo.fBinEntries[bin+1] : bincont;
37943812

37953813
if (cont!==0) {
37963814
var lbl = (cont === Math.round(cont)) ? cont.toString() : JSROOT.FFormat(cont, JSROOT.gStyle.fPaintTextFormat);
@@ -3810,21 +3828,30 @@
38103828
if (path_fill !== null)
38113829
path_fill += "M" + mx1 +","+(my-yerr1) +
38123830
"h" + (mx2-mx1) + "v" + (yerr1+yerr2+1) + "h-" + (mx2-mx1) + "z";
3813-
if (path_marker !== null)
3831+
if ((path_marker !== null) && do_marker)
38143832
path_marker += pthis.markeratt.create(midx, my);
3815-
if (path_err !== null) {
3816-
if (pthis.options.errorX > 0) {
3817-
var mmx1 = Math.round(midx - (mx2-mx1)*pthis.options.errorX),
3818-
mmx2 = Math.round(midx + (mx2-mx1)*pthis.options.errorX);
3819-
path_err += "M" + (mmx1+dend) +","+ my + endx + "h" + (mmx2-mmx1-2*dend) + endx;
3820-
}
3821-
path_err += "M" + midx +"," + (my-yerr1+dend) + endy + "v" + (yerr1+yerr2-2*dend) + endy;
3822-
}
3833+
if ((path_err !== null) && do_err)
3834+
draw_errbin(bin);
38233835
}
38243836
}
38253837
}
38263838
}
38273839

3840+
// check if we should draw markers or error marks directly, skipping optimization
3841+
if (do_marker || do_err)
3842+
if (!JSROOT.gStyle.OptimizeDraw || ((right-left<50000) && (JSROOT.gStyle.OptimizeDraw==1))) {
3843+
for (i = left; i <= right; ++i) {
3844+
if (extract_bin(i)) {
3845+
if (path_marker !== null)
3846+
path_marker += pthis.markeratt.create(midx, my);
3847+
if (path_err !== null)
3848+
draw_errbin(i);
3849+
}
3850+
}
3851+
do_err = do_marker = false;
3852+
}
3853+
3854+
38283855
for (i = left; i <= right; ++i) {
38293856

38303857
x = xaxis.GetBinLowEdge(i+1);

0 commit comments

Comments
 (0)