Skip to content

Commit

Permalink
update demo and code format
Browse files Browse the repository at this point in the history
  • Loading branch information
hizzgdev committed Sep 29, 2023
1 parent c092df4 commit 8617129
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default [
banner: '/**\n* @license BSD-3-Clause\n* @copyright 2014-2023 hizzgdev@163.com\n*\n* Project Home:\n* https://github.com/hizzgdev/jsmind/\n*/',
sourcemap: true,
globals: {
jsmind: 'jsMind',
'jsmind': 'jsMind',
'dom-to-image': 'domtoimage',
},
},
Expand Down
4 changes: 4 additions & 0 deletions example/2_features.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
type="text/javascript"
src="//cdn.jsdelivr.net/npm/jsmind/es6/jsmind.draggable-node.js"
></script>
<script
type="text/javascript"
src="//cdn.jsdelivr.net/npm/dom-to-image@2.6.0/dist/dom-to-image.min.js"
></script>
<script
type="text/javascript"
src="//cdn.jsdelivr.net/npm/jsmind/es6/jsmind.screenshot.js"
Expand Down
2 changes: 1 addition & 1 deletion example/2_features.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function open_ajax() {
}

function screen_shot() {
_jm.screenshot.shootDownload();
_jm.shoot();
}

function show_data() {
Expand Down
4 changes: 4 additions & 0 deletions example/2_features_cn.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@
type="text/javascript"
src="//jsd.onmicrosoft.cn/npm/jsmind/es6/jsmind.draggable-node.js"
></script>
<script
type="text/javascript"
src="//jsd.onmicrosoft.cn/npm/dom-to-image@2.6.0/dist/dom-to-image.min.js"
></script>
<script
type="text/javascript"
src="//jsd.onmicrosoft.cn/npm/jsmind/es6/jsmind.screenshot.js"
Expand Down
31 changes: 16 additions & 15 deletions src/plugins/jsmind.screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const DEFAULT_OPTIONS = {
watermark: {
left: $.w.location,
right: 'https://github.com/hizzgdev/jsmind',
}
},
};

class JmScreenshot {
Expand All @@ -38,10 +38,6 @@ class JmScreenshot {
this.options = opts;
}

shootDownload() {
this.shoot();
}

shoot() {
let c = this.create_canvas();
let ctx = c.getContext('2d');
Expand All @@ -50,8 +46,7 @@ class JmScreenshot {
.then(() => this.draw_nodes(ctx))
.then(() => this.draw_watermark(c, ctx))
.then(() => this.download(c))
.then(() => this.clear(c))

.then(() => this.clear(c));
}

create_canvas() {
Expand All @@ -67,17 +62,23 @@ class JmScreenshot {
}

draw_lines(ctx) {
return new Promise(function (resolve, _) {
this.jm.view.graph.copy_to(ctx, function () {
resolve(ctx);
})
}.bind(this));
return new Promise(
function (resolve, _) {
this.jm.view.graph.copy_to(ctx, function () {
resolve(ctx);
});
}.bind(this)
);
}

draw_nodes(ctx) {
return domtoimage.toSvg(this.jm.view.e_nodes)
return domtoimage
.toSvg(this.jm.view.e_nodes)
.then(this.load_image)
.then(function (img) { ctx.drawImage(img, 0, 0); return ctx });
.then(function (img) {
ctx.drawImage(img, 0, 0);
return ctx;
});
}

draw_watermark(c, ctx) {
Expand All @@ -92,7 +93,7 @@ class JmScreenshot {
ctx.textAlign = 'right';
ctx.fillText(this.options.watermark.right, c.width - 5.5, c.height - 2.5);
}
return ctx
return ctx;
}

load_image(url) {
Expand Down

0 comments on commit 8617129

Please sign in to comment.