Skip to content

Commit

Permalink
add option to control the background color of the exported image (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
hizzgdev committed Feb 19, 2024
1 parent 7d1ad43 commit 30e671c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/plugins/jsmind.screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const DEFAULT_OPTIONS = {
left: $.w.location,
right: 'https://github.com/hizzgdev/jsmind',
},
background: 'transparent',
};

class JmScreenshot {
Expand All @@ -42,6 +43,7 @@ class JmScreenshot {
let c = this.create_canvas();
let ctx = c.getContext('2d');
Promise.resolve(ctx)
.then(() => this.draw_background(ctx))
.then(() => this.draw_lines(ctx))
.then(() => this.draw_nodes(ctx))
.then(() => this.draw_watermark(c, ctx))
Expand All @@ -62,6 +64,19 @@ class JmScreenshot {
c.parentNode.removeChild(c);
}

draw_background(ctx) {
return new Promise(
function (resolve, _) {
const bg = this.options.background;
if (!!bg && bg !== 'transparent') {
ctx.fillStyle = this.options.background;
ctx.fillRect(0, 0, this.jm.view.size.w, this.jm.view.size.h);
}
resolve(ctx);
}.bind(this)
);
}

draw_lines(ctx) {
return new Promise(
function (resolve, _) {
Expand Down

0 comments on commit 30e671c

Please sign in to comment.