From f7b488eb545cfb307968bf9fbe20cfd1eb031f18 Mon Sep 17 00:00:00 2001 From: WofWca Date: Wed, 6 Oct 2021 23:21:59 +0800 Subject: [PATCH] perf: remove unnecessary `context.save()`& `context.restore()` --- smoothie.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/smoothie.js b/smoothie.js index d5a4903..4a74007 100644 --- a/smoothie.js +++ b/smoothie.js @@ -844,10 +844,6 @@ context.font = chartOptions.labels.fontSize + 'px ' + chartOptions.labels.fontFamily; - // Save the state of the canvas context, any transformations applied in this method - // will get removed from the stack at the end of this method when .restore() is called. - context.save(); - // Move the origin. context.translate(dimensions.left, dimensions.top); @@ -859,14 +855,11 @@ context.clip(); // Clear the working area. - context.save(); context.fillStyle = chartOptions.grid.fillStyle; context.clearRect(0, 0, dimensions.width, dimensions.height); context.fillRect(0, 0, dimensions.width, dimensions.height); - context.restore(); // Grid lines... - context.save(); context.lineWidth = chartOptions.grid.lineWidth; context.strokeStyle = chartOptions.grid.strokeStyle; // Vertical (time) dividers. @@ -904,7 +897,6 @@ context.strokeRect(0, 0, dimensions.width, dimensions.height); context.closePath(); } - context.restore(); // Draw any horizontal lines... if (chartOptions.horizontalLines && chartOptions.horizontalLines.length) { @@ -931,7 +923,6 @@ if (dataSet.length <= 1 || timeSeries.disabled) { continue; } - context.save(); var seriesOptions = this.seriesSet[d].options; @@ -1007,8 +998,6 @@ context.stroke(); } context.closePath(); - - context.restore(); } if (chartOptions.tooltip && this.mouseX >= 0) { @@ -1106,8 +1095,6 @@ context.fillStyle = chartOptions.title.fillStyle; context.fillText(chartOptions.title.text, titleXPos, titleYPos); } - - context.restore(); // See .save() above. }; // Sample timestamp formatting function