FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: add Figure.get_svg_data similar to get_png_data by maartenbreddels · Pull Request #1673 · bqplot/bqplot · GitHub

feat: add Figure.get_svg_data similar to get_png_data by maartenbreddels · Pull Request #1673 · bqplot/bqplot · GitHub
Skip to content

Navigation Menu

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .png  (177) .py  (1) .ts  (2) .yml  (1) All 4 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defaults:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
steps:

- name: Checkout
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
path: ./dist

visual-regression-tests:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
needs: [build]

steps:
Expand Down
20 changes: 20 additions & 0 deletions bqplot/figure.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def __init__(self, **kwargs):
super(Figure, self).__init__(**kwargs)

self._upload_png_callback = None
self._upload_svg_callback = None
self.on_msg(self._handle_custom_msgs)

@default('scale_x')
Expand Down Expand Up @@ -208,6 +209,20 @@ def get_png_data(self, callback, scale=None):
self._upload_png_callback = callback
self.send({'type': 'upload_png', 'scale': scale})

def get_svg_data(self, callback):
'''
Gets the Figure as an SVG memory view (utf-8 encoded bytes).

Parameters
----------
callback: callable
Called with the SVG data (utf-8 encoded bytes) as the only positional argument.
'''
if self._upload_svg_callback:
raise Exception('get_svg_data already in progress')
self._upload_svg_callback = callback
self.send({'type': 'upload_svg'})

@validate('min_aspect_ratio', 'max_aspect_ratio')
def _validate_aspect_ratio(self, proposal):
value = proposal['value']
Expand All @@ -225,6 +240,11 @@ def _handle_custom_msgs(self, _, content, buffers=None):
self._upload_png_callback(buffers[0])
finally:
self._upload_png_callback = None
elif content.get('event') == 'upload_svg':
try:
self._upload_svg_callback(buffers[0])
finally:
self._upload_svg_callback = None

_view_name = Unicode('Figure').tag(sync=True)
_model_name = Unicode('FigureModel').tag(sync=True)
Expand Down
17 changes: 17 additions & 0 deletions js/src/Figure.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ export class Figure extends widgets.DOMWidgetView {
this.model.on('save_png', this.save_png, this);
this.model.on('save_svg', this.save_svg, this);
this.model.on('upload_png', this.upload_png, this);
this.model.on('upload_svg', this.upload_svg, this);

const figure_scale_promise = this.create_figure_scales();

Expand Down Expand Up @@ -1207,6 +1208,22 @@ export class Figure extends widgets.DOMWidgetView {
});
}

async upload_svg(model) {
console.log('upload_svg');
const svg_string = await this.get_svg();
const svg_blob = new Blob([svg_string], {
type: 'image/svg+xml;charset=utf-8',
});
const svg_buffer = await svg_blob.arrayBuffer();
model.send(
{
event: 'upload_svg',
},
null,
[svg_buffer]
);
}

save_png(filename, scale) {
// Render a SVG data into a canvas and download as PNG.

Expand Down
2 changes: 2 additions & 0 deletions js/src/FigureModel.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export class FigureModel extends widgets.DOMWidgetModel {
this.trigger('save_svg', msg.filename);
} else if (msg.type === 'upload_png') {
this.trigger('upload_png', this, msg.scale);
} else if (msg.type === 'upload_svg') {
this.trigger('upload_svg', this);
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.

Footer

© 2026 GitHub, Inc.

Back | FazBrowse Home | New Git URL