Skip to content

Commit c796e57

Browse files
committed
modebar: do not display hover buttons when all traces are "noHover"
1 parent e6d8525 commit c796e57

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Diff for: src/components/modebar/manage.js

+11
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd, showSendToCloud) {
146146
if(hasCartesian) {
147147
hoverGroup = ['toggleSpikelines', 'hoverClosestCartesian', 'hoverCompareCartesian'];
148148
}
149+
if(hasNoHover(fullLayout)) {
150+
hoverGroup = [];
151+
}
149152

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

222+
// check whether all plot modules in fullLayout are noHover
223+
function hasNoHover(fullLayout) {
224+
for(var i = 0; i < fullLayout._basePlotModules.length; i++) {
225+
if(!Registry.traceIs(fullLayout._basePlotModules[i].name, 'noHover')) return false;
226+
}
227+
return true;
228+
}
229+
219230
function appendButtonsToGroups(groups, buttons) {
220231
if(buttons.length) {
221232
if(Array.isArray(buttons[0])) {

Diff for: test/jasmine/tests/modebar_test.js

+30
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe('ModeBar', function() {
4141
_modebardiv: d3.select(getMockModeBarTree()),
4242
_has: Plots._hasPlotType,
4343
_subplots: {xaxis: xaxes || [], yaxis: yaxes || []},
44+
_basePlotModules: [],
4445
modebar: {
4546
orientation: 'h',
4647
bgcolor: 'rgba(255,255,255,0.7)',
@@ -719,6 +720,35 @@ describe('ModeBar', function() {
719720
checkButtons(modeBar, buttons, 1);
720721
});
721722

723+
it('creates mode bar without hover button when all traces are noHover', function() {
724+
var buttons = getButtons([
725+
['toImage']
726+
]);
727+
728+
var gd = getMockGraphInfo();
729+
gd._fullLayout._basePlotModules = [{ name: 'indicator' }];
730+
731+
manageModeBar(gd);
732+
var modeBar = gd._fullLayout._modeBar;
733+
734+
checkButtons(modeBar, buttons, 1);
735+
});
736+
737+
it('creates mode bar with hover button even in the presence of one noHover trace', function() {
738+
var buttons = getButtons([
739+
['toImage'],
740+
['hoverClosestPie']
741+
]);
742+
743+
var gd = getMockGraphInfo();
744+
gd._fullLayout._basePlotModules = [{ name: 'indicator' }, {name: 'pie'}];
745+
746+
manageModeBar(gd);
747+
var modeBar = gd._fullLayout._modeBar;
748+
749+
checkButtons(modeBar, buttons, 1);
750+
});
751+
722752
it('throws an error if modeBarButtonsToRemove isn\'t an array', function() {
723753
var gd = getMockGraphInfo();
724754
gd._context.modeBarButtonsToRemove = 'not gonna work';

0 commit comments

Comments
 (0)