MCPcopy Index your code
hub / github.com/bqplot/bqplot / get_rendered_canvas

Method get_rendered_canvas

js/src/Figure.ts:1356–1380  ·  view source on GitHub ↗
(scale)

Source from the content-addressed store, hash-verified

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);

Callers 5

upload_pngMethod · 0.95
save_pngMethod · 0.95
getPixelMethod · 0.95
image.tsFile · 0.80
interacts.tsFile · 0.80

Calls 1

get_svgMethod · 0.95

Tested by

no test coverage detected