| 101 | } |
| 102 | |
| 103 | class Chart { |
| 104 | |
| 105 | static defaults = defaults; |
| 106 | static instances = instances; |
| 107 | static overrides = overrides; |
| 108 | static registry = registry; |
| 109 | static version = version; |
| 110 | static getChart = getChart; |
| 111 | |
| 112 | static register(...items) { |
| 113 | registry.add(...items); |
| 114 | invalidatePlugins(); |
| 115 | } |
| 116 | |
| 117 | static unregister(...items) { |
| 118 | registry.remove(...items); |
| 119 | invalidatePlugins(); |
| 120 | } |
| 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 = []; |
nothing calls this directly
no outgoing calls
no test coverage detected