Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: remove unnecessary context.save()& context.restore() #143

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 0 additions & 13 deletions smoothie.js
Expand Up @@ -872,10 +872,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 @@ -887,14 +883,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 @@ -926,7 +919,6 @@
context.strokeRect(0, 0, dimensions.width, dimensions.height);
context.closePath();
}
context.restore();

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

var seriesOptions = this.seriesSet[d].options,
// Keep in mind that `context.lineWidth = 0` doesn't actually set it to `0`.
Expand Down Expand Up @@ -1033,8 +1024,6 @@
context.fillStyle = seriesOptions.fillStyle;
context.fill();
}

context.restore();
}

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

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

// Sample timestamp formatting function
Expand Down