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.
This commit is contained in:
Josh Kelley 2020-12-14 05:30:20 -05:00 committed by GitHub
parent e268845c7b
commit 5ed422a93a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View 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");
```

View 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);