Skip to content

Commit 11d9438

Browse files
committed
SVG: Fixed download functionality
- Worked around CORS CSS error on Chrome on download - Downloaded SVG files now have the relevant styles applied to WordTag lines (they were missing previously) - Downloaded SVG files now include Google font imports for proper display (although the main library uses the Web Font Loader to load fonts instead)
1 parent 4a2cb4c commit 11d9438

File tree

14 files changed

+717
-111
lines changed

14 files changed

+717
-111
lines changed

demo/demo.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.

demo/demo.min.css.map

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

demo/demo.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.

demo/src/demo.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@
7575
}
7676

7777
// Fonts used in the visualisation
78-
// The actual loading of the font happens at the start of `demo.js` via the Web Font Loader
78+
// The actual loading of the font happens at the start of `demo.js` via the Web Font Loader, but we include the Google
79+
// fonts import here as well so that they work properly for downloaded SVGs.
80+
@import url("https://fonts.googleapis.com/css?family=Nunito:400,600,700");
81+
7982
svg, svg text {
8083
font-family: Nunito, futura, helvetica, arial, sans-serif;
8184
font-weight: 600;

dist/tag/js/tag.js

Lines changed: 79 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -41664,7 +41664,7 @@ function () {
4166441664
}); // Draws a line / curly bracket between the Word and this WordTag, if
4166541665
// it's a top tag
4166641666

41667-
this.line = this.svg.path();
41667+
this.line = this.svg.path().addClass("tag-element");
4166841668
this.drawTagLine(); // Centre the WordTag and its line horizontally
4166941669
// (SVG text elements are positioned on the x-axis by their centres)
4167041670

