Skip to content

Commit 6fc4792

Browse files
committed
If there are too many hints - show at least best one
1 parent 8f38703 commit 6fc4792

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

scripts/JSRoot.core.js

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

105105
/** @summary JSROOT version date
106106
* @desc Release date in format day/month/year like "14/01/2021"*/
107-
JSROOT.version_date = "16/11/2021";
107+
JSROOT.version_date = "17/11/2021";
108108

109109
/** @summary JSROOT version id and date
110110
* @desc Produced by concatenation of {@link JSROOT.version_id} and {@link JSROOT.version_date}

scripts/JSRoot.interactive.js

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ JSROOT.define(['d3', 'painter'], (d3, jsrp) => {
4141
}
4242
}
4343

44-
let hints = [], nhints = 0, maxlen = 0, lastcolor1 = 0, usecolor1 = false,
44+
let hints = [], nhints = 0, nexact = 0, maxlen = 0, lastcolor1 = 0, usecolor1 = false,
4545
textheight = 11, hmargin = 3, wmargin = 3, hstep = 1.2,
4646
frame_rect = this.getFrameRect(),
4747
pp = this.getPadPainter(),
@@ -79,6 +79,8 @@ JSROOT.define(['d3', 'painter'], (d3, jsrp) => {
7979
if (!hints[n]) continue;
8080

8181
nhints++;
82+
83+
if (hint.exact) nexact++;
8284

8385
for (let l = 0; l < hint.lines.length; ++l)
8486
maxlen = Math.max(maxlen, hint.lines[l].length);
@@ -92,16 +94,18 @@ JSROOT.define(['d3', 'painter'], (d3, jsrp) => {
9294
}
9395

9496
let layer = this.hints_layer(),
95-
hintsg = layer.select(".objects_hints"); // group with all tooltips
96-
97-
let title = "", name = "", info = "",
98-
hint = null, best_dist2 = 1e10, best_hint = null,
99-
coordinates = pnt ? Math.round(pnt.x) + "," + Math.round(pnt.y) : "";
97+
hintsg = layer.select(".objects_hints"), // group with all tooltips
98+
title = "", name = "", info = "",
99+
hint = null, best_dist2 = 1e10, best_hint = null, show_only_best = nhints > 15,
100+
coordinates = pnt ? Math.round(pnt.x) + "," + Math.round(pnt.y) : "";
101+
100102
// try to select hint with exact match of the position when several hints available
101103
for (let k = 0; k < (hints ? hints.length : 0); ++k) {
102104
if (!hints[k]) continue;
103105
if (!hint) hint = hints[k];
104-
if (hints[k].exact && (!hint || !hint.exact)) { hint = hints[k]; break; }
106+
107+
// select exact hint if this is the only one
108+
if (hints[k].exact && (nexact < 2) && (!hint || !hint.exact)) { hint = hints[k]; break; }
105109

106110
if (!pnt || (hints[k].x === undefined) || (hints[k].y === undefined)) continue;
107111

@@ -119,9 +123,10 @@ JSROOT.define(['d3', 'painter'], (d3, jsrp) => {
119123
}
120124

121125
this.showObjectStatus(name, title, info, coordinates);
126+
122127

123128
// end of closing tooltips
124-
if (!pnt || disable_tootlips || (hints.length === 0) || (maxlen === 0) || (nhints > 15)) {
129+
if (!pnt || disable_tootlips || (hints.length === 0) || (maxlen === 0) || (show_only_best && !best_hint)) {
125130
hintsg.remove();
126131
return;
127132
}
@@ -148,13 +153,18 @@ JSROOT.define(['d3', 'painter'], (d3, jsrp) => {
148153
let viewmode = hintsg.property('viewmode') || "",
149154
actualw = 0, posx = pnt.x + frame_rect.hint_delta_x;
150155

151-
if (nhints > 1) {
156+
if (show_only_best || (nhints == 1)) {
157+
viewmode = "single";
158+
posx += 15;
159+
} else {
152160
// if there are many hints, place them left or right
153161

154162
let bleft = 0.5, bright = 0.5;
155163

156-
if (viewmode == "left") bright = 0.7; else
157-
if (viewmode == "right") bleft = 0.3;
164+
if (viewmode == "left")
165+
bright = 0.7;
166+
else if (viewmode == "right")
167+
bleft = 0.3;
158168

159169
if (posx <= bleft * frame_rect.width) {
160170
viewmode = "left";
@@ -165,21 +175,18 @@ JSROOT.define(['d3', 'painter'], (d3, jsrp) => {
165175
} else {
166176
posx = hintsg.property('startx');
167177
}
168-
} else {
169-
viewmode = "single";
170-
posx += 15;
171-
}
178+
}
172179

173180
if (viewmode !== hintsg.property('viewmode')) {
174181
hintsg.property('viewmode', viewmode);
175182
hintsg.selectAll("*").remove();
176183
}
177184

178185
let curry = 10, // normal y coordinate
179-
gapy = 10, // y coordinate, taking into account all gaps
180-
gapminx = -1111, gapmaxx = -1111,
181-
minhinty = -frame_shift.y,
182-
maxhinty = this.getCanvPainter().getPadHeight() - frame_rect.y - frame_shift.y;
186+
gapy = 10, // y coordinate, taking into account all gaps
187+
gapminx = -1111, gapmaxx = -1111,
188+
minhinty = -frame_shift.y,
189+
maxhinty = this.getCanvPainter().getPadHeight() - frame_rect.y - frame_shift.y;
183190

184191
function FindPosInGap(y) {
185192
for (let n = 0; (n < hints.length) && (y < maxhinty); ++n) {
@@ -196,11 +203,14 @@ JSROOT.define(['d3', 'painter'], (d3, jsrp) => {
196203
for (let n = 0; n < hints.length; ++n) {
197204
let hint = hints[n],
198205
group = hintsg.select(".painter_hint_" + n);
206+
207+
if (show_only_best && (hint !== best_hint)) hint = null;
208+
199209
if (hint === null) {
200210
group.remove();
201211
continue;
202212
}
203-
213+
204214
let was_empty = group.empty();
205215

206216
if (was_empty)
@@ -243,9 +253,10 @@ JSROOT.define(['d3', 'painter'], (d3, jsrp) => {
243253

244254
if (nhints > 1) {
245255
let col = usecolor1 ? hint.color1 : hint.color2;
246-
if ((col !== undefined) && (col !== 'none'))
247-
r.attr("stroke", col).attr("stroke-width", hint.exact ? 3 : 1);
256+
if (col && (col !== 'none'))
257+
r.attr("stroke", col);
248258
}
259+
r.attr("stroke-width", hint.exact ? 3 : 1);
249260

250261
for (let l = 0; l < (hint.lines ? hint.lines.length : 0); l++)
251262
if (hint.lines[l] !== null) {

0 commit comments

Comments
 (0)