MCPcopy Create free account
hub / github.com/chartjs/Chart.js / update

Method update

src/core/core.controller.js:479–541  ·  view source on GitHub ↗
(mode)

Source from the content-addressed store, hash-verified

477 }
478
479 update(mode) {
480 const config = this.config;
481
482 config.update();
483 const options = this._options = config.createResolver(config.chartOptionScopes(), this.getContext());
484 const animsDisabled = this._animationsDisabled = !options.animation;
485
486 this._updateScales();
487 this._checkEventBindings();
488 this._updateHiddenIndices();
489
490 // plugins options references might have change, let's invalidate the cache
491 // https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167
492 this._plugins.invalidate();
493
494 if (this.notifyPlugins('beforeUpdate', {mode, cancelable: true}) === false) {
495 return;
496 }
497
498 // Make sure dataset controllers are updated and new controllers are reset
499 const newControllers = this.buildOrUpdateControllers();
500
501 this.notifyPlugins('beforeElementsUpdate');
502
503 // Make sure all dataset controllers have correct meta data counts
504 let minPadding = 0;
505 for (let i = 0, ilen = this.data.datasets.length; i < ilen; i++) {
506 const {controller} = this.getDatasetMeta(i);
507 const reset = !animsDisabled && newControllers.indexOf(controller) === -1;
508 // New controllers will be reset after the layout pass, so we only want to modify
509 // elements added to new datasets
510 controller.buildOrUpdateElements(reset);
511 minPadding = Math.max(+controller.getMaxOverflow(), minPadding);
512 }
513 minPadding = this._minPadding = options.layout.autoPadding ? minPadding : 0;
514 this._updateLayout(minPadding);
515
516 // Only reset the controllers if we have animations
517 if (!animsDisabled) {
518 // Can only reset the new controllers after the scales have been updated
519 // Reset is done to get the starting point for the initial animation
520 each(newControllers, (controller) => {
521 controller.reset();
522 });
523 }
524
525 this._updateDatasets(mode);
526
527 // Do this before render so that any plugins that need final scale updates can use it
528 this.notifyPlugins('afterUpdate', {mode});
529
530 this._layers.sort(compare2Level('z', '_idx'));
531
532 // Replay last event from before update, or set hover styles on active elements
533 const {_active, _lastEvent} = this;
534 if (_lastEvent) {
535 this._eventHandler(_lastEvent, true);
536 } else if (_active.length) {

Callers 3

constructorMethod · 0.95
_resizeMethod · 0.95
_updateVisibilityMethod · 0.95

Calls 15

getContextMethod · 0.95
_updateScalesMethod · 0.95
_checkEventBindingsMethod · 0.95
_updateHiddenIndicesMethod · 0.95
notifyPluginsMethod · 0.95
getDatasetMetaMethod · 0.95
_updateLayoutMethod · 0.95
_updateDatasetsMethod · 0.95
_eventHandlerMethod · 0.95
_updateHoverStylesMethod · 0.95
renderMethod · 0.95

Tested by

no test coverage detected