Skip to content

Commit a12a22b

Browse files
committed
fix "axrange" edit under axis constraint
... by extracting correct prop "leaf" end index which is used to keep track of "altered ranges" which than lead to `flags.calc: true` under axis constraints. In the test added, the # of xgrid ended being the same before and after the relayout call.
1 parent a132b85 commit a12a22b

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/plot_api/plot_api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ function _relayout(gd, aobj) {
18061806
var plen = p.parts.length;
18071807
// p.parts may end with an index integer if the property is an array
18081808
var pend = plen - 1;
1809-
while(pend > 0 && typeof p.parts[plen - 1] !== 'string') { pend--; }
1809+
while(pend > 0 && typeof p.parts[pend] !== 'string') pend--;
18101810
// last property in chain (leaf node)
18111811
var pleaf = p.parts[pend];
18121812
// leaf plus immediate parent

test/jasmine/tests/cartesian_interact_test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,39 @@ describe('axis zoom/pan and main plot zoom', function() {
554554
.catch(failTest)
555555
.then(done);
556556
});
557+
558+
it('updates axis layout when the constraints require it', function(done) {
559+
function _assert(xGridCnt) {
560+
var xGrid = d3.select(gd).selectAll('.gridlayer > .x > path.xgrid');
561+
expect(xGrid.size()).toEqual(xGridCnt);
562+
}
563+
564+
Plotly.plot(gd, [{
565+
x: [1, 1.5, 0, -1.5, -1, -1.5, 0, 1.5, 1],
566+
y: [0, 1.5, 1, 1.5, 0, -1.5, -1, -1.5, 0],
567+
line: {shape: 'spline'}
568+
}], {
569+
xaxis: {constrain: 'domain'},
570+
yaxis: {scaleanchor: 'x'},
571+
width: 700,
572+
height: 500
573+
})
574+
.then(function() {
575+
_assert(2);
576+
577+
return Plotly.relayout(gd, {
578+
'xaxis.range[0]': 0,
579+
'xaxis.range[1]': 1,
580+
'yaxis.range[0]': 0,
581+
'yaxis.range[1]': 1
582+
});
583+
})
584+
.then(function() {
585+
_assert(1);
586+
})
587+
.catch(failTest)
588+
.then(done);
589+
});
557590
});
558591

559592
describe('Event data:', function() {

test/jasmine/tests/plot_api_test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,21 @@ describe('Test plot api', function() {
669669
destroyGraphDiv();
670670
});
671671
});
672+
673+
it('should trigger calc on axis range updates when constraints are present', function() {
674+
gd = mock({
675+
data: [{
676+
y: [1, 2, 1]
677+
}],
678+
layout: {
679+
xaxis: {constrain: 'domain'},
680+
yaxis: {scaleanchor: 'x'}
681+
}
682+
});
683+
684+
Plotly.relayout(gd, 'xaxis.range[0]', 0);
685+
expect(gd.calcdata).toBeUndefined();
686+
});
672687
});
673688

674689
describe('Plotly.restyle subroutines switchboard', function() {

0 commit comments

Comments
 (0)