Skip to content

Commit ffd65fd

Browse files
committed
make sure scaleanchor/scaleratio changes trigger a recalc
1 parent 7fc9cbd commit ffd65fd

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/plot_api/plot_api.js

+2
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,8 @@ function _relayout(gd, aobj) {
21082108
pp1 === 'type' ||
21092109
pp1 === 'domain' ||
21102110
pp1 === 'fixedrange' ||
2111+
pp1 === 'scaleanchor' ||
2112+
pp1 === 'scaleratio' ||
21112113
ai.indexOf('calendar') !== -1 ||
21122114
ai.match(/^(bar|box|font)/)) {
21132115
flags.docalc = true;

test/jasmine/tests/axes_test.js

+45
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ var Axes = PlotlyInternal.Axes;
1010

1111
var createGraphDiv = require('../assets/create_graph_div');
1212
var destroyGraphDiv = require('../assets/destroy_graph_div');
13+
var customMatchers = require('../assets/custom_matchers');
14+
var failTest = require('../assets/fail_test');
1315

1416

1517
describe('Test axes', function() {
@@ -570,6 +572,49 @@ describe('Test axes', function() {
570572
});
571573
});
572574

575+
describe('constraints relayout', function() {
576+
var gd;
577+
578+
beforeEach(function() {
579+
gd = createGraphDiv();
580+
jasmine.addMatchers(customMatchers);
581+
});
582+
583+
afterEach(destroyGraphDiv);
584+
585+
it('updates ranges when adding, removing, or changing a constraint', function(done) {
586+
PlotlyInternal.plot(gd,
587+
[{z: [[0, 1], [2, 3]], type: 'heatmap'}],
588+
// plot area is 200x100 px
589+
{width: 400, height: 300, margin: {l: 100, r: 100, t: 100, b: 100}}
590+
)
591+
.then(function() {
592+
expect(gd.layout.xaxis.range).toBeCloseToArray([-0.5, 1.5], 5);
593+
expect(gd.layout.yaxis.range).toBeCloseToArray([-0.5, 1.5], 5);
594+
595+
return PlotlyInternal.relayout(gd, {'xaxis.scaleanchor': 'y'});
596+
})
597+
.then(function() {
598+
expect(gd.layout.xaxis.range).toBeCloseToArray([-1.5, 2.5], 5);
599+
expect(gd.layout.yaxis.range).toBeCloseToArray([-0.5, 1.5], 5);
600+
601+
return PlotlyInternal.relayout(gd, {'xaxis.scaleratio': 10});
602+
})
603+
.then(function() {
604+
expect(gd.layout.xaxis.range).toBeCloseToArray([-0.5, 1.5], 5);
605+
expect(gd.layout.yaxis.range).toBeCloseToArray([-4.5, 5.5], 5);
606+
607+
return PlotlyInternal.relayout(gd, {'xaxis.scaleanchor': null});
608+
})
609+
.then(function() {
610+
expect(gd.layout.xaxis.range).toBeCloseToArray([-0.5, 1.5], 5);
611+
expect(gd.layout.yaxis.range).toBeCloseToArray([-0.5, 1.5], 5);
612+
})
613+
.catch(failTest)
614+
.then(done);
615+
});
616+
});
617+
573618
describe('categoryorder', function() {
574619

575620
var gd;

0 commit comments

Comments
 (0)