Skip to content

Axis constraints #1522

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 16 commits into from
Apr 3, 2017
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
2 changes: 2 additions & 0 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,8 @@ function _relayout(gd, aobj) {
pp1 === 'type' ||
pp1 === 'domain' ||
pp1 === 'fixedrange' ||
pp1 === 'scaleanchor' ||
pp1 === 'scaleratio' ||
ai.indexOf('calendar') !== -1 ||
ai.match(/^(bar|box|font)/)) {
flags.docalc = true;
Expand Down
45 changes: 45 additions & 0 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var Axes = PlotlyInternal.Axes;

var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var customMatchers = require('../assets/custom_matchers');
var failTest = require('../assets/fail_test');


describe('Test axes', function() {
Expand Down Expand Up @@ -570,6 +572,49 @@ describe('Test axes', function() {
});
});

describe('constraints relayout', function() {
var gd;

beforeEach(function() {
gd = createGraphDiv();
jasmine.addMatchers(customMatchers);
});

afterEach(destroyGraphDiv);

it('updates ranges when adding, removing, or changing a constraint', function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice test 🎉

PlotlyInternal.plot(gd,
[{z: [[0, 1], [2, 3]], type: 'heatmap'}],
// plot area is 200x100 px
{width: 400, height: 300, margin: {l: 100, r: 100, t: 100, b: 100}}
)
.then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray([-0.5, 1.5], 5);
expect(gd.layout.yaxis.range).toBeCloseToArray([-0.5, 1.5], 5);

return PlotlyInternal.relayout(gd, {'xaxis.scaleanchor': 'y'});
})
.then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray([-1.5, 2.5], 5);
expect(gd.layout.yaxis.range).toBeCloseToArray([-0.5, 1.5], 5);

return PlotlyInternal.relayout(gd, {'xaxis.scaleratio': 10});
})
.then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray([-0.5, 1.5], 5);
expect(gd.layout.yaxis.range).toBeCloseToArray([-4.5, 5.5], 5);

return PlotlyInternal.relayout(gd, {'xaxis.scaleanchor': null});
})
.then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray([-0.5, 1.5], 5);
expect(gd.layout.yaxis.range).toBeCloseToArray([-0.5, 1.5], 5);
})
.catch(failTest)
.then(done);
});
});

describe('categoryorder', function() {

var gd;
Expand Down