Skip to content

Commit

Permalink
Merge pull request #5354 from almarklein/interp
Browse files Browse the repository at this point in the history
Implement fast zsmooth option for image trace
  • Loading branch information
archmoj committed Jan 7, 2021
2 parents 177842f + 15d157f commit 3a501ef
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/traces/image/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ module.exports = extendFlat({
'otherwise it defaults to `rgb`.'
].join(' ')
},
zsmooth: {
valType: 'enumerated',
values: ['fast', false],
dflt: false,
role: 'info',
editType: 'plot',
description: [
'Picks a smoothing algorithm used to smooth `z` data.',
'This only applies for image traces that use the `source` attribute.'
].join(' ')
},
zmin: {
valType: 'info_array',
items: [
Expand Down
15 changes: 14 additions & 1 deletion src/traces/image/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,18 @@ module.exports = {
},
suffix: ['°', '%', '%', '']
}
}
},
// For pixelated image rendering
// http://phrogz.net/tmp/canvas_image_zoom.html
// https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering
pixelatedStyle: [
'image-rendering: optimizeSpeed',
'image-rendering: -moz-crisp-edges',
'image-rendering: -o-crisp-edges',
'image-rendering: -webkit-optimize-contrast',
'image-rendering: optimize-contrast',
'image-rendering: crisp-edges',
'image-rendering: pixelated',
''
].join('; ')
};
1 change: 1 addition & 0 deletions src/traces/image/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module.exports = function supplyDefaults(traceIn, traceOut) {
traceOut.zmax = cm.zmaxDflt;
}

coerce('zsmooth');
coerce('text');
coerce('hovertext');
coerce('hovertemplate');
Expand Down
6 changes: 2 additions & 4 deletions src/traces/image/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,8 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {

image3.exit().remove();

// Pixelated image rendering
// http://phrogz.net/tmp/canvas_image_zoom.html
// https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering
var style = 'image-rendering: optimizeSpeed; image-rendering: -moz-crisp-edges; image-rendering: -o-crisp-edges; image-rendering: -webkit-optimize-contrast; image-rendering: optimize-contrast; image-rendering: crisp-edges; image-rendering: pixelated;';
var style = (trace.zsmooth === false) ? constants.pixelatedStyle : '';

if(fastImage) {
var xRange = Lib.simpleMap(xa.range, xa.r2l);
var yRange = Lib.simpleMap(ya.range, ya.r2l);
Expand Down

0 comments on commit 3a501ef

Please sign in to comment.