mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-04 15:34:04 +01:00
Fix context state restoration on destroy
In many cases, the canvas render size is changed by the lib, causing the state stack to be discarded, meaning that we can't use save() and restore() to release the context with its initial state (i.e. before creating the chart). Since we don't need (want) to manually save / restore the context initial state, simply make sure to reset it to the default state to give a fresh context back to the user. That also means we don't need to revert the scale when the pixel device ratio is not 1.
This commit is contained in:
committed by
Evert Timberg
parent
040b0e160d
commit
efced4780c
@@ -667,7 +667,33 @@ describe('Chart.Controller', function() {
|
||||
});
|
||||
|
||||
describe('controller.destroy', function() {
|
||||
it('should restore canvas (and context) initial values', function(done) {
|
||||
it('should reset context to default values', function() {
|
||||
var chart = acquireChart({});
|
||||
var context = chart.chart.ctx;
|
||||
|
||||
chart.destroy();
|
||||
|
||||
// https://www.w3.org/TR/2dcontext/#conformance-requirements
|
||||
Chart.helpers.each({
|
||||
fillStyle: '#000000',
|
||||
font: '10px sans-serif',
|
||||
lineJoin: 'miter',
|
||||
lineCap: 'butt',
|
||||
lineWidth: 1,
|
||||
miterLimit: 10,
|
||||
shadowBlur: 0,
|
||||
shadowColor: 'rgba(0, 0, 0, 0)',
|
||||
shadowOffsetX: 0,
|
||||
shadowOffsetY: 0,
|
||||
strokeStyle: '#000000',
|
||||
textAlign: 'start',
|
||||
textBaseline: 'alphabetic'
|
||||
}, function(value, key) {
|
||||
expect(context[key]).toBe(value);
|
||||
});
|
||||
});
|
||||
|
||||
it('should restore canvas initial values', function(done) {
|
||||
var chart = acquireChart({
|
||||
options: {
|
||||
responsive: true,
|
||||
|
||||
Reference in New Issue
Block a user