Skip to content

Commit 13831b2

Browse files
authored
Merge pull request #5682 from plotly/fix5679-hide-Aa-text
Do not show Aa text in legends unless there is only text in the legend item
2 parents 04b45eb + 10d1138 commit 13831b2

22 files changed

+63
-40
lines changed

src/components/legend/style.js

+59-33
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,16 @@ module.exports = function style(s, gd, legend) {
9595
.each(styleOHLC);
9696

9797
function styleLines(d) {
98+
var styleGuide = getStyleGuide(d);
99+
var showFill = styleGuide.showFill;
100+
var showLine = styleGuide.showLine;
101+
var showGradientLine = styleGuide.showGradientLine;
102+
var showGradientFill = styleGuide.showGradientFill;
103+
var anyFill = styleGuide.anyFill;
104+
var anyLine = styleGuide.anyLine;
105+
98106
var d0 = d[0];
99107
var trace = d0.trace;
100-
var showFill = trace.visible && trace.fill && trace.fill !== 'none';
101-
var showLine = subTypes.hasLines(trace);
102-
var contours = trace.contours;
103-
var showGradientLine = false;
104-
var showGradientFill = false;
105108
var dMod, tMod;
106109

107110
var cOpts = extractOpts(trace);
@@ -127,28 +130,10 @@ module.exports = function style(s, gd, legend) {
127130
}
128131
};
129132

130-
if(contours) {
131-
var coloring = contours.coloring;
132-
133-
if(coloring === 'lines') {
134-
showGradientLine = true;
135-
} else {
136-
showLine = coloring === 'none' || coloring === 'heatmap' || contours.showlines;
137-
}
138-
139-
if(contours.type === 'constraint') {
140-
showFill = contours._operation !== '=';
141-
} else if(coloring === 'fill' || coloring === 'heatmap') {
142-
showGradientFill = true;
143-
}
144-
}
145-
146133
// with fill and no markers or text, move the line and fill up a bit
147134
// so it's more centered
148-
var markersOrText = subTypes.hasMarkers(trace) || subTypes.hasText(trace);
149-
var anyFill = showFill || showGradientFill;
150-
var anyLine = showLine || showGradientLine;
151-
var pathStart = (markersOrText || !anyFill) ? 'M5,0' :
135+
136+
var pathStart = (subTypes.hasMarkers(trace) || !anyFill) ? 'M5,0' :
152137
// with a line leave it slightly below center, to leave room for the
153138
// line thickness and because the line is usually more prominent
154139
anyLine ? 'M5,-2' : 'M5,-3';
@@ -184,11 +169,15 @@ module.exports = function style(s, gd, legend) {
184169
}
185170

186171
function stylePoints(d) {
172+
var styleGuide = getStyleGuide(d);
173+
var anyFill = styleGuide.anyFill;
174+
var anyLine = styleGuide.anyLine;
175+
var showLine = styleGuide.showLine;
176+
var showMarker = styleGuide.showMarker;
177+
187178
var d0 = d[0];
188179
var trace = d0.trace;
189-
var showMarkers = subTypes.hasMarkers(trace);
190-
var showText = subTypes.hasText(trace);
191-
var showLines = subTypes.hasLines(trace);
180+
var showText = !showMarker && !anyLine && !anyFill && subTypes.hasText(trace);
192181
var dMod, tMod;
193182

194183
// 'scatter3d' don't use gd.calcdata,
@@ -217,11 +206,11 @@ module.exports = function style(s, gd, legend) {
217206
}
218207

219208
// constrain text, markers, etc so they'll fit on the legend
220-
if(showMarkers || showText || showLines) {
209+
if(showMarker || showText || showLine) {
221210
var dEdit = {};
222211
var tEdit = {};
223212

224-
if(showMarkers) {
213+
if(showMarker) {
225214
dEdit.mc = boundVal('marker.color', pickFirst);
226215
dEdit.mx = boundVal('marker.symbol', pickFirst);
227216
dEdit.mo = boundVal('marker.opacity', Lib.mean, [0.2, 1]);
@@ -238,7 +227,7 @@ module.exports = function style(s, gd, legend) {
238227
tEdit.marker.size = ms;
239228
}
240229

241-
if(showLines) {
230+
if(showLine) {
242231
tEdit.line = {
243232
width: boundVal('line.width', pickFirst, [0, 10], CST_LINE_WIDTH)
244233
};
@@ -265,7 +254,7 @@ module.exports = function style(s, gd, legend) {
265254
var ptgroup = d3.select(this).select('g.legendpoints');
266255

267256
var pts = ptgroup.selectAll('path.scatterpts')
268-
.data(showMarkers ? dMod : []);
257+
.data(showMarker ? dMod : []);
269258
// make sure marker is on the bottom, in case it enters after text
270259
pts.enter().insert('path', ':first-child')
271260
.classed('scatterpts', true)
@@ -275,7 +264,7 @@ module.exports = function style(s, gd, legend) {
275264

276265
// 'mrc' is set in pointStyle and used in textPointStyle:
277266
// constrain it here
278-
if(showMarkers) dMod[0].mrc = 3;
267+
if(showMarker) dMod[0].mrc = 3;
279268

280269
var txt = ptgroup.selectAll('g.pointtext')
281270
.data(showText ? dMod : []);
@@ -636,3 +625,40 @@ function getGradientDirection(reversescale, isRadial) {
636625
var str = isRadial ? 'radial' : 'horizontal';
637626
return str + (reversescale ? '' : 'reversed');
638627
}
628+
629+
function getStyleGuide(d) {
630+
var trace = d[0].trace;
631+
var contours = trace.contours;
632+
var showLine = subTypes.hasLines(trace);
633+
var showMarker = subTypes.hasMarkers(trace);
634+
635+
var showFill = trace.visible && trace.fill && trace.fill !== 'none';
636+
var showGradientLine = false;
637+
var showGradientFill = false;
638+
639+
if(contours) {
640+
var coloring = contours.coloring;
641+
642+
if(coloring === 'lines') {
643+
showGradientLine = true;
644+
} else {
645+
showLine = coloring === 'none' || coloring === 'heatmap' || contours.showlines;
646+
}
647+
648+
if(contours.type === 'constraint') {
649+
showFill = contours._operation !== '=';
650+
} else if(coloring === 'fill' || coloring === 'heatmap') {
651+
showGradientFill = true;
652+
}
653+
}
654+
655+
return {
656+
showMarker: showMarker,
657+
showLine: showLine,
658+
showFill: showFill,
659+
showGradientLine: showGradientLine,
660+
showGradientFill: showGradientFill,
661+
anyLine: showLine || showGradientLine,
662+
anyFill: showFill || showGradientFill,
663+
};
664+
}
-427 Bytes
Loading
-182 Bytes
Loading
-192 Bytes
Loading
-485 Bytes
Loading
-561 Bytes
Loading
Loading
-1008 Bytes
Loading
Loading
-286 Bytes
Loading
-150 Bytes
Loading

test/image/baselines/mathjax.png

38 Bytes
Loading
-394 Bytes
Loading
-503 Bytes
Loading
-536 Bytes
Loading
-865 Bytes
Loading

test/image/baselines/texttemplate.png

-264 Bytes
Loading

test/image/mocks/gl2d_text_chart_arrays.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
2,
5959
2
6060
],
61-
"mode": "lines+markers+text",
61+
"mode": "lines+text",
6262
"name": "Lines and Text",
6363
"text": [
6464
"Text G",

test/image/mocks/gl2d_text_chart_invalid-arrays.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
2,
5454
2
5555
],
56-
"mode": "lines+markers+text",
56+
"mode": "lines+text",
5757
"name": "Lines and Text",
5858
"text": [
5959
"Text G",

test/image/mocks/text_chart_arrays.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
2,
5959
2
6060
],
61-
"mode": "lines+markers+text",
61+
"mode": "lines+text",
6262
"name": "Lines and Text",
6363
"text": [
6464
"Text G",

test/image/mocks/text_chart_invalid-arrays.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
2,
5454
2
5555
],
56-
"mode": "lines+markers+text",
56+
"mode": "lines+text",
5757
"name": "Lines and Text",
5858
"text": [
5959
"Text G",

test/jasmine/tests/scatter_test.js

-3
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,6 @@ describe('end-to-end scatter tests', function() {
796796
var hasFills = name.indexOf('fill') !== -1;
797797
var hasLines = name.indexOf('lines') !== -1;
798798
var hasMarkers = name.indexOf('markers') !== -1;
799-
var hasText = name.indexOf('text') !== -1;
800799
var tracei, prefix;
801800

802801
// construct the expected ordering based on case name
@@ -814,7 +813,6 @@ describe('end-to-end scatter tests', function() {
814813
}
815814
if(hasLines) selectorArray.push(prefix + '.js-line');
816815
if(hasMarkers) selectorArray.push(prefix + '.point');
817-
if(hasText) selectorArray.push(prefix + '.textpoint');
818816
}
819817

820818
// ordering in the legend
@@ -823,7 +821,6 @@ describe('end-to-end scatter tests', function() {
823821
if(hasFills) selectorArray.push(prefix + '.js-fill');
824822
if(hasLines) selectorArray.push(prefix + '.js-line');
825823
if(hasMarkers) selectorArray.push(prefix + '.scatterpts');
826-
if(hasText) selectorArray.push(prefix + '.pointtext');
827824
}
828825

829826
var msg = i ? ('from ' + cases[indices[i - 1]].name + ' to ') : 'from default to ';

0 commit comments

Comments
 (0)