Skip to content

Commit a9526bf

Browse files
committed
test fixin
1 parent 61f250c commit a9526bf

File tree

7 files changed

+46
-25
lines changed

7 files changed

+46
-25
lines changed

src/plot_api/manage_arrays.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,8 @@ exports.editContainerArray = function editContainerArray(gd, np, edits, flags) {
141141
}
142142

143143
var componentNums = Object.keys(edits).map(Number).sort(),
144-
componentArray = np.get();
145-
146-
if(!componentArray) {
147-
componentArray = [];
148-
np.set(componentArray);
149-
}
144+
componentArrayIn = np.get(),
145+
componentArray = componentArrayIn || [];
150146

151147
var deletes = [],
152148
firstIndexChange = -1,
@@ -206,6 +202,7 @@ exports.editContainerArray = function editContainerArray(gd, np, edits, flags) {
206202
}
207203

208204
if(!componentArray.length) np.set(null);
205+
else if(!componentArrayIn) np.set(componentArray);
209206

210207
if(replotLater) return false;
211208

src/plot_api/plot_api.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var svgTextUtils = require('../lib/svg_text_utils');
3131
var manageArrays = require('./manage_arrays');
3232
var helpers = require('./helpers');
3333
var subroutines = require('./subroutines');
34+
var cartesianConstants = require('../plots/cartesian/constants');
3435

3536

