]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Update docs for .resize() method (#8151)
authorJosh Kelley <joshkel@gmail.com>
Mon, 14 Dec 2020 10:30:20 +0000 (05:30 -0500)
committerGitHub <noreply@github.com>
Mon, 14 Dec 2020 10:30:20 +0000 (12:30 +0200)
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
src/core/core.controller.js

index b2f04c4a8035664101eae542d688698ed8bfeea8..438897969b2286ad252c1198ceaea7f1f5a27540 100644 (file)
@@ -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");
 ```
index a0a8b33f85bbd5d696d16196c024d1d7da2051c6..b4d200d4bfeb04a84379c8c0a595982088b53ce0 100644 (file)
@@ -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);