Skip to content

Commit 811c874

Browse files
committed
condense axisid, sceneid, geoid to subplotid
1 parent 52a3b09 commit 811c874

File tree

5 files changed

+54
-46
lines changed

5 files changed

+54
-46
lines changed

src/lib/coerce.js

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var nestedProperty = require('./nested_property');
1616
var getColorscale = require('../components/colorscale/get_scale');
1717
var colorscaleNames = Object.keys(require('../components/colorscale/scales'));
1818

19+
var idRegex = /^([2-9]|[1-9][0-9]+)$/
1920

2021
exports.valObjects = {
2122
data_array: {
@@ -158,53 +159,20 @@ exports.valObjects = {
158159
}
159160
}
160161
},
161-
axisid: {
162+
subplotid: {
162163
description: [
163-
'An axis id string (e.g. \'x\', \'x2\', \'x3\', ...).'
164+
'An id string of a subplot type (given by dflt), optionally',
165+
'followed by an integer >1. e.g. if dflt=\'geo\', we can have',
166+
'\'geo\', \'geo2\', \'geo3\', ...'
164167
].join(' '),
165168
requiredOpts: [],
166169
otherOpts: ['dflt'],
167170
coerceFunction: function(v, propOut, dflt) {
168-
if(typeof v === 'string' && v.charAt(0)===dflt) {
169-
var axnum = Number(v.substr(1));
170-
if(axnum%1 === 0 && axnum>1) {
171-
propOut.set(v);
172-
return;
173-
}
174-
}
175-
propOut.set(dflt);
176-
}
177-
},
178-
sceneid: {
179-
description: [
180-
'A scene id string (e.g. \'scene\', \'scene2\', \'scene3\', ...).'
181-
].join(' '),
182-
requiredOpts: [],
183-
otherOpts: ['dflt'],
184-
coerceFunction: function(v, propOut, dflt) {
185-
if(typeof v === 'string' && v.substr(0,5)===dflt) {
186-
var scenenum = Number(v.substr(5));
187-
if(scenenum%1 === 0 && scenenum>1) {
188-
propOut.set(v);
189-
return;
190-
}
191-
}
192-
propOut.set(dflt);
193-
}
194-
},
195-
geoid: {
196-
description: [
197-
'A geo id string (e.g. \'geo\', \'geo2\', \'geo3\', ...).'
198-
].join(' '),
199-
requiredOpts: [],
200-
otherOpts: ['dflt'],
201-
coerceFunction: function(v, propOut, dflt) {
202-
if(typeof v === 'string' && v.substr(0,3)===dflt) {
203-
var geonum = Number(v.substr(3));
204-
if(geonum%1 === 0 && geonum>1) {
205-
propOut.set(v);
206-
return;
207-
}
171+
var dlen = dflt.length;
172+
if(typeof v === 'string' && v.substr(0, dlen) === dflt &&
173+
idRegex.test(v.substr(dlen))) {
174+
propOut.set(v);
175+
return;
208176
}
209177
propOut.set(dflt);
210178
}

src/plots/cartesian/attributes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
module.exports = {
1313
xaxis: {
14-
valType: 'axisid',
14+
valType: 'subplotid',
1515
role: 'info',
1616
dflt: 'x',
1717
description: [
@@ -23,7 +23,7 @@ module.exports = {
2323
].join(' ')
2424
},
2525
yaxis: {
26-
valType: 'axisid',
26+
valType: 'subplotid',
2727
role: 'info',
2828
dflt: 'y',
2929
description: [

src/plots/geo/layout/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
module.exports = {
1313
geo: {
14-
valType: 'geoid',
14+
valType: 'subplotid',
1515
role: 'info',
1616
dflt: 'geo',
1717
description: [

src/plots/gl3d/layout/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
module.exports = {
1313
scene: {
14-
valType: 'sceneid',
14+
valType: 'subplotid',
1515
role: 'info',
1616
dflt: 'scene',
1717
description: [

test/jasmine/tests/lib_test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,46 @@ describe('Test lib.js:', function() {
588588

589589

590590
});
591+
592+
describe('subplotid valtype', function() {
593+
var dflt = 'slice';
594+
var idAttrs = {
595+
pizza: {
596+
valType: 'subplotid',
597+
dflt: dflt
598+
}
599+
};
600+
601+
var goodVals = ['slice', 'slice2', 'slice1492'];
602+
603+
goodVals.forEach(function(goodVal) {
604+
it('should allow "' + goodVal + '"', function() {
605+
expect(coerce({pizza: goodVal}, {}, idAttrs, 'pizza'))
606+
.toEqual(goodVal);
607+
});
608+
});
609+
610+
var badVals = [
611+
'slice0',
612+
'slice1',
613+
'Slice2',
614+
'2slice',
615+
'2',
616+
2,
617+
'slice2 ',
618+
'slice2.0',
619+
' slice2',
620+
'slice 2',
621+
'slice01'
622+
];
623+
624+
badVals.forEach(function(badVal) {
625+
it('should not allow "' + badVal + '"', function() {
626+
expect(coerce({pizza: badVal}, {}, idAttrs, 'pizza'))
627+
.toEqual(dflt);
628+
});
629+
});
630+
});
591631
});
592632

593633
describe('coerceFont', function() {

0 commit comments

Comments
 (0)