Skip to content

Commit 0fccc8d

Browse files
committed
rename _main legend to _isLegend for clarity
1 parent ac6fef5 commit 0fccc8d

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/components/legend/draw.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ 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._main = true;
33+
opts._isLegend = true;
3434
layer = fullLayout._infolayer;
3535
} else {
3636
layer = opts.layer;
@@ -42,7 +42,7 @@ module.exports = function draw(gd, opts) {
4242
if(!gd._legendMouseDownTime) gd._legendMouseDownTime = 0;
4343

4444
var legendData;
45-
if(opts._main) {
45+
if(opts._isLegend) {
4646
if(!gd.calcdata) return;
4747
legendData = fullLayout.showlegend && getLegendData(gd.calcdata, opts);
4848
} else {
@@ -52,14 +52,14 @@ module.exports = function draw(gd, opts) {
5252

5353
var hiddenSlices = fullLayout.hiddenlabels || [];
5454

55-
if(opts._main && (!fullLayout.showlegend || !legendData.length)) {
55+
if(opts._isLegend && (!fullLayout.showlegend || !legendData.length)) {
5656
layer.selectAll('.legend').remove();
5757
fullLayout._topdefs.select('#' + clipId).remove();
5858
return Plots.autoMargin(gd, 'legend');
5959
}
6060

6161
var legend = Lib.ensureSingle(layer, 'g', 'legend', function(s) {
62-
if(opts._main) s.attr('pointer-events', 'all');
62+
if(opts._isLegend) s.attr('pointer-events', 'all');
6363
});
6464

6565
var clipPath = Lib.ensureSingleById(fullLayout._topdefs, 'clipPath', clipId, function(s) {
@@ -112,7 +112,7 @@ module.exports = function draw(gd, opts) {
112112
})
113113
.each(function() { d3.select(this).call(drawTexts, gd, opts); })
114114
.call(style, gd, opts)
115-
.each(function() { if(opts._main) d3.select(this).call(setupTraceToggle, gd); });
115+
.each(function() { if(opts._isLegend) d3.select(this).call(setupTraceToggle, gd); });
116116

117117
Lib.syncOrAsync([
118118
Plots.previousPromises,
@@ -121,15 +121,15 @@ module.exports = function draw(gd, opts) {
121121
// IF expandMargin return a Promise (which is truthy),
122122
// we're under a doAutoMargin redraw, so we don't have to
123123
// draw the remaining pieces below
124-
if(opts._main && expandMargin(gd)) return;
124+
if(opts._isLegend && expandMargin(gd)) return;
125125

126126
var gs = fullLayout._size;
127127
var bw = opts.borderwidth;
128128

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

132-
if(opts._main && fullLayout.margin.autoexpand) {
132+
if(opts._isLegend && fullLayout.margin.autoexpand) {
133133
var lx0 = lx;
134134
var ly0 = ly;
135135

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

147147
// Set size and position of all the elements that make up a legend:
148148
// legend, background and border, scroll box and scroll bar as well as title
149-
if(opts._main) Drawing.setTranslate(legend, lx, ly);
149+
if(opts._isLegend) Drawing.setTranslate(legend, lx, ly);
150150

151151
// to be safe, remove previous listeners
152152
scrollBar.on('.drag', null);
153153
legend.on('wheel', null);
154154

155-
if(!opts._main || opts._height <= opts._maxHeight || gd._context.staticPlot) {
155+
if(!opts._isLegend || opts._height <= opts._maxHeight || gd._context.staticPlot) {
156156
// if scrollbar should not be shown.
157157
var height = opts._effHeight;
158158

159-
// if not the main legend, let it be its full size
160-
if(!opts._main) height = opts._height;
159+
// if unified hover, let it be its full size
160+
if(!opts._isLegend) height = opts._height;
161161

162162
bg.attr({
163163
width: opts._width - bw,
@@ -386,7 +386,7 @@ function drawTexts(g, gd, opts) {
386386
var trace = legendItem.trace;
387387
var isPieLike = Registry.traceIs(trace, 'pie-like');
388388
var traceIndex = trace.index;
389-
var isEditable = opts._main && gd._context.edits.legendText && !isPieLike;
389+
var isEditable = opts._isLegend && gd._context.edits.legendText && !isPieLike;
390390
var maxNameLength = opts._maxNameLength;
391391

392392
var name;
@@ -491,15 +491,15 @@ function setupTraceToggle(g, gd) {
491491
}
492492

493493
function textLayout(s, g, gd, opts) {
494-
if(!opts._main) s.attr('data-notex', true); // do not process MathJax if not main
494+
if(!opts._isLegend) s.attr('data-notex', true); // do not process MathJax for unified hover
495495
svgTextUtils.convertToTspans(s, gd, function() {
496496
computeTextDimensions(g, gd, opts);
497497
});
498498
}
499499

500500
function computeTextDimensions(g, gd, opts) {
501501
var legendItem = g.data()[0][0];
502-
if(opts._main && legendItem && !legendItem.trace.showlegend) {
502+
if(opts._isLegend && legendItem && !legendItem.trace.showlegend) {
503503
g.remove();
504504
return;
505505
}

src/components/legend/get_legend_data.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module.exports = function getLegendData(calcdata, opts) {
1111
var lgroupi = 0;
1212
var maxNameLength = 0;
1313
var i, j;
14-
var main = opts._main;
1514

1615
function addOneItem(legendGroup, legendItem) {
1716
// each '' legend group is treated as a separate group
@@ -37,7 +36,7 @@ module.exports = function getLegendData(calcdata, opts) {
3736
var trace = cd0.trace;
3837
var lgroup = trace.legendgroup;
3938

40-
if(main && (!trace.visible || !trace.showlegend)) continue;
39+
if(opts._isLegend && (!trace.visible || !trace.showlegend)) continue;
4140

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

0 commit comments

Comments
 (0)