From 5ed422a93a9e5685edf12d78e865bb053d6a1373 Mon Sep 17 00:00:00 2001 From: Josh Kelley Date: Mon, 14 Dec 2020 05:30:20 -0500 Subject: [PATCH] Update docs for .resize() method (#8151) See #7678 and #8149. (The `silent` parameter mentioned in the original 7678 no longer exists.) Add JSDoc. Fix some minor issues with grammar and coding style consistency. --- docs/docs/developers/api.md | 15 ++++++++++----- src/core/core.controller.js | 5 +++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/docs/developers/api.md b/docs/docs/developers/api.md index b2f04c4a8..438897969 100644 --- a/docs/docs/developers/api.md +++ b/docs/docs/developers/api.md @@ -19,7 +19,7 @@ This must be called before the canvas is reused for a new chart. myLineChart.destroy(); ``` -## .update(mode) +## .update(mode?) Triggers an update of the chart. This can be safely called after updating the data object. This will update all scales, legends, and then re-render the chart. @@ -40,7 +40,7 @@ See [Updating Charts](updates.md) for more details. ## .reset() -Reset the chart to it's state before the initial animation. A new animation can then be triggered using `update`. +Reset the chart to its state before the initial animation. A new animation can then be triggered using `update`. ```javascript myLineChart.reset(); @@ -60,14 +60,19 @@ myLineChart.stop(); // => returns 'this' for chainability ``` -## .resize() +## .resize(width?, height?) Use this to manually resize the canvas element. This is run each time the canvas container is resized, but you can call this method manually if you change the size of the canvas nodes container element. +You can call `.resize()` with no parameters to have the chart take the size of its container element, or you can pass explicit dimensions (e.g., for [printing](../general/responsive.md#printing-resizable-charts)). + ```javascript // Resizes & redraws to fill its container element myLineChart.resize(); // => returns 'this' for chainability + +// With an explicit size: +myLineChart.resize(width, height); ``` ## .clear() @@ -82,7 +87,7 @@ myLineChart.clear(); ## .toBase64Image() -This returns a base 64 encoded string of the chart in it's current state. +This returns a base 64 encoded string of the chart in its current state. ```javascript myLineChart.toBase64Image(); @@ -177,5 +182,5 @@ chart.setActiveElements([ Finds the chart instance from the given key. If the key is a `string`, it is interpreted as the ID of the Canvas node for the Chart. The key can also be a `CanvasRenderingContext2D` or an `HTMLDOMElement`. This will return `undefined` if no Chart is found. To be found, the chart must have previously been created. ```javascript -const chart = Chart.getChart("canvas-id") +const chart = Chart.getChart("canvas-id"); ``` diff --git a/src/core/core.controller.js b/src/core/core.controller.js index a0a8b33f8..b4d200d4b 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -189,6 +189,11 @@ class Chart { return this; } + /** + * Resize the chart to its container or to explicit dimensions. + * @param {number} [width] + * @param {number} [height] + */ resize(width, height) { if (!animator.running(this)) { this._resize(width, height); -- 2.47.2