Skip to content

Commit

Permalink
feat(Canvas): add support for displaying output in Jupyter Notebook (#60
Browse files Browse the repository at this point in the history
)
  • Loading branch information
DjDeveloperr authored Oct 7, 2023
1 parent 57b8e31 commit a6a2219
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ export class Canvas {
flush() {
if (this[_gpu]) sk_canvas_flush(this[_ptr]);
}

[Symbol.for("Jupyter.display")]() {
return {
"image/png": encodeBase64(this.encode("png")),
};
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/svgcanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ export class SvgCanvas {
);
const text = new TextDecoder().decode(buffer);
sk_data_free(skdata);
Object.defineProperty(text, Symbol.for("Jupyter.display"), {
value: function (this: string) {
return {
"image/svg+xml": this,
};
},
});
return text;
}

Expand Down

0 comments on commit a6a2219

Please sign in to comment.