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

Method bindResponsiveEvents

src/core/core.controller.js:1001–1053  ·  view source on GitHub ↗

* @private

()

Source from the content-addressed store, hash-verified

999 * @private
1000 */
1001 bindResponsiveEvents() {
1002 if (!this._responsiveListeners) {
1003 this._responsiveListeners = {};
1004 }
1005 const listeners = this._responsiveListeners;
1006 const platform = this.platform;
1007
1008 const _add = (type, listener) => {
1009 platform.addEventListener(this, type, listener);
1010 listeners[type] = listener;
1011 };
1012 const _remove = (type, listener) => {
1013 if (listeners[type]) {
1014 platform.removeEventListener(this, type, listener);
1015 delete listeners[type];
1016 }
1017 };
1018
1019 const listener = (width, height) => {
1020 if (this.canvas) {
1021 this.resize(width, height);
1022 }
1023 };
1024
1025 let detached; // eslint-disable-line prefer-const
1026 const attached = () => {
1027 _remove('attach', attached);
1028
1029 this.attached = true;
1030 this.resize();
1031
1032 _add('resize', listener);
1033 _add('detach', detached);
1034 };
1035
1036 detached = () => {
1037 this.attached = false;
1038
1039 _remove('resize', listener);
1040
1041 // Stop animating and remove metasets, so when re-attached, the animations start from beginning.
1042 this._stop();
1043 this._resize(0, 0);
1044
1045 _add('attach', attached);
1046 };
1047
1048 if (platform.isAttached(this.canvas)) {
1049 attached();
1050 } else {
1051 detached();
1052 }
1053 }
1054
1055 /**
1056 * @private

Callers 1

bindEventsMethod · 0.95

Calls 3

_stopMethod · 0.95
_resizeMethod · 0.95
isAttachedMethod · 0.45

Tested by

no test coverage detected