Skip to content

Commit dd7c13a

Browse files
authored
Export svg (#33)
* WIP: add option to export svg needs to move CSS styling into SVG inline styles * WIP svg export - everything except font * font export corrected (assuming internet connection) - using @import
1 parent b41c2d0 commit dd7c13a

File tree

6 files changed

+37
-2
lines changed

6 files changed

+37
-2
lines changed

dist/tag/css/tag.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/tag/js/tag.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<button id="custom-annotation">Custom annotation</button>
2828
<button id="taxonomy-toggle">Taxonomy</button>
2929
<button id="options-toggle">Options</button>
30+
<button id="download-button">Download (CTRL+S)<a id="download" download></a></button>
3031
</header>
3132

3233
<div id="input-modal" class="modal">

src/css/app.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import url(http://fonts.googleapis.com/css?family=Nunito:400,600);
2+
13
#fill {
24
/* ensure body takes up entire window */
35
position:absolute;

src/js/main.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ import Tooltip from './managers/tooltip.js';
99
import Word from './components/word.js';
1010
import WordCluster from './components/wordcluster.js';
1111
import Link from './components/link.js';
12+
import load from './xhr.js';
1213

1314
const Main = (function() {
1415
// classes
1516
let parser, lm, rm, tm;
1617

18+
let css;
19+
1720
// main svg element
1821
let svg;
1922

@@ -49,6 +52,9 @@ const Main = (function() {
4952
tm = new Taxonomy('taxonomy');
5053
tree = new TreeLayout('#tree', svg);
5154

55+
load('/dist/tag/css/tag.min.css')
56+
.then((text) => css = text);
57+
5258
// load and render initial dataset by default
5359
changeDataset();
5460

@@ -241,6 +247,30 @@ const Main = (function() {
241247
document.body.addEventListener('dragenter', (e) => e.preventDefault());
242248
document.body.addEventListener('dragover', (e) => e.preventDefault());
243249
document.body.addEventListener('drop', uploadFile);
250+
251+
252+
function exportFile() {
253+
254+
let exportedSVG = svg.svg();
255+
console.log(css);
256+
let i = exportedSVG.indexOf('</defs>');
257+
exportedSVG = exportedSVG.slice(0, i)
258+
+ '<style>' + css + 'text{text-anchor:middle;}</style>'
259+
+ exportedSVG.slice(i);
260+
let a = document.getElementById('download');
261+
a.setAttribute('href', 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(exportedSVG));
262+
a.setAttribute('download', 'tag.svg');
263+
a.click();
264+
}
265+
document.getElementById('download-button').onclick = exportFile;
266+
document.addEventListener('keydown', (e) => {
267+
let key = e.keyCode || e.which;
268+
let ctrl = e.ctrlKey || (e.metaKey && !e.ctrlKey);
269+
if (key === 83 && ctrl) {
270+
e.preventDefault();
271+
exportFile();
272+
}
273+
})
244274
}
245275

246276
/* read an externally loaded file */

src/js/managers/labelmanager.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Link from '../components/link.js';
2+
13
module.exports = (function() {
24
let _svg;
35
let activeObject = null;

0 commit comments

Comments
 (0)