Skip to content

Negate axis offset and then turn it into a string #2339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components/modebar/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ function handleDrag3d(gd, ev) {
layoutUpdate[sceneIds[i] + '.' + parts[1]] = val;
}

// for multi-type subplots
var val2d = (val === 'pan') ? val : 'zoom';
layoutUpdate.dragmode = val2d;

Plotly.relayout(gd, layoutUpdate);
}

Expand Down
91 changes: 55 additions & 36 deletions src/components/modebar/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
var hasTernary = fullLayout._has('ternary');
var hasMapbox = fullLayout._has('mapbox');
var hasPolar = fullLayout._has('polar');
var allAxesFixed = areAllAxesFixed(fullLayout);

var groups = [];

function addGroup(newGroup) {
if(!newGroup.length) return;

var out = [];

for(var i = 0; i < newGroup.length; i++) {
Expand All @@ -100,55 +103,71 @@ function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
// buttons common to all plot types
addGroup(['toImage', 'sendDataToCloud']);

// graphs with more than one plot types get 'union buttons'
// which reset the view or toggle hover labels across all subplots.
if((hasCartesian || hasGL2D || hasPie || hasTernary) + hasGeo + hasGL3D > 1) {
addGroup(['resetViews', 'toggleHover']);
return appendButtonsToGroups(groups, buttonsToAdd);
}
var zoomGroup = [];
var hoverGroup = [];
var resetGroup = [];
var dragModeGroup = [];

if(hasGL3D) {
addGroup(['zoom3d', 'pan3d', 'orbitRotation', 'tableRotation']);
addGroup(['resetCameraDefault3d', 'resetCameraLastSave3d']);
addGroup(['hoverClosest3d']);
if((hasCartesian || hasGL2D || hasPie || hasTernary) + hasGeo + hasGL3D + hasMapbox + hasPolar > 1) {
// graphs with more than one plot types get 'union buttons'
// which reset the view or toggle hover labels across all subplots.
hoverGroup = ['toggleHover'];
resetGroup = ['resetViews'];
}
else if(hasGeo) {
zoomGroup = ['zoomInGeo', 'zoomOutGeo'];
hoverGroup = ['hoverClosestGeo'];
resetGroup = ['resetGeo'];
}
else if(hasGL3D) {
hoverGroup = ['hoverClosest3d'];
resetGroup = ['resetCameraDefault3d', 'resetCameraLastSave3d'];
}
else if(hasMapbox) {
hoverGroup = ['toggleHover'];
resetGroup = ['resetViewMapbox'];
}
else if(hasGL2D) {
hoverGroup = ['hoverClosestGl2d'];
}
else if(hasPie) {
hoverGroup = ['hoverClosestPie'];
}
else { // hasPolar, hasTernary
// always show at least one hover icon.
hoverGroup = ['toggleHover'];
}
// if we have cartesian, allow switching between closest and compare
// regardless of what other types are on the plot, since they'll all
// just treat any truthy hovermode as 'closest'
if(hasCartesian) {
hoverGroup = ['toggleSpikelines', 'hoverClosestCartesian', 'hoverCompareCartesian'];
}

var allAxesFixed = areAllAxesFixed(fullLayout),
dragModeGroup = [];
if((hasCartesian || hasGL2D) && !allAxesFixed) {
zoomGroup = ['zoomIn2d', 'zoomOut2d', 'autoScale2d'];
if(resetGroup[0] !== 'resetViews') resetGroup = ['resetScale2d'];
}

if(((hasCartesian || hasGL2D) && !allAxesFixed) || hasTernary) {
if(hasGL3D) {
dragModeGroup = ['zoom3d', 'pan3d', 'orbitRotation', 'tableRotation'];
}
else if(((hasCartesian || hasGL2D) && !allAxesFixed) || hasTernary) {
dragModeGroup = ['zoom2d', 'pan2d'];
}
if(hasMapbox || hasGeo) {
else if(hasMapbox || hasGeo) {
dragModeGroup = ['pan2d'];
}
if(hasPolar) {
else if(hasPolar) {
dragModeGroup = ['zoom2d'];
}
if(isSelectable(fullData)) {
dragModeGroup.push('select2d');
dragModeGroup.push('lasso2d');
}
if(dragModeGroup.length) addGroup(dragModeGroup);

if((hasCartesian || hasGL2D) && !allAxesFixed && !hasTernary) {
addGroup(['zoomIn2d', 'zoomOut2d', 'autoScale2d', 'resetScale2d']);
dragModeGroup.push('select2d', 'lasso2d');
}

if(hasCartesian && hasPie) {
addGroup(['toggleHover']);
} else if(hasGL2D) {
addGroup(['hoverClosestGl2d']);
} else if(hasCartesian) {
addGroup(['toggleSpikelines', 'hoverClosestCartesian', 'hoverCompareCartesian']);
} else if(hasPie) {
addGroup(['hoverClosestPie']);
} else if(hasMapbox) {
addGroup(['resetViewMapbox', 'toggleHover']);
} else if(hasGeo) {
addGroup(['zoomInGeo', 'zoomOutGeo', 'resetGeo']);
addGroup(['hoverClosestGeo']);
}
addGroup(dragModeGroup);
addGroup(zoomGroup.concat(resetGroup));
addGroup(hoverGroup);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup. Looking good!


return appendButtonsToGroups(groups, buttonsToAdd);
}
Expand Down
8 changes: 4 additions & 4 deletions test/jasmine/tests/gl3d_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ describe('@gl Test gl3d modebar handlers', function() {

buttonZoom3d.click();
assertScenes(gd._fullLayout, 'dragmode', 'zoom');
expect(gd.layout.dragmode).toBe(undefined);
expect(gd.layout.dragmode).toBe('zoom'); // for multi-type subplots
expect(gd._fullLayout.dragmode).toBe('zoom');
expect(buttonTurntable.isActive()).toBe(false);
expect(buttonZoom3d.isActive()).toBe(true);
Expand All @@ -504,8 +504,8 @@ describe('@gl Test gl3d modebar handlers', function() {

buttonPan3d.click();
assertScenes(gd._fullLayout, 'dragmode', 'pan');
expect(gd.layout.dragmode).toBe(undefined);
expect(gd._fullLayout.dragmode).toBe('zoom');
expect(gd.layout.dragmode).toBe('pan'); // for multi-type subplots
expect(gd._fullLayout.dragmode).toBe('pan');
expect(buttonTurntable.isActive()).toBe(false);
expect(buttonPan3d.isActive()).toBe(true);

Expand All @@ -525,7 +525,7 @@ describe('@gl Test gl3d modebar handlers', function() {

buttonOrbit.click();
assertScenes(gd._fullLayout, 'dragmode', 'orbit');
expect(gd.layout.dragmode).toBe(undefined);
expect(gd.layout.dragmode).toBe('zoom'); // fallback for multi-type subplots
expect(gd._fullLayout.dragmode).toBe('zoom');
expect(buttonTurntable.isActive()).toBe(false);
expect(buttonOrbit.isActive()).toBe(true);
Expand Down
65 changes: 53 additions & 12 deletions test/jasmine/tests/modebar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ describe('ModeBar', function() {
expectedButtonCount += group.length;
});

expect(modeBar.hasButtons(buttons)).toBe(true, 'modeBar.hasButtons');
var actualButtons = modeBar.buttons.map(function(group) {
return group.map(function(button) { return button.name; }).join(', ');
}).join(' - ');

expect(modeBar.hasButtons(buttons)).toBe(true, 'modeBar.hasButtons: ' + actualButtons);
expect(countGroups(modeBar)).toBe(expectedGroupCount, 'correct group count');
expect(countButtons(modeBar)).toBe(expectedButtonCount, 'correct button count');
expect(countLogo(modeBar)).toBe(1, 'correct logo count');
Expand Down Expand Up @@ -323,7 +327,8 @@ describe('ModeBar', function() {
var buttons = getButtons([
['toImage', 'sendDataToCloud'],
['pan2d'],
['resetViewMapbox', 'toggleHover']
['resetViewMapbox'],
['toggleHover']
]);

var gd = getMockGraphInfo();
Expand All @@ -339,7 +344,8 @@ describe('ModeBar', function() {
var buttons = getButtons([
['toImage', 'sendDataToCloud'],
['pan2d', 'select2d', 'lasso2d'],
['resetViewMapbox', 'toggleHover']
['resetViewMapbox'],
['toggleHover']
]);

var gd = getMockGraphInfo();
Expand Down Expand Up @@ -393,7 +399,9 @@ describe('ModeBar', function() {
it('creates mode bar (cartesian + gl3d version)', function() {
var buttons = getButtons([
['toImage', 'sendDataToCloud'],
['resetViews', 'toggleHover']
['zoom3d', 'pan3d', 'orbitRotation', 'tableRotation'],
['resetViews'],
['toggleSpikelines', 'hoverClosestCartesian', 'hoverCompareCartesian']
]);

var gd = getMockGraphInfo();
Expand All @@ -405,14 +413,41 @@ describe('ModeBar', function() {
checkButtons(modeBar, buttons, 1);
});

it('creates mode bar (cartesian + geo version)', function() {
it('creates mode bar (cartesian + geo unselectable version)', function() {
var buttons = getButtons([
['toImage', 'sendDataToCloud'],
['resetViews', 'toggleHover']
['zoom2d', 'pan2d'],
['zoomIn2d', 'zoomOut2d', 'autoScale2d', 'resetViews'],
['toggleSpikelines', 'hoverClosestCartesian', 'hoverCompareCartesian']
]);

var gd = getMockGraphInfo();
var gd = getMockGraphInfo(['x'], ['y']);
gd._fullLayout._basePlotModules = [{ name: 'cartesian' }, { name: 'geo' }];
gd._fullLayout.xaxis = {fixedrange: false};

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

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

it('creates mode bar (cartesian + geo selectable version)', function() {
var buttons = getButtons([
['toImage', 'sendDataToCloud'],
['zoom2d', 'pan2d', 'select2d', 'lasso2d'],
['zoomIn2d', 'zoomOut2d', 'autoScale2d', 'resetViews'],
['toggleSpikelines', 'hoverClosestCartesian', 'hoverCompareCartesian']
]);

var gd = getMockGraphInfo(['x'], ['y']);
gd._fullLayout._basePlotModules = [{ name: 'cartesian' }, { name: 'geo' }];
gd._fullLayout.xaxis = {fixedrange: false};
gd._fullData = [{
type: 'scatter',
visible: true,
mode: 'markers',
_module: {selectPoints: true}
}];

manageModeBar(gd);
var modeBar = gd._fullLayout._modeBar;
Expand All @@ -425,7 +460,7 @@ describe('ModeBar', function() {
['toImage', 'sendDataToCloud'],
['zoom2d', 'pan2d', 'select2d', 'lasso2d'],
['zoomIn2d', 'zoomOut2d', 'autoScale2d', 'resetScale2d'],
['toggleHover']
['toggleSpikelines', 'hoverClosestCartesian', 'hoverCompareCartesian']
]);

var gd = getMockGraphInfo(['x'], ['y']);
Expand All @@ -447,7 +482,9 @@ describe('ModeBar', function() {
it('creates mode bar (gl3d + geo version)', function() {
var buttons = getButtons([
['toImage', 'sendDataToCloud'],
['resetViews', 'toggleHover']
['zoom3d', 'pan3d', 'orbitRotation', 'tableRotation'],
['resetViews'],
['toggleHover']
]);

var gd = getMockGraphInfo();
Expand All @@ -462,7 +499,8 @@ describe('ModeBar', function() {
it('creates mode bar (un-selectable ternary version)', function() {
var buttons = getButtons([
['toImage', 'sendDataToCloud'],
['zoom2d', 'pan2d']
['zoom2d', 'pan2d'],
['toggleHover']
]);

var gd = getMockGraphInfo();
Expand All @@ -477,7 +515,8 @@ describe('ModeBar', function() {
it('creates mode bar (selectable ternary version)', function() {
var buttons = getButtons([
['toImage', 'sendDataToCloud'],
['zoom2d', 'pan2d', 'select2d', 'lasso2d']
['zoom2d', 'pan2d', 'select2d', 'lasso2d'],
['toggleHover']
]);

var gd = getMockGraphInfo();
Expand Down Expand Up @@ -514,7 +553,9 @@ describe('ModeBar', function() {
it('creates mode bar (ternary + gl3d version)', function() {
var buttons = getButtons([
['toImage', 'sendDataToCloud'],
['resetViews', 'toggleHover']
['zoom3d', 'pan3d', 'orbitRotation', 'tableRotation'],
['resetViews'],
['toggleHover']
]);

var gd = getMockGraphInfo();
Expand Down