Skip to content

Commit 1197718

Browse files
authored
Disable chart legend interaction if interaction.enabled is set to false (#2791)
1 parent 59ca163 commit 1197718

1 file changed

Lines changed: 48 additions & 31 deletions

File tree

src/legend.js

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -366,38 +366,53 @@ ChartInternal.prototype.updateLegend = function(
366366
.style('visibility', function(id) {
367367
return $$.isLegendToShow(id) ? 'visible' : 'hidden'
368368
})
369-
.style('cursor', 'pointer')
370-
.on('click', function(id) {
371-
if (config.legend_item_onclick) {
372-
config.legend_item_onclick.call($$, id)
373-
} else {
374-
if ($$.d3.event.altKey) {
375-
$$.api.hide()
376-
$$.api.show(id)
377-
} else {
378-
$$.api.toggle(id)
379-
$$.isTargetToShow(id) ? $$.api.focus(id) : $$.api.revert()
380-
}
381-
}
382-
})
383-
.on('mouseover', function(id) {
384-
if (config.legend_item_onmouseover) {
385-
config.legend_item_onmouseover.call($$, id)
386-
} else {
387-
$$.d3.select(this).classed(CLASS.legendItemFocused, true)
388-
if (!$$.transiting && $$.isTargetToShow(id)) {
389-
$$.api.focus(id)
390-
}
391-
}
392-
})
393-
.on('mouseout', function(id) {
394-
if (config.legend_item_onmouseout) {
395-
config.legend_item_onmouseout.call($$, id)
396-
} else {
397-
$$.d3.select(this).classed(CLASS.legendItemFocused, false)
398-
$$.api.revert()
399-
}
369+
.style('cursor', function() {
370+
return config.interaction_enabled ? 'pointer' : 'auto'
400371
})
372+
.on('click',
373+
config.interaction_enabled
374+
? function(id) {
375+
if (config.legend_item_onclick) {
376+
config.legend_item_onclick.call($$, id)
377+
} else {
378+
if ($$.d3.event.altKey) {
379+
$$.api.hide()
380+
$$.api.show(id)
381+
} else {
382+
$$.api.toggle(id)
383+
$$.isTargetToShow(id) ? $$.api.focus(id) : $$.api.revert()
384+
}
385+
}
386+
}
387+
: null
388+
)
389+
.on('mouseover',
390+
config.interaction_enabled
391+
? function(id) {
392+
if (config.legend_item_onmouseover) {
393+
config.legend_item_onmouseover.call($$, id)
394+
} else {
395+
$$.d3.select(this).classed(CLASS.legendItemFocused, true)
396+
if (!$$.transiting && $$.isTargetToShow(id)) {
397+
$$.api.focus(id)
398+
}
399+
}
400+
}
401+
: null
402+
)
403+
.on('mouseout',
404+
config.interaction_enabled
405+
? function(id) {
406+
if (config.legend_item_onmouseout) {
407+
config.legend_item_onmouseout.call($$, id)
408+
} else {
409+
$$.d3.select(this).classed(CLASS.legendItemFocused, false)
410+
$$.api.revert()
411+
}
412+
}
413+
: null
414+
);
415+
401416
l.append('text')
402417
.text(function(id) {
403418
return isDefined(config.data_names[id]) ? config.data_names[id] : id
@@ -408,11 +423,13 @@ ChartInternal.prototype.updateLegend = function(
408423
.style('pointer-events', 'none')
409424
.attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200)
410425
.attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendText)
426+
411427
l.append('rect')
412428
.attr('class', CLASS.legendItemEvent)
413429
.style('fill-opacity', 0)
414430
.attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendRect : -200)
415431
.attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendRect)
432+
416433
l.append('line')
417434
.attr('class', CLASS.legendItemTile)
418435
.style('stroke', $$.color)

0 commit comments

Comments
 (0)