Skip to content

Commit 432d827

Browse files
authored
Merge pull request #1494 from plotly/relayout-fixes
Relayout edge case fixes
2 parents 3a672b8 + 28347ff commit 432d827

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

src/components/annotations/convert_coords.js

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ var toLogRange = require('../../lib/to_log_range');
2626
* same relayout call should override this conversion.
2727
*/
2828
module.exports = function convertCoords(gd, ax, newType, doExtra) {
29+
ax = ax || {};
30+
2931
var toLog = (newType === 'log') && (ax.type === 'linear'),
3032
fromLog = (newType === 'linear') && (ax.type === 'log');
3133

src/components/images/convert_coords.js

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ var toLogRange = require('../../lib/to_log_range');
3131
* same relayout call should override this conversion.
3232
*/
3333
module.exports = function convertCoords(gd, ax, newType, doExtra) {
34+
ax = ax || {};
35+
3436
var toLog = (newType === 'log') && (ax.type === 'linear'),
3537
fromLog = (newType === 'linear') && (ax.type === 'log');
3638

src/plots/gl3d/scene.js

+1
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ proto.setConvert = function() {
714714
for(var i = 0; i < 3; ++i) {
715715
var ax = this.fullSceneLayout[axisProperties[i]];
716716
Axes.setConvert(ax, this.fullLayout);
717+
ax.setScale = Lib.noop;
717718
}
718719
};
719720

test/jasmine/tests/gl_plot_interact_test.js

+67
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var Drawing = require('@src/components/drawing');
77

88
var createGraphDiv = require('../assets/create_graph_div');
99
var destroyGraphDiv = require('../assets/destroy_graph_div');
10+
var fail = require('../assets/fail_test');
1011
var mouseEvent = require('../assets/mouse_event');
1112
var selectButton = require('../assets/modebar_button');
1213
var customMatchers = require('../assets/custom_matchers');
@@ -631,6 +632,72 @@ describe('Test gl3d drag and wheel interactions', function() {
631632
});
632633
});
633634

635+
describe('Test gl3d relayout calls', function() {
636+
var gd;
637+
638+
beforeEach(function() {
639+
gd = createGraphDiv();
640+
});
641+
642+
afterEach(function() {
643+
Plotly.purge(gd);
644+
destroyGraphDiv();
645+
});
646+
647+
it('should be able to adjust margins', function(done) {
648+
var w = 500;
649+
var h = 500;
650+
651+
function assertMargins(t, l, b, r) {
652+
var div3d = document.getElementById('scene');
653+
expect(parseFloat(div3d.style.top)).toEqual(t, 'top');
654+
expect(parseFloat(div3d.style.left)).toEqual(l, 'left');
655+
expect(h - parseFloat(div3d.style.height) - t).toEqual(b, 'bottom');
656+
expect(w - parseFloat(div3d.style.width) - l).toEqual(r, 'right');
657+
}
658+
659+
Plotly.newPlot(gd, [{
660+
type: 'scatter3d',
661+
x: [1, 2, 3],
662+
y: [1, 2, 3],
663+
z: [1, 2, 1]
664+
}], {
665+
width: w,
666+
height: h
667+
})
668+
.then(function() {
669+
assertMargins(100, 80, 80, 80);
670+
671+
return Plotly.relayout(gd, 'margin', {
672+
l: 0, t: 0, r: 0, b: 0
673+
});
674+
})
675+
.then(function() {
676+
assertMargins(0, 0, 0, 0);
677+
})
678+
.catch(fail)
679+
.then(done);
680+
});
681+
682+
it('should skip root-level axis objects', function(done) {
683+
Plotly.newPlot(gd, [{
684+
type: 'scatter3d',
685+
x: [1, 2, 3],
686+
y: [1, 2, 3],
687+
z: [1, 2, 1]
688+
}])
689+
.then(function() {
690+
return Plotly.relayout(gd, {
691+
xaxis: {},
692+
yaxis: {},
693+
zaxis: {}
694+
});
695+
})
696+
.catch(fail)
697+
.then(done);
698+
});
699+
});
700+
634701
describe('Test gl2d plots', function() {
635702
var gd;
636703

test/jasmine/tests/plot_api_test.js

+15
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,21 @@ describe('Test plot api', function() {
237237
})
238238
.then(done);
239239
});
240+
241+
it('should skip empty axis objects', function(done) {
242+
Plotly.plot(gd, [{
243+
x: [1, 2, 3],
244+
y: [1, 2, 1]
245+
}], {
246+
xaxis: { title: 'x title' },
247+
yaxis: { title: 'y title' }
248+
})
249+
.then(function() {
250+
return Plotly.relayout(gd, { zaxis: {} });
251+
})
252+
.catch(fail)
253+
.then(done);
254+
});
240255
});
241256

242257
describe('Plotly.restyle', function() {

0 commit comments

Comments
 (0)