Skip to content

Commit

Permalink
perf: remove unnecessary context.save()& context.restore()
Browse files Browse the repository at this point in the history
  • Loading branch information
WofWca committed Oct 6, 2021
1 parent 0f72ef6 commit 9ccc235
Showing 1 changed file with 0 additions and 13 deletions.
13 changes: 0 additions & 13 deletions smoothie.js
Expand Up @@ -852,10 +852,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);

Expand All @@ -867,14 +863,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.
Expand Down Expand Up @@ -912,7 +905,6 @@
context.strokeRect(0, 0, dimensions.width, dimensions.height);
context.closePath();
}
context.restore();

// Draw any horizontal lines...
if (chartOptions.horizontalLines && chartOptions.horizontalLines.length) {
Expand All @@ -939,7 +931,6 @@
if (dataSet.length <= 1 || timeSeries.disabled) {
continue;
}
context.save();

var seriesOptions = this.seriesSet[d].options;

Expand Down Expand Up @@ -1015,8 +1006,6 @@
context.stroke();
}
context.closePath();

context.restore();
}

if (chartOptions.tooltip && this.mouseX >= 0) {
Expand Down Expand Up @@ -1114,8 +1103,6 @@
context.fillStyle = chartOptions.title.fillStyle;
context.fillText(chartOptions.title.text, titleXPos, titleYPos);
}

context.restore(); // See .save() above.
};

// Sample timestamp formatting function
Expand Down

0 comments on commit 9ccc235

Please sign in to comment.