From 1bc85bfbca666020ff685febe0b28d7a18bb2a7c Mon Sep 17 00:00:00 2001 From: jdescottes Date: Sat, 19 Sep 2015 00:07:14 +0200 Subject: [PATCH] Fix : Hide grid when zoom no longer allows proper display --- src/js/rendering/frame/FrameRenderer.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/js/rendering/frame/FrameRenderer.js b/src/js/rendering/frame/FrameRenderer.js index 82ea9ada..c5cb70af 100644 --- a/src/js/rendering/frame/FrameRenderer.js +++ b/src/js/rendering/frame/FrameRenderer.js @@ -140,11 +140,23 @@ }; ns.FrameRenderer.prototype.getGridWidth = function () { - if (this.supportGridRendering) { - return this.gridWidth_; - } else { + if (!this.supportGridRendering) { return 0; } + + return this.gridWidth_; + }; + + /** + * Compute a grid width value best suited to the current display context, + * particularly for the current zoom level + */ + ns.FrameRenderer.prototype.computeGridWidthForDisplay_ = function () { + var gridWidth = this.getGridWidth(); + while (this.zoom < 6 * gridWidth) { + gridWidth--; + } + return gridWidth; }; ns.FrameRenderer.prototype.updateMargins_ = function (frame) { @@ -249,7 +261,7 @@ var isIE10 = pskl.utils.UserAgent.isIE && pskl.utils.UserAgent.version === 10; - var gridWidth = this.getGridWidth(); + var gridWidth = this.computeGridWidthForDisplay_(); var isGridEnabled = gridWidth > 0; if (isGridEnabled || isIE10) { var scaled = pskl.utils.ImageResizer.resizeNearestNeighbour(this.canvas, this.zoom, gridWidth);