Skip to content

Commit d57020c

Browse files
committed
Fixed canvas corruption bug when line labels are toggled
1 parent 1febdcd commit d57020c

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/types/box.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ module.exports = function(Chart) {
114114
var view = this._view;
115115
var ctx = this.chartInstance.chart.ctx;
116116

117-
// Canvas setup
118117
ctx.save();
118+
119+
// Canvas setup
119120
ctx.beginPath();
120121
ctx.rect(view.clip.x1, view.clip.y1, view.clip.x2 - view.clip.x1, view.clip.y2 - view.clip.y1);
121122
ctx.clip();
@@ -129,6 +130,8 @@ module.exports = function(Chart) {
129130
height = view.bottom - view.top;
130131
ctx.fillRect(view.left, view.top, width, height);
131132
ctx.strokeRect(view.left, view.top, width, height);
133+
134+
ctx.restore();
132135
}
133136
});
134137

src/types/line.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ module.exports = function(Chart) {
116116
return;
117117
}
118118

119-
// Canvas setup
120119
ctx.save();
120+
121+
// Canvas setup
121122
ctx.beginPath();
122123
ctx.rect(view.clip.x1, view.clip.y1, view.clip.x2 - view.clip.x1, view.clip.y2 - view.clip.y1);
123124
ctx.clip();
@@ -135,7 +136,6 @@ module.exports = function(Chart) {
135136
ctx.moveTo(view.x1, view.y1);
136137
ctx.lineTo(view.x2, view.y2);
137138
ctx.stroke();
138-
ctx.restore();
139139

140140
if (view.labelEnabled && view.labelContent) {
141141
ctx.beginPath();
@@ -169,6 +169,8 @@ module.exports = function(Chart) {
169169
view.labelY + (view.labelHeight / 2)
170170
);
171171
}
172+
173+
ctx.restore();
172174
}
173175
});
174176

0 commit comments

Comments
 (0)