Skip to content

Commit 6abbfb2

Browse files
committed
use _inHover instead of !_isLegend for clarity
1 parent 0fccc8d commit 6abbfb2

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/components/fx/hover.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,7 @@ function createHoverText(hoverData, opts, gd) {
10451045
legendOpts.layer = container;
10461046

10471047
// Draw unified hover label
1048+
legendOpts._inHover = true;
10481049
legendDraw(gd, legendOpts);
10491050

10501051
// Position the hover

src/components/legend/draw.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,20 @@ module.exports = function draw(gd, opts) {
3030
// Check whether this is the main legend (ie. called without any opts)
3131
if(!opts) {
3232
opts = fullLayout.legend || {};
33-
opts._isLegend = true;
3433
layer = fullLayout._infolayer;
3534
} else {
3635
layer = opts.layer;
3736
clipId += '-hover';
3837
}
3938

39+
var inHover = !!opts._inHover;
40+
4041
if(!layer) return;
4142

4243
if(!gd._legendMouseDownTime) gd._legendMouseDownTime = 0;
4344

4445
var legendData;
45-
if(opts._isLegend) {
46+
if(!inHover) {
4647
if(!gd.calcdata) return;
4748
legendData = fullLayout.showlegend && getLegendData(gd.calcdata, opts);
4849
} else {
@@ -52,14 +53,14 @@ module.exports = function draw(gd, opts) {
5253

5354
var hiddenSlices = fullLayout.hiddenlabels || [];
5455

55-
if(opts._isLegend && (!fullLayout.showlegend || !legendData.length)) {
56+
if(!inHover && (!fullLayout.showlegend || !legendData.length)) {
5657
layer.selectAll('.legend').remove();
5758
fullLayout._topdefs.select('#' + clipId).remove();
5859
return Plots.autoMargin(gd, 'legend');
5960
}
6061

6162
var legend = Lib.ensureSingle(layer, 'g', 'legend', function(s) {
62-
if(opts._isLegend) s.attr('pointer-events', 'all');
63+
if(!inHover) s.attr('pointer-events', 'all');
6364
});
6465

6566
var clipPath = Lib.ensureSingleById(fullLayout._topdefs, 'clipPath', clipId, function(s) {
@@ -112,7 +113,7 @@ module.exports = function draw(gd, opts) {
112113
})
113114
.each(function() { d3.select(this).call(drawTexts, gd, opts); })
114115
.call(style, gd, opts)
115-
.each(function() { if(opts._isLegend) d3.select(this).call(setupTraceToggle, gd); });
116+
.each(function() { if(!inHover) d3.select(this).call(setupTraceToggle, gd); });
116117

117118
Lib.syncOrAsync([
118119
Plots.previousPromises,
@@ -121,15 +122,15 @@ module.exports = function draw(gd, opts) {
121122
// IF expandMargin return a Promise (which is truthy),
122123
// we're under a doAutoMargin redraw, so we don't have to
123124
// draw the remaining pieces below
124-
if(opts._isLegend && expandMargin(gd)) return;
125+
if(!inHover && expandMargin(gd)) return;
125126

126127
var gs = fullLayout._size;
127128
var bw = opts.borderwidth;
128129

129130
var lx = gs.l + gs.w * opts.x - FROM_TL[getXanchor(opts)] * opts._width;
130131
var ly = gs.t + gs.h * (1 - opts.y) - FROM_TL[getYanchor(opts)] * opts._effHeight;
131132

132-
if(opts._isLegend && fullLayout.margin.autoexpand) {
133+
if(!inHover && fullLayout.margin.autoexpand) {
133134
var lx0 = lx;
134135
var ly0 = ly;
135136

@@ -146,18 +147,18 @@ module.exports = function draw(gd, opts) {
146147

147148
// Set size and position of all the elements that make up a legend:
148149
// legend, background and border, scroll box and scroll bar as well as title
149-
if(opts._isLegend) Drawing.setTranslate(legend, lx, ly);
150+
if(!inHover) Drawing.setTranslate(legend, lx, ly);
150151

151152
// to be safe, remove previous listeners
152153
scrollBar.on('.drag', null);
153154
legend.on('wheel', null);
154155

155-
if(!opts._isLegend || opts._height <= opts._maxHeight || gd._context.staticPlot) {
156+
if(inHover || opts._height <= opts._maxHeight || gd._context.staticPlot) {
156157
// if scrollbar should not be shown.
157158
var height = opts._effHeight;
158159

159160
// if unified hover, let it be its full size
160-
if(!opts._isLegend) height = opts._height;
161+
if(inHover) height = opts._height;
161162

162163
bg.attr({
163164
width: opts._width - bw,
@@ -386,7 +387,7 @@ function drawTexts(g, gd, opts) {
386387
var trace = legendItem.trace;
387388
var isPieLike = Registry.traceIs(trace, 'pie-like');
388389
var traceIndex = trace.index;
389-
var isEditable = opts._isLegend && gd._context.edits.legendText && !isPieLike;
390+
var isEditable = !opts._inHover && gd._context.edits.legendText && !isPieLike;
390391
var maxNameLength = opts._maxNameLength;
391392

392393
var name;
@@ -491,15 +492,15 @@ function setupTraceToggle(g, gd) {
491492
}
492493

493494
function textLayout(s, g, gd, opts) {
494-
if(!opts._isLegend) s.attr('data-notex', true); // do not process MathJax for unified hover
495+
if(opts._inHover) s.attr('data-notex', true); // do not process MathJax for unified hover
495496
svgTextUtils.convertToTspans(s, gd, function() {
496497
computeTextDimensions(g, gd, opts);
497498
});
498499
}
499500

500501
function computeTextDimensions(g, gd, opts) {
501502
var legendItem = g.data()[0][0];
502-
if(opts._isLegend && legendItem && !legendItem.trace.showlegend) {
503+
if(!opts._inHover && legendItem && !legendItem.trace.showlegend) {
503504
g.remove();
504505
return;
505506
}

src/components/legend/get_legend_data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = function getLegendData(calcdata, opts) {
3636
var trace = cd0.trace;
3737
var lgroup = trace.legendgroup;
3838

39-
if(opts._isLegend && (!trace.visible || !trace.showlegend)) continue;
39+
if(!opts._inHover && (!trace.visible || !trace.showlegend)) continue;
4040

4141
if(Registry.traceIs(trace, 'pie-like')) {
4242
if(!slicesShown[lgroup]) slicesShown[lgroup] = {};

0 commit comments

Comments
 (0)