Skip to content

Relayout edge case fixes #1494

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 2 commits into from
Mar 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/components/annotations/convert_coords.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var toLogRange = require('../../lib/to_log_range');
* same relayout call should override this conversion.
*/
module.exports = function convertCoords(gd, ax, newType, doExtra) {
ax = ax || {};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.. so that e.g. in relayout blank axis objects that pass the forgiving AX_NAME_PATTERN (which also matches zaxis? by the way) don't leave to exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @alexcjohnson ⤴️

Copy link
Collaborator

Choose a reason for hiding this comment

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

Man, if only I could turn back time and not use linearized coordinates on log axes...


var toLog = (newType === 'log') && (ax.type === 'linear'),
fromLog = (newType === 'linear') && (ax.type === 'log');

Expand Down
2 changes: 2 additions & 0 deletions src/components/images/convert_coords.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var toLogRange = require('../../lib/to_log_range');
* same relayout call should override this conversion.
*/
module.exports = function convertCoords(gd, ax, newType, doExtra) {
ax = ax || {};

var toLog = (newType === 'log') && (ax.type === 'linear'),
fromLog = (newType === 'linear') && (ax.type === 'log');

Expand Down
1 change: 1 addition & 0 deletions src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ proto.setConvert = function() {
for(var i = 0; i < 3; ++i) {
var ax = this.fullSceneLayout[axisProperties[i]];
Axes.setConvert(ax, this.fullLayout);
ax.setScale = Lib.noop;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This statement also appears in the 3d axis_defaults.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need it here to make margin relayout calls work.

I got carried away in #1431 where I 🔪 ed it. My mistake.

}
};

Expand Down
67 changes: 67 additions & 0 deletions test/jasmine/tests/gl_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var Drawing = require('@src/components/drawing');

var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var fail = require('../assets/fail_test');
var mouseEvent = require('../assets/mouse_event');
var selectButton = require('../assets/modebar_button');
var customMatchers = require('../assets/custom_matchers');
Expand Down Expand Up @@ -631,6 +632,72 @@ describe('Test gl3d drag and wheel interactions', function() {
});
});

describe('Test gl3d relayout calls', function() {
var gd;

beforeEach(function() {
gd = createGraphDiv();
});

afterEach(function() {
Plotly.purge(gd);
destroyGraphDiv();
});

it('should be able to adjust margins', function(done) {
var w = 500;
var h = 500;

function assertMargins(t, l, b, r) {
var div3d = document.getElementById('scene');
expect(parseFloat(div3d.style.top)).toEqual(t, 'top');
expect(parseFloat(div3d.style.left)).toEqual(l, 'left');
expect(h - parseFloat(div3d.style.height) - t).toEqual(b, 'bottom');
expect(w - parseFloat(div3d.style.width) - l).toEqual(r, 'right');
}

Plotly.newPlot(gd, [{
type: 'scatter3d',
x: [1, 2, 3],
y: [1, 2, 3],
z: [1, 2, 1]
}], {
width: w,
height: h
})
.then(function() {
assertMargins(100, 80, 80, 80);

return Plotly.relayout(gd, 'margin', {
l: 0, t: 0, r: 0, b: 0
});
})
.then(function() {
assertMargins(0, 0, 0, 0);
})
.catch(fail)
.then(done);
});

it('should skip root-level axis objects', function(done) {
Plotly.newPlot(gd, [{
type: 'scatter3d',
x: [1, 2, 3],
y: [1, 2, 3],
z: [1, 2, 1]
}])
.then(function() {
return Plotly.relayout(gd, {
xaxis: {},
yaxis: {},
zaxis: {}
});
})
.catch(fail)
.then(done);
});
});

describe('Test gl2d plots', function() {
var gd;

Expand Down
15 changes: 15 additions & 0 deletions test/jasmine/tests/plot_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,21 @@ describe('Test plot api', function() {
})
.then(done);
});

it('should skip empty axis objects', function(done) {
Plotly.plot(gd, [{
x: [1, 2, 3],
y: [1, 2, 1]
}], {
xaxis: { title: 'x title' },
yaxis: { title: 'y title' }
})
.then(function() {
return Plotly.relayout(gd, { zaxis: {} });
})
.catch(fail)
.then(done);
});
});

describe('Plotly.restyle', function() {
Expand Down