@@ -45195,50 +45195,96 @@ function getCssRules(elements) {
4519545195
var sheets = document.styleSheets;
4519645196
var ret = [];
4519745197
var importRules = [];
45198+
var _iteratorNormalCompletion = true;
45199+
var _didIteratorError = false;
45200+
var _iteratorError = undefined;
4519845201

45199-
for (var i in sheets) {
45200-
var rules = sheets[i].rules || sheets[i].cssRules;
45202+
try {
45203+
for (var _iterator = sheets[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
45204+
var sheet = _step.value;
4520145205

45202-
for (var r in rules) {
45203-
// Include @import rules by default, since we can't be sure if they
45204-
// apply, and since they are generally used for fonts
45205-
if (rules[r].type === CSSRule.IMPORT_RULE) {
45206-
importRules.push(rules[r].cssText);
45207-
continue;
45208-
} // For other types of rules, check against the listed elements
45206+
try {
45207+
var rules = sheet.rules || sheets.cssRules;
45208+
var _iteratorNormalCompletion2 = true;
45209+
var _didIteratorError2 = false;
45210+
var _iteratorError2 = undefined;
4520945211

45212+
try {
45213+
for (var _iterator2 = rules[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
45214+
var rule = _step2.value;
4521045215

45211-
var _iteratorNormalCompletion = true;
45212-
var _didIteratorError = false;
45213-
var _iteratorError = undefined;
45216+
// Include @import rules by default, since we can't be sure if they
45217+
// apply, and since they are generally used for fonts
45218+
if (rule.type === CSSRule.IMPORT_RULE) {
45219+
importRules.push(rule.cssText);
45220+
continue;
45221+
} // For other types of rules, check against the listed elements
4521445222

45215-
try {
45216-
for (var _iterator = elements[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
45217-
var el = _step.value;
45218-
el.matches = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector || el.oMatchesSelector;
4521945223

45220-
if (el.matches(rules[r].selectorText)) {
45221-
ret.push(rules[r].cssText);
45222-
break;
45223-
}
45224-
}
45225-
} catch (err) {
45226-
_didIteratorError = true;
45227-
_iteratorError = err;
45228-
} finally {
45229-
try {
45230-
if (!_iteratorNormalCompletion && _iterator.return != null) {
45231-
_iterator.return();
45224+
var _iteratorNormalCompletion3 = true;
45225+
var _didIteratorError3 = false;
45226+
var _iteratorError3 = undefined;
45227+
45228+
try {
45229+
for (var _iterator3 = elements[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
45230+
var el = _step3.value;
45231+
el.matches = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector || el.oMatchesSelector;
45232+
45233+
if (el.matches(rule.selectorText)) {
45234+
ret.push(rule.cssText);
45235+
break;
45236+
}
45237+
}
45238+
} catch (err) {
45239+
_didIteratorError3 = true;
45240+
_iteratorError3 = err;
45241+
} finally {
45242+
try {
45243+
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
45244+
_iterator3.return();
45245+
}
45246+
} finally {
45247+
if (_didIteratorError3) {
45248+
throw _iteratorError3;
45249+
}
45250+
}
45251+
}
4523245252
}
45253+
} catch (err) {
45254+
_didIteratorError2 = true;
45255+
_iteratorError2 = err;
4523345256
} finally {
45234-
if (_didIteratorError) {
45235-
throw _iteratorError;
45257+
try {
45258+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
45259+
_iterator2.return();
45260+
}
45261+
} finally {
45262+
if (_didIteratorError2) {
45263+
throw _iteratorError2;
45264+
}
4523645265
}
4523745266
}
45267+
} catch (err) {
45268+
// Sometimes we get CORS errors with Chrome and external stylesheets,
45269+
// but we should be all right to keep going
45270+
console.log("Warning:", err);
4523845271
}
45239-
}
45240-
} // Import rules have to be at the top of the styles list
45272+
} // Import rules have to be at the top of the styles list
4524145273

45274+
} catch (err) {
45275+
_didIteratorError = true;
45276+
_iteratorError = err;
45277+
} finally {
45278+
try {
45279+
if (!_iteratorNormalCompletion && _iterator.return != null) {
45280+
_iterator.return();
45281+
}
45282+
} finally {
45283+
if (_didIteratorError) {
45284+
throw _iteratorError;
45285+
}
45286+
}
45287+
}
4524245288

4524345289
return _lodash.default.uniq(importRules.concat(ret));
4524445290
}

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.

docs/WordTag.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ <h4 class="name" id="textWidth">
437437
<dd class="tag-source">
438438
<ul class="dummy">
439439
<li>
440-
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line178">line 178</a>
440+
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line179">line 179</a>
441441
</li>
442442
</ul>
443443
</dd>
@@ -616,7 +616,7 @@ <h4 class="name" id="centre">
616616
<dd class="tag-source">
617617
<ul class="dummy">
618618
<li>
619-
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line92">line 92</a>
619+
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line93">line 93</a>
620620
</li>
621621
</ul>
622622
</dd>
@@ -707,7 +707,7 @@ <h4 class="name" id="remove">
707707
<dd class="tag-source">
708708
<ul class="dummy">
709709
<li>
710-
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line106">line 106</a>
710+
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line107">line 107</a>
711711
</li>
712712
</ul>
713713
</dd>
@@ -797,7 +797,7 @@ <h4 class="name" id="drawTagLine">
797797
<dd class="tag-source">
798798
<ul class="dummy">
799799
<li>
800-
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line115">line 115</a>
800+
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line116">line 116</a>
801801
</li>
802802
</ul>
803803
</dd>
@@ -932,7 +932,7 @@ <h5>Parameters:</h5>
932932
<dd class="tag-source">
933933
<ul class="dummy">
934934
<li>
935-
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line144">line 144</a>
935+
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line145">line 145</a>
936936
</li>
937937
</ul>
938938
</dd>
@@ -1021,7 +1021,7 @@ <h4 class="name" id="boxWidth">
10211021
<dd class="tag-source">
10221022
<ul class="dummy">
10231023
<li>
1024-
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line170">line 170</a>
1024+
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line171">line 171</a>
10251025
</li>
10261026
</ul>
10271027
</dd>
@@ -1110,7 +1110,7 @@ <h4 class="name" id="drawBbox">
11101110
<dd class="tag-source">
11111111
<ul class="dummy">
11121112
<li>
1113-
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line225">line 225</a>
1113+
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line226">line 226</a>
11141114
</li>
11151115
</ul>
11161116
</dd>
@@ -1199,7 +1199,7 @@ <h4 class="name" id="drawTextBbox">
11991199
<dd class="tag-source">
12001200
<ul class="dummy">
12011201
<li>
1202-
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line237">line 237</a>
1202+
<a href="components_word-tag.js.html">components/word-tag.js</a>, <a href="components_word-tag.js.html#line238">line 238</a>
12031203
</li>
12041204
</ul>
12051205
</dd>

docs/components_word-tag.js.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ <h1 class="page-title">
165165

166166
// Draws a line / curly bracket between the Word and this WordTag, if
167167
// it's a top tag
168-
this.line = this.svg.path();
168+
this.line = this.svg.path()
169+
.addClass("tag-element");
169170
this.drawTagLine();
170171

171172
// Centre the WordTag and its line horizontally

docs/index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,15 @@ <h1>Citing TAG</h1><p>If you use TAG in your work, please use the following cita
124124
}</code></pre><h2>Write-up</h2><p>A paper describing TAG was accepted to <a href="http://lrec2018.lrec-conf.org/en/conference-programme/accepted-papers/">LREC'18</a>. A pre-print can be found at <a href="https://arxiv.org/abs/1711.00529">https://arxiv.org/abs/1711.00529</a></p>
125125
<h2>Installation</h2><p>TAG can be built and installed using <a href="https://docs.npmjs.com/getting-started/installing-node"><code>npm</code></a>.</p>
126126
<h3>Via <code>npm</code></h3><pre class="prettyprint source"><code>npm install git+https://github.com/CreativeCodingLab/TextAnnotationGraphs.git</code></pre><h2>Usage</h2><p>To use TAG with your own applications, first include the library in your script:</p>
127-
<h4>Browserify (CommonJS)</h4><pre class="prettyprint source"><code>const TAG = require(&quot;text-annotation-graphs&quot;);</code></pre><h4>ES6</h4><pre class="prettyprint source"><code>import TAG from &quot;text-annotation-graphs&quot;;</code></pre><p>Then initialise the visualisation on an element, optionally specifying the initial data set to load. For more details, consult the full API documentation.</p>
127+
<h4>Browserify (CommonJS)</h4><pre class="prettyprint source"><code>const TAG = require(&quot;text-annotation-graphs&quot;);</code></pre><h4>ES6</h4><pre class="prettyprint source"><code>import TAG from &quot;text-annotation-graphs&quot;;</code></pre><p>Then initialise the visualisation on an element, optionally specifying the initial data set to load and any overrides to the default options. For more details, consult the full API documentation.</p>
128128
<pre class="prettyprint source"><code>const graph = TAG.tag({
129129
container: $container,
130-
data: &lt;...>,
131-
format: &quot;json&quot;
130+
data: {...},
131+
format: &quot;odin&quot;,
132+
options: {...}
132133
});</code></pre><h2>Development</h2><p>Tasks are managed via <a href="https://docs.npmjs.com/misc/scripts"><code>npm</code> scripts</a> and the <a href="https://github.com/pawelgalazka/runjs"><code>runjs</code> build tool</a>. The most commonly used tasks are listed in <code>package.json</code>, and details for the various sub-tasks can be found in <code>runfile.js</code>.</p>
133134
<h3>Demo</h3><p>After cloning the repository and installing the project dependencies via <code>npm install</code>, you can run the interactive demo using <code>npm run demo</code> and directing your browser to <code>localhost:8080</code>.</p>
135+
<p>To run the demo on a different port, set the <code>PORT</code> environmental variable. For example, running <code>PORT=9000 npm run demo</code> will start the demo server on <code>localhost:9000</code> instead.</p>
134136
<h3>Building the source</h3><p>TAG is written in ES6, and uses <a href="https://sass-lang.com/">Sass</a> for its styles.</p>
135137
<p>Assuming you've cloned the repository, simply run <code>npm install &amp;&amp; npm run build</code> to install dependencies and transpile the source to ES2015.</p>
136138
<h3>Live monitoring of changes</h3><p>For convenience, you can monitor changes to the library's sources (css + js) with the following <code>npm</code> task: </p>

docs/module-Util.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ <h5>Parameters:</h5>
458458
<dd class="tag-source">
459459
<ul class="dummy">
460460
<li>
461-
<a href="util.js.html">util.js</a>, <a href="util.js.html#line66">line 66</a>
461+
<a href="util.js.html">util.js</a>, <a href="util.js.html#line73">line 73</a>
462462
</li>
463463
</ul>
464464
</dd>

0 commit comments

Comments
 (0)