Skip to content

Commit 990a7c0

Browse files
committed
fix: round the pixel rations less than 1 to the nearest tenth
1 parent 3c50686 commit 990a7c0

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

lib/minimap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ export default class Minimap {
861861
*/
862862
getDevicePixelRatio() {
863863
if (this.getDevicePixelRatioRounding()) {
864-
if (devicePixelRatio >= 0.5) {
864+
if (devicePixelRatio >= 1) {
865865
return Math.round(devicePixelRatio)
866866
} else {
867867
return Math.max(Math.round(devicePixelRatio * 10) / 10, 0.1)

spec/minimap-spec.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,28 @@ describe("Stand alone minimap", () => {
512512
expect(changeSpy.callCount).toEqual(3)
513513
})
514514

515-
it("returns the rounding number of devicePixelRatio", () => {
516-
window.devicePixelRatio = 1.25
515+
describe("returns the rounding number of devicePixelRatio", () => {
516+
it("1.25", () => {
517+
window.devicePixelRatio = 1.25
518+
minimap.setDevicePixelRatioRounding(true)
517519

518-
minimap.setDevicePixelRatioRounding(true)
520+
expect(minimap.getDevicePixelRatioRounding()).toEqual(true)
521+
expect(minimap.getDevicePixelRatio()).toEqual(1)
522+
})
523+
it("0.811", () => {
524+
window.devicePixelRatio = 0.811
525+
minimap.setDevicePixelRatioRounding(true)
519526

520-
expect(minimap.getDevicePixelRatioRounding()).toEqual(true)
521-
expect(minimap.getDevicePixelRatio()).toEqual(1)
527+
expect(minimap.getDevicePixelRatioRounding()).toEqual(true)
528+
expect(minimap.getDevicePixelRatio()).toEqual(0.8)
529+
})
530+
it("0.05", () => {
531+
window.devicePixelRatio = 0.051
532+
minimap.setDevicePixelRatioRounding(true)
533+
534+
expect(minimap.getDevicePixelRatioRounding()).toEqual(true)
535+
expect(minimap.getDevicePixelRatio()).toEqual(0.1)
536+
})
522537
})
523538

524539
it("prevents the rounding number of devicePixelRatio", () => {

0 commit comments

Comments
 (0)