@@ -15,12 +15,6 @@ var constants = require('./constants');
15
15
16
16
var unsupportedBrowsers = Lib . isIOS ( ) || Lib . isSafari ( ) || Lib . isIE ( ) ;
17
17
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
-
24
18
module . exports = function plot ( gd , plotinfo , cdimage , imageLayer ) {
25
19
var xa = plotinfo . xaxis ;
26
20
var ya = plotinfo . yaxis ;
@@ -31,7 +25,7 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
31
25
var plotGroup = d3 . select ( this ) ;
32
26
var cd0 = cd [ 0 ] ;
33
27
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' ;
35
29
trace . _fastImage = fastImage ;
36
30
37
31
var z = cd0 . z ;
@@ -144,8 +138,7 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
144
138
// Pixelated image rendering
145
139
// http://phrogz.net/tmp/canvas_image_zoom.html
146
140
// 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;' ;
149
142
150
143
var p = new Promise ( function ( resolve ) {
151
144
if ( trace . _hasZ ) {
@@ -181,13 +174,21 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
181
174
}
182
175
} )
183
176
. then ( function ( ) {
184
- var href , canvas ;
177
+ var href , canvas , localStyle ;
178
+ localStyle = initialStyle ;
185
179
if ( trace . _hasZ ) {
186
180
canvas = drawMagnifiedPixelsOnCanvas ( function ( i , j ) { return z [ j ] [ i ] ; } ) ;
187
181
href = canvas . toDataURL ( 'image/png' ) ;
188
182
} else if ( trace . _hasSource ) {
189
183
if ( fastImage ) {
190
184
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 + ';' ;
191
192
} else {
192
193
var context = trace . _canvas . el . getContext ( '2d' ) ;
193
194
var data = context . getImageData ( 0 , 0 , w , h ) . data ;
@@ -209,7 +210,8 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
209
210
height : imageHeight ,
210
211
width : imageWidth ,
211
212
x : left ,
212
- y : top
213
+ y : top ,
214
+ style : localStyle
213
215
} ) ;
214
216
} ) ;
215
217
0 commit comments