3637
/**
@@ -1950,6 +1951,17 @@ function _relayout(gd, aobj) {
19501951
doextra(ptrunk + '.autorange', true);
19511952
}
19521953
}
1954+
else if(pleaf.match(cartesianConstants.AX_NAME_PATTERN)) {
1955+
var fullProp = Lib.nestedProperty(fullLayout, ai).get(),
1956+
newType = (vi || {}).type;
1957+
1958+
// This can potentially cause strange behavior if the autotype is not
1959+
// numeric (linear, because we don't auto-log) but the previous type
1960+
// was log. That's a very strange edge case though
1961+
if(!newType || newType === '-') newType = 'linear';
1962+
Registry.getComponentMethod('annotations', 'convertCoords')(gd, fullProp, newType, doextra);
1963+
Registry.getComponentMethod('images', 'convertCoords')(gd, fullProp, newType, doextra);
1964+
}
19531965

19541966
// alter gd.layout
19551967

@@ -1967,7 +1979,7 @@ function _relayout(gd, aobj) {
19671979

19681980
if(i === '') {
19691981
// replacing the entire array: too much going on, force recalc
1970-
flags.docalc = true;
1982+
if(ai.indexOf('updatemenus') === -1) flags.docalc = true;
19711983
}
19721984
else if(propStr === '') {
19731985
// special handling of undoit if we're adding or removing an element
@@ -1982,12 +1994,13 @@ function _relayout(gd, aobj) {
19821994
}
19831995
else Lib.warn('unrecognized full object value', aobj);
19841996

1985-
if(refAutorange(toggledObj, 'x') || refAutorange(toggledObj, 'y')) {
1997+
if(refAutorange(toggledObj, 'x') || refAutorange(toggledObj, 'y') &&
1998+
ai.indexOf('updatemenus') === -1) {
19861999
flags.docalc = true;
19872000
}
19882001
}
19892002
else if((refAutorange(obji, 'x') || refAutorange(obji, 'y')) &&
1990-
!Lib.containsAny(ai, ['color', 'opacity', 'align', 'dash'])) {
2003+
!Lib.containsAny(ai, ['color', 'opacity', 'align', 'dash', 'updatemenus'])) {
19912004
flags.docalc = true;
19922005
}
19932006

test/jasmine/tests/command_test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,8 @@ describe('attaching component bindings', function() {
594594
expect(gd.layout.sliders[0].active).toBe(0);
595595

596596
// Check that it still has one attached listener:
597-
expect(typeof gd._internalEv._events.plotly_animatingframe).toBe('function');
597+
expect(typeof gd._internalEv._events.plotly_animatingframe).toBe('function',
598+
gd._internalEv._events.plotly_animatingframe);
598599

599600
// Change this to a non-simple binding:
600601
return Plotly.relayout(gd, {'sliders[0].steps[0].args[0]': 'line.color'});

test/jasmine/tests/layout_images_test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ describe('Layout images', function() {
328328

329329
Plotly.plot(gd, data, layout).then(function() {
330330
assertImages(0);
331+
expect(gd.layout.images).toBeUndefined();
331332

332333
return Plotly.relayout(gd, 'images[0]', makeImage(jsLogo, 0.1, 0.1));
333334
})
@@ -375,7 +376,7 @@ describe('Layout images', function() {
375376
})
376377
.then(function() {
377378
assertImages(0);
378-
expect(gd.layout.images).toEqual([]);
379+
expect(gd.layout.images).toBeUndefined();
379380

380381
done();
381382
});

test/jasmine/tests/mapbox_test.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -545,17 +545,22 @@ describe('mapbox plots', function() {
545545
return layerLen;
546546
}
547547

548+
function getLayerLength(gd) {
549+
return (gd.layout.mapbox.layers || []).length;
550+
}
551+
548552
function assertLayerStyle(gd, expectations, index) {
549553
var mapInfo = getMapInfo(gd),
550554
layers = mapInfo.layers,
551555
layerNames = mapInfo.layoutLayers;
552556

553557
var layer = layers[layerNames[index]];
558+
expect(layer).toBeDefined(layerNames[index]);
554559

555560
return new Promise(function(resolve) {
556561
setTimeout(function() {
557562
Object.keys(expectations).forEach(function(k) {
558-
expect(layer.paint[k]).toEqual(expectations[k]);
563+
expect(((layer || {}).paint || {})[k]).toEqual(expectations[k]);
559564
});
560565
resolve();
561566
}, TRANSITION_DELAY);
@@ -565,26 +570,26 @@ describe('mapbox plots', function() {
565570
expect(countVisibleLayers(gd)).toEqual(0);
566571

567572
Plotly.relayout(gd, 'mapbox.layers[0]', layer0).then(function() {
568-
expect(gd.layout.mapbox.layers.length).toEqual(1);
573+
expect(getLayerLength(gd)).toEqual(1);
569574
expect(countVisibleLayers(gd)).toEqual(1);
570575

571576
// add a new layer at the beginning
572577
return Plotly.relayout(gd, 'mapbox.layers[1]', layer1);
573578
})
574579
.then(function() {
575-
expect(gd.layout.mapbox.layers.length).toEqual(2);
580+
expect(getLayerLength(gd)).toEqual(2);
576581
expect(countVisibleLayers(gd)).toEqual(2);
577582

578583
return Plotly.relayout(gd, mapUpdate);
579584
})
580585
.then(function() {
581-
expect(gd.layout.mapbox.layers.length).toEqual(2);
586+
expect(getLayerLength(gd)).toEqual(2);
582587
expect(countVisibleLayers(gd)).toEqual(2);
583588

584589
return Plotly.relayout(gd, styleUpdate0);
585590
})
586591
.then(function() {
587-
expect(gd.layout.mapbox.layers.length).toEqual(2);
592+
expect(getLayerLength(gd)).toEqual(2);
588593
expect(countVisibleLayers(gd)).toEqual(2);
589594

590595
return assertLayerStyle(gd, {
@@ -594,13 +599,13 @@ describe('mapbox plots', function() {
594599
}, 0);
595600
})
596601
.then(function() {
597-
expect(gd.layout.mapbox.layers.length).toEqual(2);
602+
expect(getLayerLength(gd)).toEqual(2);
598603
expect(countVisibleLayers(gd)).toEqual(2);
599604

600605
return Plotly.relayout(gd, styleUpdate1);
601606
})
602607
.then(function() {
603-
expect(gd.layout.mapbox.layers.length).toEqual(2);
608+
expect(getLayerLength(gd)).toEqual(2);
604609
expect(countVisibleLayers(gd)).toEqual(2);
605610

606611
return assertLayerStyle(gd, {
@@ -610,20 +615,20 @@ describe('mapbox plots', function() {
610615
}, 1);
611616
})
612617
.then(function() {
613-
expect(gd.layout.mapbox.layers.length).toEqual(2);
618+
expect(getLayerLength(gd)).toEqual(2);
614619
expect(countVisibleLayers(gd)).toEqual(2);
615620

616621
// delete the first layer
617622
return Plotly.relayout(gd, 'mapbox.layers[0]', null);
618623
})
619624
.then(function() {
620-
expect(gd.layout.mapbox.layers.length).toEqual(1);
625+
expect(getLayerLength(gd)).toEqual(1);
621626
expect(countVisibleLayers(gd)).toEqual(1);
622627

623628
return Plotly.relayout(gd, 'mapbox.layers[0]', null);
624629
})
625630
.then(function() {
626-
expect(gd.layout.mapbox.layers).toBeUndefined();
631+
expect(getLayerLength(gd)).toEqual(0);
627632
expect(countVisibleLayers(gd)).toEqual(0);
628633

629634
return Plotly.relayout(gd, 'mapbox.layers[0]', {});
@@ -637,7 +642,7 @@ describe('mapbox plots', function() {
637642
return Plotly.relayout(gd, 'mapbox.layers[0].source', layer0.source);
638643
})
639644
.then(function() {
640-
expect(gd.layout.mapbox.layers.length).toEqual(1);
645+
expect(getLayerLength(gd)).toEqual(1);
641646
expect(countVisibleLayers(gd)).toEqual(1);
642647
})
643648
.catch(failTest)

test/jasmine/tests/plotschema_test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ describe('plot schema', function() {
204204
expect(plotSchema.defs.valObjects).toBeDefined();
205205

206206
expect(plotSchema.defs.metaKeys)
207-
.toEqual(['_isSubplotObj', '_isLinkedToArray', '_deprecated', 'description', 'role']);
207+
.toEqual([
208+
'_isSubplotObj', '_isLinkedToArray', '_arrayAttrRegexps',
209+
'_deprecated', 'description', 'role'
210+
]);
208211
});
209212

210213
it('should list the correct frame attributes', function() {

test/jasmine/tests/updatemenus_test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ describe('update menus interactions', function() {
315315
});
316316

317317
it('should draw only visible menus', function(done) {
318+
var initialUM1 = Lib.extendDeep({}, gd.layout.updatemenus[1]);
318319
assertMenus([0, 0]);
319320
expect(gd._fullLayout._pushmargin['updatemenu-0']).toBeDefined();
320321
expect(gd._fullLayout._pushmargin['updatemenu-1']).toBeDefined();
@@ -333,7 +334,7 @@ describe('update menus interactions', function() {
333334

334335
return Plotly.relayout(gd, {
335336
'updatemenus[0].visible': true,
336-
'updatemenus[1].visible': true
337+
'updatemenus[1]': initialUM1
337338
});
338339
})
339340
.then(function() {
@@ -655,7 +656,7 @@ describe('update menus interactions', function() {
655656
});
656657

657658
function assertNodeCount(query, cnt) {
658-
expect(d3.selectAll(query).size()).toEqual(cnt);
659+
expect(d3.selectAll(query).size()).toEqual(cnt, query);
659660
}
660661

661662
// call assertMenus([0, 3]); to check that the 2nd update menu is dropped

0 commit comments

Comments
 (0)