Skip to content

Commit 31e34fa

Browse files
committed
fix and 🔒 basePlotModules sorting
1 parent 6fd6919 commit 31e34fa

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

src/plots/sort_modules.js

+6-14
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,15 @@
88

99
'use strict';
1010

11-
function sortBasePlotModules(a, b) {
12-
var nameA = a.name;
13-
var nameB = b.name;
14-
15-
// always plot splom before cartesian (i.e. scattergl traces)
16-
if(nameB === 'splom' && nameA === 'cartesian') {
17-
return 1;
18-
}
11+
// always plot splom before cartesian (i.e. scattergl traces)
12+
function sortModules(a, b) {
13+
if(a === 'splom') return -1;
14+
if(b === 'splom') return 1;
1915
return 0;
2016
}
2117

22-
function sortModules(a, b) {
23-
// always plot splom before scattergl traces
24-
if(b === 'splom' && a === 'scattergl') {
25-
return 1;
26-
}
27-
return 0;
18+
function sortBasePlotModules(a, b) {
19+
return sortModules(a.name, b.name);
2820
}
2921

3022
module.exports = {

test/jasmine/tests/plots_test.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ describe('Test Plots', function() {
1313
'use strict';
1414

1515
describe('Plots.supplyDefaults', function() {
16-
1716
it('should not throw an error when gd is a plain object', function() {
1817
var height = 100,
1918
gd = {
@@ -154,6 +153,26 @@ describe('Test Plots', function() {
154153

155154
testSanitizeMarginsHasBeenCalledOnlyOnce(gd);
156155
});
156+
157+
it('should sort base plot modules on fullLayout object', function() {
158+
var gd = Lib.extendDeep({}, require('@mocks/plot_types.json'));
159+
gd.data.unshift({type: 'scattergl'});
160+
gd.data.push({type: 'splom'});
161+
162+
supplyAllDefaults(gd);
163+
var names = gd._fullLayout._basePlotModules.map(function(m) {
164+
return m.name;
165+
});
166+
167+
expect(names).toEqual([
168+
'splom',
169+
'cartesian',
170+
'gl3d',
171+
'geo',
172+
'pie',
173+
'ternary'
174+
]);
175+
});
157176
});
158177

159178
describe('Plots.supplyLayoutGlobalDefaults should', function() {

0 commit comments

Comments
 (0)