Skip to content

Commit 0756be8

Browse files
committed
Initial implementation of screenshot feature
1 parent f019ff9 commit 0756be8

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed

gulpfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ function dist() {
270270
'./js/vendor/three.js',
271271
'./js/vendor/three.min.js',
272272
'./js/vendor/webm-writer-0.1.1.js',
273+
'./js/screenshot.js',
273274

274275
// everything else
275276
'./package.json', // For NW.js

index.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ <h4>Workspace</h4>
441441
<div class="log-workspace-selection"></div>
442442
</li>
443443
</ul>
444-
<div class="graph-row">
444+
<div id="screenshot-frame" class="graph-row">
445445
<div class="log-graph">
446446
<video></video>
447447
<canvas width="200" height="100" id="graphCanvas"></canvas>
@@ -2200,6 +2200,13 @@ <h4 class="modal-title">Shortcut Keys</h4>
22002200
</span>
22012201
<div class="description">Special Case, clear all bookmarks</div>
22022202
</li>
2203+
<li>
2204+
<span class="keys">
2205+
<div class="key">Alt</div>
2206+
<div class="key">S</div>
2207+
</span>
2208+
<div class="description">Save current graph to PNG file</div>
2209+
</li>
22032210
</ul>
22042211
</div>
22052212
</div>
@@ -2730,6 +2737,8 @@ <h4 class="modal-title">Advanced User Settings</h4>
27302737
</div>
27312738
</div>
27322739
<!-- Scripts -->
2740+
<script src="node_modules/html2canvas/dist/html2canvas.min.js"></script>
2741+
<script src="js/screenshot.js"></script>
27332742
<script src="js/complex.js"></script>
27342743
<script src="js/real.js"></script>
27352744
<script src="js/vendor/jquery-1.11.3.min.js"></script>

js/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,8 @@ function BlackboxLogViewer() {
18961896
if(!(shifted)) {
18971897
toggleOverrideStatus('graphSmoothOverride', 'has-smoothing-override' );
18981898
e.preventDefault();
1899+
} else if (e.altKey) {
1900+
makeScreenshot();
18991901
}
19001902
} catch(e) {
19011903
console.log('Smoothing override toggle feature not functioning');

js/screenshot.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
3+
function makeScreenshot() {
4+
let el = document.querySelector("#screenshot-frame"),
5+
elStyle = getComputedStyle(el),
6+
options = {
7+
/*
8+
The element that contains the graph has `position: fixed` set with `top: 60px`.
9+
This option ensures, that the image content won't overflow to the bottom.
10+
*/
11+
scrollY: -1 * parseInt(elStyle.top),
12+
};
13+
html2canvas(el, options).then(canvas => {
14+
window.canv = canvas;
15+
let anchor = document.createElement("a");
16+
anchor.download = "graph-screenshot.png";
17+
anchor.href = canvas.toDataURL();
18+
anchor.click();
19+
});
20+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"author": "The Betaflight open source project.",
2424
"license": "GPL-3.0",
2525
"dependencies": {
26+
"html2canvas": "^1.0.0-rc.5",
2627
"lodash": "^4.17.13"
2728
},
2829
"devDependencies": {

yarn.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ balanced-match@^1.0.0:
365365
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
366366
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
367367

368+
base64-arraybuffer@^0.2.0:
369+
version "0.2.0"
370+
resolved "https://registry.yarnpkg.com/base64-arraybuffer/-/base64-arraybuffer-0.2.0.tgz#4b944fac0191aa5907afe2d8c999ccc57ce80f45"
371+
integrity sha512-7emyCsu1/xiBXgQZrscw/8KPRT44I4Yq9Pe6EGs3aPRTsWuggML1/1DTuZUuIaJPIm1FTDUVXl4x/yW8s0kQDQ==
372+
368373
base64-js@^1.0.2, base64-js@^1.2.3:
369374
version "1.3.1"
370375
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1"
@@ -812,6 +817,13 @@ crypto-random-string@^1.0.0:
812817
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e"
813818
integrity sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4=
814819

820+
css-line-break@1.1.1:
821+
version "1.1.1"
822+
resolved "https://registry.yarnpkg.com/css-line-break/-/css-line-break-1.1.1.tgz#d5e9bdd297840099eb0503c7310fd34927a026ef"
823+
integrity sha512-1feNVaM4Fyzdj4mKPIQNL2n70MmuYzAXZ1aytlROFX1JsOo070OsugwGjj7nl6jnDJWHDM8zRZswkmeYVWZJQA==
824+
dependencies:
825+
base64-arraybuffer "^0.2.0"
826+
815827
d@1:
816828
version "1.0.1"
817829
resolved "https://registry.yarnpkg.com/d/-/d-1.0.1.tgz#8698095372d58dbee346ffd0c7093f99f8f9eb5a"
@@ -1754,6 +1766,13 @@ hosted-git-info@^2.1.4:
17541766
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.3.tgz#622638609162d788c6c7cc8c491442e7bbdff03e"
17551767
integrity sha512-gSxJXCMa4wZSq9YqCxcVWWtXw63FNFSx9XmDfet4IJg0vuiwxAdiLqbgxZty2/X5gHHd9F36v4VmEcAlZMgnGw==
17561768

1769+
html2canvas@^1.0.0-rc.5:
1770+
version "1.0.0-rc.5"
1771+
resolved "https://registry.yarnpkg.com/html2canvas/-/html2canvas-1.0.0-rc.5.tgz#4ee3cac9f6e20a0fa0c2f35a6f99c960ae7ec4c1"
1772+
integrity sha512-DtNqPxJNXPoTajs+lVQzGS1SULRI4GQaROeU5R41xH8acffHukxRh/NBVcTBsfCkJSkLq91rih5TpbEwUP9yWA==
1773+
dependencies:
1774+
css-line-break "1.1.1"
1775+
17571776
http-signature@~1.2.0:
17581777
version "1.2.0"
17591778
resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.2.0.tgz#9aecd925114772f3d95b65a60abb8f7c18fbace1"

0 commit comments

Comments
 (0)