]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Rename helpers.clear to helpers.clearCanvas (#8238)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Mon, 28 Dec 2020 08:21:46 +0000 (10:21 +0200)
committerGitHub <noreply@github.com>
Mon, 28 Dec 2020 08:21:46 +0000 (10:21 +0200)
* Change parameters of helpers.clear

* Update test

docs/docs/getting-started/v3-migration.md
src/core/core.controller.js
src/helpers/helpers.canvas.js
test/specs/helpers.canvas.tests.js
types/helpers/helpers.canvas.d.ts

index 4eb8b83998d311747e439ff0b18100688b29715f..4e792434f14389565e7145a679e17295d69ae2ad 100644 (file)
@@ -488,6 +488,7 @@ All helpers are now exposed in a flat hierarchy, e.g., `Chart.helpers.canvas.cli
 * The second parameter to `drawPoint` is now the full options object, so `style`, `rotation`, and `radius` are no longer passed explicitly
 * `helpers.getMaximumHeight` was replaced by `helpers.dom.getMaximumSize`
 * `helpers.getMaximumWidth` was replaced by `helpers.dom.getMaximumSize`
+* `helpers.clear` was renamed to `helpers.clearCanvas` and now takes `canvas` and optionally `ctx` as parameter(s).
 
 #### Platform
 
index 813ae358684b75a62c4635e1d9d3272edfc454dc..6b9f95e316a891698ea249352f52fbb8d433bf5f 100644 (file)
@@ -8,7 +8,7 @@ import registry from './core.registry';
 import Config, {determineAxis, getIndexAxis} from './core.config';
 import {retinaScale} from '../helpers/helpers.dom';
 import {each, callback as callCallback, uid, valueOrDefault, _elementsEqual} from '../helpers/helpers.core';
-import {clear as canvasClear, clipArea, unclipArea, _isPointInArea} from '../helpers/helpers.canvas';
+import {clearCanvas, clipArea, unclipArea, _isPointInArea} from '../helpers/helpers.canvas';
 // @ts-ignore
 import {version} from '../../package.json';
 
@@ -180,7 +180,7 @@ class Chart {
        }
 
        clear() {
-               canvasClear(this);
+               clearCanvas(this.canvas, this.ctx);
                return this;
        }
 
@@ -824,7 +824,7 @@ class Chart {
 
        destroy() {
                const me = this;
-               const canvas = me.canvas;
+               const {canvas, ctx} = me;
                let i, ilen;
 
                me.stop();
@@ -837,8 +837,8 @@ class Chart {
 
                if (canvas) {
                        me.unbindEvents();
-                       canvasClear(me);
-                       me.platform.releaseContext(me.ctx);
+                       clearCanvas(canvas, ctx);
+                       me.platform.releaseContext(ctx);
                        me.canvas = null;
                        me.ctx = null;
                }
index 5d463de2881331bfc01d8dea36bf0284cf9edc46..0d590444e025adf038afa9122813560050b63d9a 100644 (file)
@@ -107,11 +107,13 @@ export function _alignPixel(chart, pixel, width) {
 }
 
 /**
- * Clears the entire canvas associated to the given `chart`.
- * @param {Chart} chart - The chart for which to clear the canvas.
+ * Clears the entire canvas.
+ * @param {HTMLCanvasElement} canvas
+ * @param {CanvasRenderingContext2D} [ctx]
  */
-export function clear(chart) {
-       chart.ctx.clearRect(0, 0, chart.width, chart.height);
+export function clearCanvas(canvas, ctx) {
+       ctx = ctx || canvas.getContext('2d');
+       ctx.clearRect(0, 0, canvas.width, canvas.height);
 }
 
 export function drawPoint(ctx, options, x, y) {
index 35410fea11974e35886ba72e17545fa1b9223756..8bab0ada3ef41252ef0addc3b39ab6dfe0e4af5a 100644 (file)
@@ -5,7 +5,7 @@ describe('Chart.helpers.canvas', function() {
 
        var helpers = Chart.helpers;
 
-       describe('clear', function() {
+       describe('clearCanvas', function() {
                it('should clear the chart canvas', function() {
                        var chart = acquireChart({}, {
                                canvas: {
@@ -15,7 +15,7 @@ describe('Chart.helpers.canvas', function() {
 
                        spyOn(chart.ctx, 'clearRect');
 
-                       helpers.clear(chart);
+                       helpers.clearCanvas(chart.canvas, chart.ctx);
 
                        expect(chart.ctx.clearRect.calls.count()).toBe(1);
                        expect(chart.ctx.clearRect.calls.first().object).toBe(chart.ctx);
index 4dcaa022c13a431c4f53b91354da9c74b36a0138..13a9772c08c1869e09744bcf7d62c44de11e3394 100644 (file)
@@ -3,11 +3,7 @@ import { Color } from '../color';
 import { ChartArea } from '../geometric';
 import { CanvasFontSpec } from './helpers.options';
 
-/**
- * Clears the entire canvas associated to the given `chart`.
- * @param {Chart} chart - The chart for which to clear the canvas.
- */
-export function clear(chart: { ctx: CanvasRenderingContext2D }): void;
+export function clearCanvas(canvas: HTMLCanvasElement, ctx?: CanvasRenderingContext2D): void;
 
 export function clipArea(ctx: CanvasRenderingContext2D, area: ChartArea): void;