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

Method constructor

src/core/core.controller.js:123–200  ·  view source on GitHub ↗
(item, userConfig)

Source from the content-addressed store, hash-verified

121
122 // eslint-disable-next-line max-statements
123 constructor(item, userConfig) {
124 const config = this.config = new Config(userConfig);
125 const initialCanvas = getCanvas(item);
126 const existingChart = getChart(initialCanvas);
127 if (existingChart) {
128 throw new Error(
129 'Canvas is already in use. Chart with ID \'' + existingChart.id + '\'' +
130 ' must be destroyed before the canvas with ID \'' + existingChart.canvas.id + '\' can be reused.'
131 );
132 }
133
134 const options = config.createResolver(config.chartOptionScopes(), this.getContext());
135
136 this.platform = new (config.platform || _detectPlatform(initialCanvas))();
137 this.platform.updateConfig(config);
138
139 const context = this.platform.acquireContext(initialCanvas, options.aspectRatio);
140 const canvas = context && context.canvas;
141 const height = canvas && canvas.height;
142 const width = canvas && canvas.width;
143
144 this.id = uid();
145 this.ctx = context;
146 this.canvas = canvas;
147 this.width = width;
148 this.height = height;
149 this._options = options;
150 // Store the previously used aspect ratio to determine if a resize
151 // is needed during updates. Do this after _options is set since
152 // aspectRatio uses a getter
153 this._aspectRatio = this.aspectRatio;
154 this._layers = [];
155 this._metasets = [];
156 // The meta of each dataset object in _metasets, so that getDatasetMeta
157 // finds it without searching the array.
158 this._metasetByDataset = new Map();
159 this._stacks = undefined;
160 this.boxes = [];
161 this.currentDevicePixelRatio = undefined;
162 this.chartArea = undefined;
163 this._active = [];
164 // Whether `_active` was set by `setActiveElements`: such a set stays outside chartArea.
165 this._activeSetByCode = false;
166 this._lastEvent = undefined;
167 this._listeners = {};
168 /** @type {?{attach?: function, detach?: function, resize?: function}} */
169 this._responsiveListeners = undefined;
170 this._sortedMetasets = [];
171 this.scales = {};
172 this._plugins = new PluginService();
173 this.$proxies = {};
174 this._hiddenIndices = {};
175 this.attached = false;
176 this._animationsDisabled = undefined;
177 this.$context = undefined;
178 this._doResize = debounce(mode => this.update(mode), options.resizeDelay || 0);
179 this._dataChanges = [];
180

Callers

nothing calls this directly

Calls 12

getContextMethod · 0.95
updateMethod · 0.95
_initializeMethod · 0.95
getCanvasFunction · 0.85
_detectPlatformFunction · 0.85
debounceFunction · 0.85
createResolverMethod · 0.80
chartOptionScopesMethod · 0.80
listenMethod · 0.80
getChartFunction · 0.70
updateConfigMethod · 0.45
acquireContextMethod · 0.45

Tested by

no test coverage detected