Skip to content

Commit

Permalink
fix: make makeScale a free function
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Dec 29, 2020
1 parent 9c5dbaf commit 1d3ce49
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions lib/minimap-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,14 +841,16 @@ class MinimapElement {
} else {
let canvasTransform = makeTranslate(0, canvasTop, this.useHardwareAcceleration)
if (devicePixelRatio !== 1) {
canvasTransform += ' ' + this.makeScale(1 / devicePixelRatio)
const scale = 1 / devicePixelRatio
canvasTransform += ' ' + makeScale(scale, scale, this.useHardwareAcceleration)
}
applyStyles(this.backLayer.canvas, { transform: canvasTransform })
applyStyles(this.tokensLayer.canvas, { transform: canvasTransform })
applyStyles(this.frontLayer.canvas, { transform: canvasTransform })
}
} else {
const canvasTransform = this.makeScale(1 / devicePixelRatio)
const scale = 1 / devicePixelRatio
const canvasTransform = makeScale(scale, scale, this.useHardwareAcceleration)
applyStyles(this.backLayer.canvas, { transform: canvasTransform })
applyStyles(this.tokensLayer.canvas, { transform: canvasTransform })
applyStyles(this.frontLayer.canvas, { transform: canvasTransform })
Expand Down Expand Up @@ -1276,22 +1278,6 @@ class MinimapElement {
// ## ## ## ## ## ##
// ###### ###### ######

/**
* Returns a string with a CSS scaling tranform value.
*
* @param {number} [x = 0] the x scaling factor
* @param {number} [y = 0] the y scaling factor
* @return {string} the CSS scaling string
* @access private
*/
makeScale (x = 0, y = x) {
if (this.useHardwareAcceleration) {
return `scale3d(${x}, ${y}, 1)`
} else {
return `scale(${x}, ${y})`
}
}

/**
* A method that mimic the jQuery `animate` method and used to animate the
* scroll when clicking on the MinimapElement canvas.
Expand Down Expand Up @@ -1378,6 +1364,23 @@ function makeTranslate (x = 0, y = 0, useHardwareAcceleration = false) {
}
}

/**
* Returns a string with a CSS scaling tranform value.
*
* @param {number} [x = 0] the x scaling factor
* @param {number} [y = 0] the y scaling factor
* @param {boolean} [useHardwareAcceleration = false] use hardware acceleration
* @return {string} the CSS scaling string
* @access private
*/
function makeScale (x = 0, y = x, useHardwareAcceleration = false) {
if (useHardwareAcceleration) {
return `scale3d(${x}, ${y}, 1)`
} else {
return `scale(${x}, ${y})`
}
}

/**
* A method that return the current time as a Date.
*
Expand Down

0 comments on commit 1d3ce49

Please sign in to comment.