MCPcopy
hub / github.com/chartjs/Chart.js / update

Method update

src/core/core.controller.js:475–537  ·  src/core/core.controller.js::Chart.update
(mode)

Source from the content-addressed store, hash-verified

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

Callers 2

constructorMethod · 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