Skip to content

Commit

Permalink
correct style
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj authored and almarklein committed Nov 30, 2020
1 parent db00dea commit d4eadbd
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/traces/image/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,19 @@ 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 initialStyle = '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 = '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) {
// Flip the SVG image as needed (around the proper center location)
var axisScale = [
(xa.range[0] < xa.range[1]) ? 1 : -1,
(ya.range[0] < ya.range[1]) ? -1 : 1
];
style += 'transform:' +
strTranslate(left + imageWidth / 2 + 'px', top + imageHeight / 2 + 'px') +
'scale(' + axisScale[0] + ',' + axisScale[1] + ')' +
strTranslate(-left - imageWidth / 2 + 'px', -top - imageHeight / 2 + 'px') + ';';

This comment has been minimized.

Copy link
@archmoj

archmoj Nov 30, 2020

Author Contributor

It appears this block could be simplified to:

        if(fastImage) {
            var flipX = xa.range[1] < xa.range[0];
            var flipY = ya.range[1] > ya.range[0];
            if(flipX || flipY) {
                // Flip the SVG image as needed (around the proper center location)
                style += 'transform:' +
                    'translate(50%,50%)' +
                    'scale(' + (flipX ? -1 : 1) + ',' + (flipY ? -1 : 1) + ')' +
                    'translate(-50%,-50%);';
            }
        }
}
image3.attr('style', style);

var p = new Promise(function(resolve) {
if(trace._hasZ) {
Expand Down Expand Up @@ -175,23 +187,13 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
}
})
.then(function() {
var href, canvas, localStyle;
localStyle = initialStyle;
var href, canvas;
if(trace._hasZ) {
canvas = drawMagnifiedPixelsOnCanvas(function(i, j) {return z[j][i];});
href = canvas.toDataURL('image/png');
} else if(trace._hasSource) {
if(fastImage) {
href = trace.source;
// Flip the SVG image as needed (around the proper center location)
var axisScale = [
(xa.range[0] < xa.range[1]) ? 1 : -1,
(ya.range[0] < ya.range[1]) ? -1 : 1
];
localStyle += 'transform:' +
strTranslate(left + imageWidth / 2 + 'px', top + imageHeight / 2 + 'px') +
'scale(' + axisScale[0] + ',' + axisScale[1] + ')' +
strTranslate(-left - imageWidth / 2 + 'px', -top - imageHeight / 2 + 'px') + ';';
} else {
var context = trace._canvas.el.getContext('2d');
var data = context.getImageData(0, 0, w, h).data;
Expand All @@ -213,8 +215,7 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
height: imageHeight,
width: imageWidth,
x: left,
y: top,
style: localStyle
y: top
});
});

Expand Down

0 comments on commit d4eadbd

Please sign in to comment.