Skip to content

Commit 1117113

Browse files
committed
Reuse Lib.counterRegex to match deprecated title string attributes [882]
- Add `matchBeginning` parameter to `regex.counter`.
1 parent 014548c commit 1117113

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/lib/regex.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
* @param {Optional(string)} tail: a fixed piece after the id
1717
* eg counterRegex('scene', '.annotations') for scene2.annotations etc.
1818
* @param {boolean} openEnded: if true, the string may continue past the match.
19+
* @param {boolean} matchBeginning: if false, the string may start before the match.
1920
*/
20-
exports.counter = function(head, tail, openEnded) {
21+
exports.counter = function(head, tail, openEnded, matchBeginning) {
2122
var fullTail = (tail || '') + (openEnded ? '' : '$');
23+
var startWithPrefix = matchBeginning === false ? '' : '^';
2224
if(head === 'xy') {
23-
return new RegExp('^x([2-9]|[1-9][0-9]+)?y([2-9]|[1-9][0-9]+)?' + fullTail);
25+
return new RegExp(startWithPrefix + 'x([2-9]|[1-9][0-9]+)?y([2-9]|[1-9][0-9]+)?' + fullTail);
2426
}
25-
return new RegExp('^' + head + '([2-9]|[1-9][0-9]+)?' + fullTail);
27+
return new RegExp(startWithPrefix + head + '([2-9]|[1-9][0-9]+)?' + fullTail);
2628
};

src/plot_api/plot_api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ function _restyle(gd, aobj, traces) {
17001700
* @param layoutObj
17011701
*/
17021702
function cleanDeprecatedLayoutAttributes(layoutObj) {
1703-
var oldAxisTitleRegExp = /axis\d{0,2}\.title$/;
1703+
var oldAxisTitleRegExp = Lib.counterRegex('axis', '\.title', false, false);
17041704
var keys, i, key, value;
17051705

17061706
if(typeof layoutObj.title === 'string') {

0 commit comments

Comments
 (0)