Skip to content

Commit

Permalink
Ignores image trace's source attribute that are not data URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinerg committed Aug 13, 2020
1 parent 1c893e2 commit d45496d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/traces/image/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
var Lib = require('../../lib');
var attributes = require('./attributes');
var constants = require('./constants');
var dataUri = require('../../snapshot/helpers').IMAGE_URL_PREFIX;

module.exports = function supplyDefaults(traceIn, traceOut) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}
var source = coerce('source');
traceOut._isFromSource = !!source;
coerce('source');
if(traceOut.source && !traceOut.source.match(dataUri)) traceOut.source = null;
traceOut._isFromSource = !!traceOut.source;

var z = coerce('z');
traceOut._isFromZ = !(z === undefined || !z.length || !z[0] || !z[0].length);
Expand Down
18 changes: 17 additions & 1 deletion test/jasmine/tests/image_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,23 @@ describe('image supplyDefaults', function() {

traceIn = {
type: 'image',
source: 'base64'
source: 'data:image/png;base64,somedata'
};
traceOut = Plots.supplyTraceDefaults(traceIn, {type: 'image'}, 0, layout);
expect(traceOut.visible).toBe(true);
});

it('should set visible to false when source is a URL', function() {
traceIn = {
source: 'https://antrg.com/assets/img/portrait_2013_circle_200px.png'
};
supplyDefaults(traceIn, traceOut);
expect(traceOut.visible).toBe(false);
expect(traceOut.source).toBe(null);

traceIn = {
type: 'image',
source: 'data:image/png;base64,somedata'
};
traceOut = Plots.supplyTraceDefaults(traceIn, {type: 'image'}, 0, layout);
expect(traceOut.visible).toBe(true);
Expand Down

0 comments on commit d45496d

Please sign in to comment.