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

Method bindResponsiveEvents

src/core/core.controller.js:1080–1132  ·  view source on GitHub ↗

* @private

()

Source from the content-addressed store, hash-verified

1078 * @private
1079 */
1080 bindResponsiveEvents() {
1081 if (!this._responsiveListeners) {
1082 this._responsiveListeners = {};
1083 }
1084 const listeners = this._responsiveListeners;
1085 const platform = this.platform;
1086
1087 const _add = (type, listener) => {
1088 platform.addEventListener(this, type, listener);
1089 listeners[type] = listener;
1090 };
1091 const _remove = (type, listener) => {
1092 if (listeners[type]) {
1093 platform.removeEventListener(this, type, listener);
1094 delete listeners[type];
1095 }
1096 };
1097
1098 const listener = (width, height) => {
1099 if (this.canvas) {
1100 this.resize(width, height);
1101 }
1102 };
1103
1104 let detached; // eslint-disable-line prefer-const
1105 const attached = () => {
1106 _remove('attach', attached);
1107
1108 this.attached = true;
1109 this.resize();
1110
1111 _add('resize', listener);
1112 _add('detach', detached);
1113 };
1114
1115 detached = () => {
1116 this.attached = false;
1117
1118 _remove('resize', listener);
1119
1120 // Stop animating and remove metasets, so when re-attached, the animations start from beginning.
1121 this._stop();
1122 this._resize(0, 0);
1123
1124 _add('attach', attached);
1125 };
1126
1127 if (platform.isAttached(this.canvas)) {
1128 attached();
1129 } else {
1130 detached();
1131 }
1132 }
1133
1134 /**
1135 * @private

Callers 1

bindEventsMethod · 0.95

Calls 3

_stopMethod · 0.95
_resizeMethod · 0.95
isAttachedMethod · 0.45

Tested by

no test coverage detected