* 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
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';
}
clear() {
- canvasClear(this);
+ clearCanvas(this.canvas, this.ctx);
return this;
}
destroy() {
const me = this;
- const canvas = me.canvas;
+ const {canvas, ctx} = me;
let i, ilen;
me.stop();
if (canvas) {
me.unbindEvents();
- canvasClear(me);
- me.platform.releaseContext(me.ctx);
+ clearCanvas(canvas, ctx);
+ me.platform.releaseContext(ctx);
me.canvas = null;
me.ctx = null;
}
}
/**
- * 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) {
var helpers = Chart.helpers;
- describe('clear', function() {
+ describe('clearCanvas', function() {
it('should clear the chart canvas', function() {
var chart = acquireChart({}, {
canvas: {
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);
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;