@@ -9,11 +9,14 @@ import Tooltip from './managers/tooltip.js';
99import Word from './components/word.js' ;
1010import WordCluster from './components/wordcluster.js' ;
1111import Link from './components/link.js' ;
12+ import load from './xhr.js' ;
1213
1314const 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 */
0 commit comments