(scale)
| 1354 | } |
| 1355 | |
| 1356 | async get_rendered_canvas(scale): Promise<HTMLCanvasElement> { |
| 1357 | // scale up the underlying canvas for high dpi screens |
| 1358 | // such that image is of the same quality |
| 1359 | scale = scale || window.devicePixelRatio; |
| 1360 | // Render a SVG data into a canvas and |
| 1361 | const xml = await this.get_svg(); |
| 1362 | |
| 1363 | return new Promise((resolve) => { |
| 1364 | const image = new Image(); |
| 1365 | image.onload = () => { |
| 1366 | const canvas = document.createElement('canvas'); |
| 1367 | canvas.classList.add('bqplot'); |
| 1368 | canvas.width = this.width * scale; |
| 1369 | canvas.height = this.height * scale; |
| 1370 | canvas.style.width = this.width.toString(); |
| 1371 | canvas.style.height = this.height.toString(); |
| 1372 | const context = canvas.getContext('2d'); |
| 1373 | context.scale(scale, scale); |
| 1374 | context.drawImage(image, 0, 0); |
| 1375 | resolve(canvas); |
| 1376 | }; |
| 1377 | image.src = |
| 1378 | 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(xml))); |
| 1379 | }); |
| 1380 | } |
| 1381 | |
| 1382 | async upload_png(model, scale) { |
| 1383 | const canvas = await this.get_rendered_canvas(scale); |
no test coverage detected