@@ -15,12 +15,6 @@ var constants = require('./constants');
1515
1616var unsupportedBrowsers = Lib . isIOS ( ) || Lib . isSafari ( ) || Lib . isIE ( ) ;
1717
18- function compatibleAxis ( ax ) {
19- return ax . type === 'linear' &&
20- // y axis must be reversed but x axis mustn't be
21- ( ( ax . range [ 1 ] > ax . range [ 0 ] ) === ( ax . _id . charAt ( 0 ) === 'x' ) ) ;
22- }
23-
2418module . exports = function plot ( gd , plotinfo , cdimage , imageLayer ) {
2519 var xa = plotinfo . xaxis ;
2620 var ya = plotinfo . yaxis ;
@@ -31,7 +25,7 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
3125 var plotGroup = d3 . select ( this ) ;
3226 var cd0 = cd [ 0 ] ;
3327 var trace = cd0 . trace ;
34- var fastImage = supportsPixelatedImage && ! trace . _hasZ && trace . _hasSource && compatibleAxis ( xa ) && compatibleAxis ( ya ) ;
28+ var fastImage = supportsPixelatedImage && ! trace . _hasZ && trace . _hasSource && xa . type === 'linear' && ya . type === 'linear' ;
3529 trace . _fastImage = fastImage ;
3630
3731 var z = cd0 . z ;
@@ -144,8 +138,7 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
144138 // Pixelated image rendering
145139 // http://phrogz.net/tmp/canvas_image_zoom.html
146140 // https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering
147- image3
148- . attr ( '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;' ) ;
141+ 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;' ;
149142
150143 var p = new Promise ( function ( resolve ) {
151144 if ( trace . _hasZ ) {
@@ -181,13 +174,21 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
181174 }
182175 } )
183176 . then ( function ( ) {
184- var href , canvas ;
177+ var href , canvas , localStyle ;
178+ localStyle = initialStyle ;
185179 if ( trace . _hasZ ) {
186180 canvas = drawMagnifiedPixelsOnCanvas ( function ( i , j ) { return z [ j ] [ i ] ; } ) ;
187181 href = canvas . toDataURL ( 'image/png' ) ;
188182 } else if ( trace . _hasSource ) {
189183 if ( fastImage ) {
190184 href = trace . source ;
185+ // Flip the SVG image as needed
186+ var axis_scale = [ ( xa . range [ 0 ] < xa . range [ 1 ] ) ? 1 : - 1 , ( ya . range [ 0 ] < ya . range [ 1 ] ) ? - 1 : 1 ] ;
187+ var trans = '' ;
188+ trans += 'translate(' + ( left + imageWidth / 2 ) + 'px,' + ( top + imageHeight / 2 ) + 'px)' ;
189+ trans += 'scale(' + axis_scale [ 0 ] + ',' + axis_scale [ 1 ] + ')' ;
190+ trans += 'translate(' + ( - left - imageWidth / 2 ) + 'px,' + ( - top - imageHeight / 2 ) + 'px)' ;
191+ localStyle += 'transform:' + trans + ';' ;
191192 } else {
192193 var context = trace . _canvas . el . getContext ( '2d' ) ;
193194 var data = context . getImageData ( 0 , 0 , w , h ) . data ;
@@ -209,7 +210,8 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
209210 height : imageHeight ,
210211 width : imageWidth ,
211212 x : left ,
212- y : top
213+ y : top ,
214+ style : localStyle
213215 } ) ;
214216 } ) ;
215217
0 commit comments