Skip to content

Commit 923ec2e

Browse files
committed
add visible to legend
1 parent 76b6612 commit 923ec2e

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src/components/legend/attributes.js

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ module.exports = {
1010
// support yaxis, yaxis2, yaxis3, ... counters
1111
_isSubplotObj: true,
1212

13+
visible: {
14+
valType: 'boolean',
15+
dflt: true,
16+
editType: 'legend',
17+
description: [
18+
'Determines whether or not this legend is visible.'
19+
].join(' ')
20+
},
21+
1322
bgcolor: {
1423
valType: 'color',
1524
editType: 'legend',

src/components/legend/defaults.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ function groupDefaults(legendId, layoutIn, layoutOut, fullData) {
1717
return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
1818
}
1919

20+
// N.B. unified hover needs to inherit from font, bgcolor & bordercolor even when legend.visible is false
21+
var itemFont = Lib.coerceFont(coerce, 'font', layoutOut.font);
22+
coerce('bgcolor', layoutOut.paper_bgcolor);
23+
coerce('bordercolor');
24+
25+
var visible = coerce('visible');
26+
if(!visible) return;
27+
2028
var trace;
2129
var traceCoerce = function(attr, dflt) {
2230
var traceIn = trace._input;
@@ -90,10 +98,7 @@ function groupDefaults(legendId, layoutIn, layoutOut, fullData) {
9098

9199
if(showLegend === false) return;
92100

93-
coerce('bgcolor', layoutOut.paper_bgcolor);
94-
coerce('bordercolor');
95101
coerce('borderwidth');
96-
var itemFont = Lib.coerceFont(coerce, 'font', layoutOut.font);
97102

98103
var orientation = coerce('orientation');
99104
var isHorizontal = orientation === 'h';
@@ -164,7 +169,10 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
164169

165170
groupDefaults(legendId, layoutIn, layoutOut, fullData);
166171

167-
if(layoutOut[legendId]) {
172+
if(
173+
layoutOut[legendId] &&
174+
layoutOut[legendId].visible
175+
) {
168176
layoutOut[legendId]._id = legendId;
169177
}
170178

src/components/legend/get_legend_data.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = function getLegendData(calcdata, opts, hasMultipleLegends) {
1717
var i, j;
1818

1919
function addOneItem(legendId, legendGroup, legendItem) {
20+
if(opts.visible === false) return;
2021
if(hasMultipleLegends && legendId !== opts._id) return;
2122

2223
// each '' legend group is treated as a separate group

test/plot-schema.json

+6
Original file line numberDiff line numberDiff line change
@@ -2957,6 +2957,12 @@
29572957
"bottom"
29582958
]
29592959
},
2960+
"visible": {
2961+
"description": "Determines whether or not this legend is visible.",
2962+
"dflt": true,
2963+
"editType": "legend",
2964+
"valType": "boolean"
2965+
},
29602966
"x": {
29612967
"description": "Sets the x position (in normalized coordinates) of the legend. Defaults to *1.02* for vertical legends and defaults to *0* for horizontal legends.",
29622968
"editType": "legend",

0 commit comments

Comments
 (0)