Skip to content

Commit d4e449e

Browse files
authored
Merge pull request #5204 from plotly/list-all-export-formats
Mention the full-json option in the Plotly.toImage warning
2 parents 1e17697 + 9ce11aa commit d4e449e

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/lib/index.js

+17
Original file line numberDiff line numberDiff line change
@@ -1244,3 +1244,20 @@ lib.ensureUniformFontSize = function(gd, baseFont) {
12441244
);
12451245
return out;
12461246
};
1247+
1248+
/**
1249+
* provide a human-readable list e.g. "A, B, C and D" with an ending separator
1250+
*
1251+
* @param {array} arr : the array to join
1252+
* @param {string} mainSeparator : main separator
1253+
* @param {string} lastSeparator : last separator
1254+
*
1255+
* @return {string} : joined list
1256+
*/
1257+
lib.join2 = function(arr, mainSeparator, lastSeparator) {
1258+
var len = arr.length;
1259+
if(len > 1) {
1260+
return arr.slice(0, -1).join(mainSeparator) + lastSeparator + arr[len - 1];
1261+
}
1262+
return arr.join(mainSeparator);
1263+
};

src/plot_api/to_image.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function toImage(gd, opts) {
116116
}
117117

118118
if(!isImpliedOrValid('format')) {
119-
throw new Error('Image format is not jpeg, png, svg or webp.');
119+
throw new Error('Export format is not ' + Lib.join2(attrs.format.values, ', ', ' or ') + '.');
120120
}
121121

122122
var fullOpts = {};

test/jasmine/tests/toimage_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('Plotly.toImage', function() {
6565
Plotly.plot(gd, fig.data, fig.layout)
6666
.then(function(gd) {
6767
expect(function() { Plotly.toImage(gd, {format: 'x'}); })
68-
.toThrow(new Error('Image format is not jpeg, png, svg or webp.'));
68+
.toThrow(new Error('Export format is not png, jpeg, webp, svg or full-json.'));
6969
})
7070
.catch(failTest)
7171
.then(done);

0 commit comments

Comments
 (0)