MCPcopy
hub / github.com/chartjs/Chart.js / releaseContext

Method releaseContext

src/platform/platform.dom.js:293–323  ·  view source on GitHub ↗

* @param {CanvasRenderingContext2D} context

(context)

Source from the content-addressed store, hash-verified

291 * @param {CanvasRenderingContext2D} context
292 */
293 releaseContext(context) {
294 const canvas = context.canvas;
295 if (!canvas[EXPANDO_KEY]) {
296 return false;
297 }
298
299 const initial = canvas[EXPANDO_KEY].initial;
300 ['height', 'width'].forEach((prop) => {
301 const value = initial[prop];
302 if (isNullOrUndef(value)) {
303 canvas.removeAttribute(prop);
304 } else {
305 canvas.setAttribute(prop, value);
306 }
307 });
308
309 const style = initial.style || {};
310 Object.keys(style).forEach((key) => {
311 canvas.style[key] = style[key];
312 });
313
314 // The canvas render size might have been changed (and thus the state stack discarded),
315 // we can't use save() and restore() to restore the initial state. So make sure that at
316 // least the canvas context is reset to the default state by setting the canvas width.
317 // https://www.w3.org/TR/2011/WD-html5-20110525/the-canvas-element.html
318 // eslint-disable-next-line no-self-assign
319 canvas.width = canvas.width;
320
321 delete canvas[EXPANDO_KEY];
322 return true;
323 }
324
325 /**
326 *

Callers 1

destroyMethod · 0.45

Calls 1

isNullOrUndefFunction · 0.85

Tested by

no test coverage detected