diff --git a/src/lib/index.js b/src/lib/index.js index 157dd15542b..17342b1a649 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -1244,3 +1244,20 @@ lib.ensureUniformFontSize = function(gd, baseFont) { ); return out; }; + +/** + * provide a human-readable list e.g. "A, B, C and D" with an ending separator + * + * @param {array} arr : the array to join + * @param {string} mainSeparator : main separator + * @param {string} lastSeparator : last separator + * + * @return {string} : joined list + */ +lib.join2 = function(arr, mainSeparator, lastSeparator) { + var len = arr.length; + if(len > 1) { + return arr.slice(0, -1).join(mainSeparator) + lastSeparator + arr[len - 1]; + } + return arr.join(mainSeparator); +}; diff --git a/src/plot_api/to_image.js b/src/plot_api/to_image.js index 11491416f01..e0e3f4c18bd 100644 --- a/src/plot_api/to_image.js +++ b/src/plot_api/to_image.js @@ -116,7 +116,7 @@ function toImage(gd, opts) { } if(!isImpliedOrValid('format')) { - throw new Error('Image format is not jpeg, png, svg or webp.'); + throw new Error('Export format is not ' + Lib.join2(attrs.format.values, ', ', ' or ') + '.'); } var fullOpts = {}; diff --git a/test/jasmine/tests/toimage_test.js b/test/jasmine/tests/toimage_test.js index 5baac3d2445..fdbe1ce6bdf 100644 --- a/test/jasmine/tests/toimage_test.js +++ b/test/jasmine/tests/toimage_test.js @@ -65,7 +65,7 @@ describe('Plotly.toImage', function() { Plotly.plot(gd, fig.data, fig.layout) .then(function(gd) { expect(function() { Plotly.toImage(gd, {format: 'x'}); }) - .toThrow(new Error('Image format is not jpeg, png, svg or webp.')); + .toThrow(new Error('Export format is not png, jpeg, webp, svg or full-json.')); }) .catch(failTest) .then(done);