Skip to content

Commit 8cf8d51

Browse files
committed
test editType for attrs that affect axis length
also fix a bug with relayout of 2D arrays
1 parent 3875fcc commit 8cf8d51

File tree

4 files changed

+87
-38
lines changed

4 files changed

+87
-38
lines changed

src/components/grid/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var gridAttrs = {
5454
valType: 'info_array',
5555
freeLength: true,
5656
dimensions: 2,
57-
items: {valType: 'enumerated', values: [counterRegex('xy').toString(), '']},
57+
items: {valType: 'enumerated', values: [counterRegex('xy').toString(), ''], editType: 'plot'},
5858
role: 'info',
5959
editType: 'plot',
6060
description: [
@@ -69,7 +69,7 @@ var gridAttrs = {
6969
xaxes: {
7070
valType: 'info_array',
7171
freeLength: true,
72-
items: {valType: 'enumerated', values: [cartesianIdRegex.x.toString(), '']},
72+
items: {valType: 'enumerated', values: [cartesianIdRegex.x.toString(), ''], editType: 'plot'},
7373
role: 'info',
7474
editType: 'plot',
7575
description: [
@@ -83,7 +83,7 @@ var gridAttrs = {
8383
yaxes: {
8484
valType: 'info_array',
8585
freeLength: true,
86-
items: {valType: 'enumerated', values: [cartesianIdRegex.y.toString(), '']},
86+
items: {valType: 'enumerated', values: [cartesianIdRegex.y.toString(), ''], editType: 'plot'},
8787
role: 'info',
8888
editType: 'plot',
8989
description: [

src/plot_api/plot_api.js

+15-14
Original file line numberDiff line numberDiff line change
@@ -1857,20 +1857,21 @@ function _relayout(gd, aobj) {
18571857
throw new Error('cannot set ' + ai + 'and a parent attribute simultaneously');
18581858
}
18591859

1860-
var p = Lib.nestedProperty(layout, ai),
1861-
vi = aobj[ai],
1862-
plen = p.parts.length,
1863-
// p.parts may end with an index integer if the property is an array
1864-
pend = typeof p.parts[plen - 1] === 'string' ? (plen - 1) : (plen - 2),
1865-
// last property in chain (leaf node)
1866-
pleaf = p.parts[pend],
1867-
// leaf plus immediate parent
1868-
pleafPlus = p.parts[pend - 1] + '.' + pleaf,
1869-
// trunk nodes (everything except the leaf)
1870-
ptrunk = p.parts.slice(0, pend).join('.'),
1871-
parentIn = Lib.nestedProperty(gd.layout, ptrunk).get(),
1872-
parentFull = Lib.nestedProperty(fullLayout, ptrunk).get(),
1873-
vOld = p.get();
1860+
var p = Lib.nestedProperty(layout, ai);
1861+
var vi = aobj[ai];
1862+
var plen = p.parts.length;
1863+
// p.parts may end with an index integer if the property is an array
1864+
var pend = plen - 1;
1865+
while(pend > 0 && typeof p.parts[plen - 1] !== 'string') { pend--; }
1866+
// last property in chain (leaf node)
1867+
var pleaf = p.parts[pend];
1868+
// leaf plus immediate parent
1869+
var pleafPlus = p.parts[pend - 1] + '.' + pleaf;
1870+
// trunk nodes (everything except the leaf)
1871+
var ptrunk = p.parts.slice(0, pend).join('.');
1872+
var parentIn = Lib.nestedProperty(gd.layout, ptrunk).get();
1873+
var parentFull = Lib.nestedProperty(fullLayout, ptrunk).get();
1874+
var vOld = p.get();
18741875

18751876
if(vi === undefined) continue;
18761877

src/plots/domain.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ exports.attributes = function(opts, extra) {
4040
role: 'info',
4141
editType: opts.editType,
4242
items: [
43-
{valType: 'number', min: 0, max: 1},
44-
{valType: 'number', min: 0, max: 1}
43+
{valType: 'number', min: 0, max: 1, editType: opts.editType},
44+
{valType: 'number', min: 0, max: 1, editType: opts.editType}
4545
],
4646
dflt: [0, 1]
4747
};

test/jasmine/tests/plot_api_test.js

+67-19
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ describe('Test plot api', function() {
507507
'doCamera'
508508
];
509509

510+
var gd;
511+
510512
beforeAll(function() {
511513
mockedMethods.forEach(function(m) {
512514
spyOn(subroutines, m);
@@ -523,8 +525,20 @@ describe('Test plot api', function() {
523525
return gd;
524526
}
525527

528+
function expectModeBarOnly(msg) {
529+
expect(gd.calcdata).toBeDefined(msg);
530+
expect(subroutines.doModeBar.calls.count()).toBeGreaterThan(0, msg);
531+
expect(subroutines.layoutReplot.calls.count()).toBe(0, msg);
532+
}
533+
534+
function expectReplot(msg) {
535+
expect(gd.calcdata).toBeDefined(msg);
536+
expect(subroutines.doModeBar.calls.count()).toBe(0, msg);
537+
expect(subroutines.layoutReplot.calls.count()).toBeGreaterThan(0, msg);
538+
}
539+
526540
it('should trigger replot (but not recalc) when switching into select or lasso dragmode for scattergl traces', function() {
527-
var gd = mock({
541+
gd = mock({
528542
data: [{
529543
type: 'scattergl',
530544
x: [1, 2, 3],
@@ -535,35 +549,69 @@ describe('Test plot api', function() {
535549
}
536550
});
537551

538-
function expectModeBarOnly() {
539-
expect(gd.calcdata).toBeDefined();
540-
expect(subroutines.doModeBar).toHaveBeenCalled();
541-
expect(subroutines.layoutReplot).not.toHaveBeenCalled();
542-
}
543-
544-
function expectReplot() {
545-
expect(gd.calcdata).toBeDefined();
546-
expect(subroutines.doModeBar).not.toHaveBeenCalled();
547-
expect(subroutines.layoutReplot).toHaveBeenCalled();
548-
}
549-
550552
Plotly.relayout(gd, 'dragmode', 'pan');
551-
expectModeBarOnly();
553+
expectModeBarOnly('pan');
552554

553555
Plotly.relayout(mock(gd), 'dragmode', 'lasso');
554-
expectReplot();
556+
expectReplot('lasso 1');
555557

556558
Plotly.relayout(mock(gd), 'dragmode', 'select');
557-
expectModeBarOnly();
559+
expectModeBarOnly('select 1');
558560

559561
Plotly.relayout(mock(gd), 'dragmode', 'lasso');
560-
expectModeBarOnly();
562+
expectModeBarOnly('lasso 2');
561563

562564
Plotly.relayout(mock(gd), 'dragmode', 'zoom');
563-
expectModeBarOnly();
565+
expectModeBarOnly('zoom');
564566

565567
Plotly.relayout(mock(gd), 'dragmode', 'select');
566-
expectReplot();
568+
expectReplot('select 2');
569+
});
570+
571+
it('should trigger replot (but not recalc) when changing attributes that affect axis length/range', function() {
572+
// but axis.autorange itself is NOT here, because setting it from false to true requires an
573+
// autorange so that we calculate _min and _max, which we ignore if autorange is off.
574+
var axLayoutEdits = {
575+
'xaxis.rangemode': 'tozero',
576+
'xaxis.domain': [0.2, 0.8],
577+
'xaxis.domain[1]': 0.7,
578+
'yaxis.domain': [0.1, 0.9],
579+
'yaxis.domain[0]': 0.3,
580+
'yaxis.overlaying': 'y2',
581+
'margin.l': 50,
582+
'margin.r': 20,
583+
'margin.t': 1,
584+
'margin.b': 5,
585+
'margin.autoexpand': false,
586+
height: 567,
587+
width: 432,
588+
'grid.rows': 2,
589+
'grid.columns': 3,
590+
'grid.xgap': 0.5,
591+
'grid.ygap': 0,
592+
'grid.roworder': 'bottom to top',
593+
'grid.pattern': 'independent',
594+
'grid.yaxes': ['y2', 'y'],
595+
'grid.xaxes[0]': 'x2',
596+
'grid.domain': {x: [0, 0.4], y: [0.6, 1]},
597+
'grid.domain.x': [0.01, 0.99],
598+
'grid.domain.y[0]': 0.33,
599+
'grid.subplots': [['', 'xy'], ['x2y2', '']],
600+
'grid.subplots[1][1]': 'xy'
601+
};
602+
603+
for(var attr in axLayoutEdits) {
604+
gd = mock({
605+
data: [{y: [1, 2]}, {y: [4, 3], xaxis: 'x2', yaxis: 'y2'}],
606+
layout: {
607+
xaxis2: {domain: [0.6, 0.9]},
608+
yaxis2: {domain: [0.6, 0.9]}
609+
}
610+
});
611+
612+
Plotly.relayout(gd, attr, axLayoutEdits[attr]);
613+
expectReplot(attr);
614+
}
567615
});
568616
});
569617

0 commit comments

Comments
 (0)