Skip to content

Commit

Permalink
modebar: do not display hover buttons when all traces are "noHover"
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinerg committed Jun 26, 2019
1 parent e6d8525 commit c796e57
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/components/modebar/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd, showSendToCloud) {
if(hasCartesian) {
hoverGroup = ['toggleSpikelines', 'hoverClosestCartesian', 'hoverCompareCartesian'];
}
if(hasNoHover(fullLayout)) {
hoverGroup = [];
}

if((hasCartesian || hasGL2D) && !allAxesFixed) {
zoomGroup = ['zoomIn2d', 'zoomOut2d', 'autoScale2d'];
Expand Down Expand Up @@ -216,6 +219,14 @@ function isSelectable(fullData) {
return selectable;
}

// check whether all plot modules in fullLayout are noHover
function hasNoHover(fullLayout) {
for(var i = 0; i < fullLayout._basePlotModules.length; i++) {
if(!Registry.traceIs(fullLayout._basePlotModules[i].name, 'noHover')) return false;
}
return true;
}

function appendButtonsToGroups(groups, buttons) {
if(buttons.length) {
if(Array.isArray(buttons[0])) {
Expand Down
30 changes: 30 additions & 0 deletions test/jasmine/tests/modebar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('ModeBar', function() {
_modebardiv: d3.select(getMockModeBarTree()),
_has: Plots._hasPlotType,
_subplots: {xaxis: xaxes || [], yaxis: yaxes || []},
_basePlotModules: [],
modebar: {
orientation: 'h',
bgcolor: 'rgba(255,255,255,0.7)',
Expand Down Expand Up @@ -719,6 +720,35 @@ describe('ModeBar', function() {
checkButtons(modeBar, buttons, 1);
});

it('creates mode bar without hover button when all traces are noHover', function() {
var buttons = getButtons([
['toImage']
]);

var gd = getMockGraphInfo();
gd._fullLayout._basePlotModules = [{ name: 'indicator' }];

manageModeBar(gd);
var modeBar = gd._fullLayout._modeBar;

checkButtons(modeBar, buttons, 1);
});

it('creates mode bar with hover button even in the presence of one noHover trace', function() {
var buttons = getButtons([
['toImage'],
['hoverClosestPie']
]);

var gd = getMockGraphInfo();
gd._fullLayout._basePlotModules = [{ name: 'indicator' }, {name: 'pie'}];

manageModeBar(gd);
var modeBar = gd._fullLayout._modeBar;

checkButtons(modeBar, buttons, 1);
});

it('throws an error if modeBarButtonsToRemove isn\'t an array', function() {
var gd = getMockGraphInfo();
gd._context.modeBarButtonsToRemove = 'not gonna work';
Expand Down

0 comments on commit c796e57

Please sign in to comment.