Skip to content

Commit 2f934ad

Browse files
committed
Only enable legend title click by default when there are multiple legends
1 parent 207910e commit 2f934ad

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/components/legend/attributes.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,25 +179,25 @@ module.exports = {
179179
titleclick: {
180180
valType: 'enumerated',
181181
values: ['toggle', 'toggleothers', false],
182-
dflt: 'toggle',
183182
editType: 'legend',
184183
description: [
185184
'Determines the behavior on legend title click.',
186185
'*toggle* toggles the visibility of all items in the legend.',
187186
'*toggleothers* toggles the visibility of all other legends.',
188-
'*false* disables legend title click interactions.'
187+
'*false* disables legend title click interactions.',
188+
'Defaults to *toggle* when there are multiple legends, *false* otherwise.'
189189
].join(' ')
190190
},
191191
titledoubleclick: {
192192
valType: 'enumerated',
193193
values: ['toggle', 'toggleothers', false],
194-
dflt: 'toggleothers',
195194
editType: 'legend',
196195
description: [
197196
'Determines the behavior on legend title double-click.',
198197
'*toggle* toggles the visibility of all items in the legend.',
199198
'*toggleothers* toggles the visibility of all other legends.',
200-
'*false* disables legend title double-click interactions.'
199+
'*false* disables legend title double-click interactions.',
200+
'Defaults to *toggleothers* when there are multiple legends, *false* otherwise.'
201201
].join(' ')
202202
},
203203
x: {

src/components/legend/defaults.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var attributes = require('./attributes');
99
var basePlotLayoutAttributes = require('../../plots/layout_attributes');
1010
var helpers = require('./helpers');
1111

12-
function groupDefaults(legendId, layoutIn, layoutOut, fullData) {
12+
function groupDefaults(legendId, layoutIn, layoutOut, fullData, legendCount) {
1313
var containerIn = layoutIn[legendId] || {};
1414
var containerOut = Template.newContainer(layoutOut, legendId);
1515

@@ -239,8 +239,9 @@ function groupDefaults(legendId, layoutIn, layoutOut, fullData) {
239239

240240
Lib.coerceFont(coerce, 'title.font', dfltTitleFont);
241241

242-
coerce('titleclick');
243-
coerce('titledoubleclick');
242+
var hasMultipleLegends = legendCount > 1;
243+
coerce('titleclick', hasMultipleLegends ? 'toggle' : false);
244+
coerce('titledoubleclick', hasMultipleLegends ? 'toggleothers' : false);
244245
}
245246
}
246247

@@ -280,7 +281,7 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
280281
for(i = 0; i < legends.length; i++) {
281282
var legendId = legends[i];
282283

283-
groupDefaults(legendId, layoutIn, layoutOut, allLegendsData);
284+
groupDefaults(legendId, layoutIn, layoutOut, allLegendsData, legends.length);
284285

285286
if(layoutOut[legendId]) {
286287
layoutOut[legendId]._id = legendId;

0 commit comments

Comments
 (0)