Skip to content

Commit 1f96817

Browse files
ndg63276Mark Williams
andauthored
LIMS-1496: Fix offset grid scan heatmaps in Safari (#896)
* LIMS-1496: Fix offset grid scan heatmaps in Safari --------- Co-authored-by: Mark Williams <mark.williams@diamond.ac.uk>
1 parent e6ad9b0 commit 1f96817

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

client/src/js/modules/dc/views/gridplot.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,28 @@ define(['jquery', 'marionette',
389389
this.scale = this.perceivedw/(w+this.offset_w)
390390

391391
this.ctx.globalAlpha = 1
392-
this.ctx.drawImage(this.snapshot, stx-this.offset_w/2, sty-this.offset_h/2, w+this.offset_w, h+this.offset_h, 0, 0, this.perceivedw, this.perceivedh)
392+
let sx = stx-this.offset_w/2
393+
let sy = sty-this.offset_h/2
394+
let swidth = w+this.offset_w
395+
let sheight = h+this.offset_h
396+
let dx = 0
397+
let dy = 0
398+
let dwidth = this.perceivedw
399+
let dheight = this.perceivedh
400+
// Safari ignores sx values less than zero
401+
if (sx < 0) {
402+
dx = Math.abs(sx * this.scale)
403+
sx = 0
404+
swidth = Math.min(this.perceivedw/this.scale, this.snapshot.width)
405+
dwidth = Math.min(this.perceivedw, this.snapshot.width*this.scale)
406+
}
407+
// Safari ignores swidth values greater than snapshot width - sx
408+
if (swidth > this.snapshot.width - sx) {
409+
dwidth *= (this.snapshot.width - sx) / swidth
410+
swidth = this.snapshot.width - sx
411+
}
412+
413+
this.ctx.drawImage(this.snapshot, sx, sy, swidth, sheight, dx, dy, dwidth, dheight)
393414
}
394415

395416
var d = []

0 commit comments

Comments
 (0)