(item, userConfig)
| 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 | this._stacks = undefined; |
| 157 | this.boxes = []; |
| 158 | this.currentDevicePixelRatio = undefined; |
| 159 | this.chartArea = undefined; |
| 160 | this._active = []; |
| 161 | this._lastEvent = undefined; |
| 162 | this._listeners = {}; |
| 163 | /** @type {?{attach?: function, detach?: function, resize?: function}} */ |
| 164 | this._responsiveListeners = undefined; |
| 165 | this._sortedMetasets = []; |
| 166 | this.scales = {}; |
| 167 | this._plugins = new PluginService(); |
| 168 | this.$proxies = {}; |
| 169 | this._hiddenIndices = {}; |
| 170 | this.attached = false; |
| 171 | this._animationsDisabled = undefined; |
| 172 | this.$context = undefined; |
| 173 | this._doResize = debounce(mode => this.update(mode), options.resizeDelay || 0); |
| 174 | this._dataChanges = []; |
| 175 | |
| 176 | // Add the chart instance to the global namespace |
| 177 | instances[this.id] = this; |
| 178 | |
| 179 | if (!context || !canvas) { |
| 180 | // The given item is not a compatible context2d element, let's return before finalizing |
nothing calls this directly
no test coverage detected