From 0db886c000d49c0bd2f32ab7b65d5d4c492d58a7 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Fri, 18 Dec 2020 16:21:42 +0100 Subject: [PATCH 01/13] Add Image.interpolate property --- src/traces/image/attributes.js | 10 ++++++++++ src/traces/image/defaults.js | 1 + src/traces/image/plot.js | 5 ++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/traces/image/attributes.js b/src/traces/image/attributes.js index 0280b54ba29..62d27fab12c 100644 --- a/src/traces/image/attributes.js +++ b/src/traces/image/attributes.js @@ -51,6 +51,16 @@ module.exports = extendFlat({ 'otherwise it defaults to `rgb`.' ].join(' ') }, + interpolate: { + valType: 'boolean', + dflt: false, + role: 'info', + editType: 'plot', + description: [ + 'Whether to render the image with bilinear interpolation.', + 'Default false (nearest neighbor interpolation).' + ].join(' ') + }, zmin: { valType: 'info_array', items: [ diff --git a/src/traces/image/defaults.js b/src/traces/image/defaults.js index b906cc072a7..80faffcff9e 100644 --- a/src/traces/image/defaults.js +++ b/src/traces/image/defaults.js @@ -47,6 +47,7 @@ module.exports = function supplyDefaults(traceIn, traceOut) { traceOut.zmax = cm.zmaxDflt; } + coerce('interpolate', false); coerce('text'); coerce('hovertext'); coerce('hovertemplate'); diff --git a/src/traces/image/plot.js b/src/traces/image/plot.js index 60bc5a6cc2d..c6d0996d8a7 100644 --- a/src/traces/image/plot.js +++ b/src/traces/image/plot.js @@ -139,7 +139,10 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) { // 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 = ''; + if(!trace.interpolate) { + 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;'; + } if(fastImage) { var xRange = Lib.simpleMap(xa.range, xa.r2l); var yRange = Lib.simpleMap(ya.range, ya.r2l); From e4cfb61fcdd3df2c4f7ec6c2503b8ee86dd68c00 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Fri, 18 Dec 2020 16:48:36 +0100 Subject: [PATCH 02/13] change to enumeration --- src/traces/image/attributes.js | 9 +++++---- src/traces/image/defaults.js | 2 +- src/traces/image/plot.js | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/traces/image/attributes.js b/src/traces/image/attributes.js index 62d27fab12c..4d520df18e9 100644 --- a/src/traces/image/attributes.js +++ b/src/traces/image/attributes.js @@ -52,13 +52,14 @@ module.exports = extendFlat({ ].join(' ') }, interpolate: { - valType: 'boolean', - dflt: false, + valType: 'enumerated', + values: ['nearest', 'linear'], role: 'info', editType: 'plot', description: [ - 'Whether to render the image with bilinear interpolation.', - 'Default false (nearest neighbor interpolation).' + 'The type of interpolation for rendering the image.', + 'Default `nearest` (nearest neighbor interpolation).', + 'Can also be set to `linear` (bilinear interpolation).' ].join(' ') }, zmin: { diff --git a/src/traces/image/defaults.js b/src/traces/image/defaults.js index 80faffcff9e..71af3c1b5c4 100644 --- a/src/traces/image/defaults.js +++ b/src/traces/image/defaults.js @@ -47,7 +47,7 @@ module.exports = function supplyDefaults(traceIn, traceOut) { traceOut.zmax = cm.zmaxDflt; } - coerce('interpolate', false); + coerce('interpolate', 'nearest'); coerce('text'); coerce('hovertext'); coerce('hovertemplate'); diff --git a/src/traces/image/plot.js b/src/traces/image/plot.js index c6d0996d8a7..8cc60bef9ea 100644 --- a/src/traces/image/plot.js +++ b/src/traces/image/plot.js @@ -140,7 +140,7 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) { // http://phrogz.net/tmp/canvas_image_zoom.html // https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering var style = ''; - if(!trace.interpolate) { + if(trace.interpolate === 'nearest') { 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;'; } if(fastImage) { From 0eaabaf7bbfbe470fa7aa6485f188fcb12a2f31e Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Fri, 18 Dec 2020 16:57:31 +0100 Subject: [PATCH 03/13] keep dflt in attributes --- src/traces/image/attributes.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/traces/image/attributes.js b/src/traces/image/attributes.js index 4d520df18e9..143de935b50 100644 --- a/src/traces/image/attributes.js +++ b/src/traces/image/attributes.js @@ -54,6 +54,7 @@ module.exports = extendFlat({ interpolate: { valType: 'enumerated', values: ['nearest', 'linear'], + dflt: 'nearest', role: 'info', editType: 'plot', description: [ From 0bf264c27e1c5e4dd54ee40ca1f8cab8dcf3788d Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Fri, 18 Dec 2020 21:22:24 +0100 Subject: [PATCH 04/13] implement suggestion --- src/traces/image/plot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/traces/image/plot.js b/src/traces/image/plot.js index 8cc60bef9ea..16b97cbf193 100644 --- a/src/traces/image/plot.js +++ b/src/traces/image/plot.js @@ -141,7 +141,7 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) { // https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering var style = ''; if(trace.interpolate === 'nearest') { - 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;'; + 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;'; } if(fastImage) { var xRange = Lib.simpleMap(xa.range, xa.r2l); From 1b53120b3ef8f4d0add6b9e9329077e309f26430 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Mon, 4 Jan 2021 22:39:52 +0100 Subject: [PATCH 05/13] Update src/traces/image/defaults.js Co-authored-by: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com> --- src/traces/image/defaults.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/traces/image/defaults.js b/src/traces/image/defaults.js index 71af3c1b5c4..791f5bb4015 100644 --- a/src/traces/image/defaults.js +++ b/src/traces/image/defaults.js @@ -47,7 +47,7 @@ module.exports = function supplyDefaults(traceIn, traceOut) { traceOut.zmax = cm.zmaxDflt; } - coerce('interpolate', 'nearest'); + coerce('zsmooth'); coerce('text'); coerce('hovertext'); coerce('hovertemplate'); From 8f0b0f1e60f17c93ddcf783b6aea63e82a24fed6 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Tue, 5 Jan 2021 09:46:11 +0100 Subject: [PATCH 06/13] Update src/traces/image/attributes.js Co-authored-by: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com> --- src/traces/image/attributes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/traces/image/attributes.js b/src/traces/image/attributes.js index 143de935b50..28acb5d7c3e 100644 --- a/src/traces/image/attributes.js +++ b/src/traces/image/attributes.js @@ -51,7 +51,7 @@ module.exports = extendFlat({ 'otherwise it defaults to `rgb`.' ].join(' ') }, - interpolate: { + zsmooth: { valType: 'enumerated', values: ['nearest', 'linear'], dflt: 'nearest', From 33ab9590f3c6ceac40646125c67ce0e16f445fa7 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Tue, 5 Jan 2021 09:46:45 +0100 Subject: [PATCH 07/13] Update src/traces/image/attributes.js Co-authored-by: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com> --- src/traces/image/attributes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/traces/image/attributes.js b/src/traces/image/attributes.js index 28acb5d7c3e..aa822dea296 100644 --- a/src/traces/image/attributes.js +++ b/src/traces/image/attributes.js @@ -53,7 +53,7 @@ module.exports = extendFlat({ }, zsmooth: { valType: 'enumerated', - values: ['nearest', 'linear'], + values: ['fast', false], dflt: 'nearest', role: 'info', editType: 'plot', From a3eff716482a2865a139b3cfb94468219a924885 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Tue, 5 Jan 2021 09:46:58 +0100 Subject: [PATCH 08/13] Update src/traces/image/attributes.js Co-authored-by: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com> --- src/traces/image/attributes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/traces/image/attributes.js b/src/traces/image/attributes.js index aa822dea296..919f4207723 100644 --- a/src/traces/image/attributes.js +++ b/src/traces/image/attributes.js @@ -54,7 +54,7 @@ module.exports = extendFlat({ zsmooth: { valType: 'enumerated', values: ['fast', false], - dflt: 'nearest', + dflt: false, role: 'info', editType: 'plot', description: [ From bd28585da006de63459902045fb90d0eed73539f Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Tue, 5 Jan 2021 09:47:24 +0100 Subject: [PATCH 09/13] Update src/traces/image/attributes.js Co-authored-by: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com> --- src/traces/image/attributes.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/traces/image/attributes.js b/src/traces/image/attributes.js index 919f4207723..4dc9109a81d 100644 --- a/src/traces/image/attributes.js +++ b/src/traces/image/attributes.js @@ -57,11 +57,9 @@ module.exports = extendFlat({ dflt: false, role: 'info', editType: 'plot', - description: [ - 'The type of interpolation for rendering the image.', - 'Default `nearest` (nearest neighbor interpolation).', - 'Can also be set to `linear` (bilinear interpolation).' - ].join(' ') + description: [ + 'Picks a smoothing algorithm use to smooth `z` data.' + ].join(' ') }, zmin: { valType: 'info_array', From 6dcb840f8bbbc545f5f932eaad77877ae5fb5a9f Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Tue, 5 Jan 2021 10:14:45 +0100 Subject: [PATCH 10/13] put pixelated style in constants --- src/traces/image/constants.js | 14 +++++++++++++- src/traces/image/plot.js | 9 ++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/traces/image/constants.js b/src/traces/image/constants.js index 75b5a0606fd..d37f4e9c393 100644 --- a/src/traces/image/constants.js +++ b/src/traces/image/constants.js @@ -55,5 +55,17 @@ 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('; ') }; diff --git a/src/traces/image/plot.js b/src/traces/image/plot.js index 9dbba86b9ef..1b33553b230 100644 --- a/src/traces/image/plot.js +++ b/src/traces/image/plot.js @@ -136,13 +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 = ''; - if(trace.interpolate === 'nearest') { - 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); From 8b3903010ecf8a6891ec4f168ecc07c3f692089d Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Tue, 5 Jan 2021 10:20:40 +0100 Subject: [PATCH 11/13] add to docstring --- src/traces/image/attributes.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/traces/image/attributes.js b/src/traces/image/attributes.js index 3b5ad442414..673ac9ef41c 100644 --- a/src/traces/image/attributes.js +++ b/src/traces/image/attributes.js @@ -58,7 +58,8 @@ module.exports = extendFlat({ role: 'info', editType: 'plot', description: [ - 'Picks a smoothing algorithm use to smooth `z` data.' + 'Picks a smoothing algorithm used to smooth `z` data.', + 'This only applies for image traces that use the `source` attribute.' ].join(' ') }, zmin: { From 5b012530891c7d6d401a1e96c4fe55bc975c8335 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Wed, 6 Jan 2021 09:51:56 +0100 Subject: [PATCH 12/13] style --- src/traces/image/attributes.js | 4 ++-- src/traces/image/plot.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/traces/image/attributes.js b/src/traces/image/attributes.js index 673ac9ef41c..e144e029d28 100644 --- a/src/traces/image/attributes.js +++ b/src/traces/image/attributes.js @@ -57,10 +57,10 @@ module.exports = extendFlat({ dflt: false, role: 'info', editType: 'plot', - description: [ + description: [ 'Picks a smoothing algorithm used to smooth `z` data.', 'This only applies for image traces that use the `source` attribute.' - ].join(' ') + ].join(' ') }, zmin: { valType: 'info_array', diff --git a/src/traces/image/plot.js b/src/traces/image/plot.js index 1b33553b230..4c35540e5a6 100644 --- a/src/traces/image/plot.js +++ b/src/traces/image/plot.js @@ -137,7 +137,7 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) { image3.exit().remove(); 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); From 15d157fff9574f2e7a54cc0f4ac3262f1dd1bce1 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Thu, 7 Jan 2021 13:51:32 +0100 Subject: [PATCH 13/13] fix css --- src/traces/image/constants.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/traces/image/constants.js b/src/traces/image/constants.js index d37f4e9c393..240ef31cc7b 100644 --- a/src/traces/image/constants.js +++ b/src/traces/image/constants.js @@ -66,6 +66,7 @@ module.exports = { 'image-rendering: -webkit-optimize-contrast', 'image-rendering: optimize-contrast', 'image-rendering: crisp-edges', - 'image-rendering: pixelated' + 'image-rendering: pixelated', + '' ].join('; ') };