Skip to content

Commit b975472

Browse files
committed
Fixes and enhancements
- Demo/Options: New select menus in UI demo options pane for selecting between categories of top/bottom Links - Links: `.visible` attribute now indicates whether or not a Link has been drawn onto the visualisation, not whether it *should* be. - Links: Bugfix to slotting algorithm: Previously, Links with nested Links might have occupied too low a slot - Row: Added configuration option for specifying additional top padding for Link labels (it is not trivial to get the exact amount of extra height needed from the elements directly) - Taxonomy: Taxonomy manager will now revert to configured default colours when the visualisation is cleared - Odin: Now parses RelationMentions properly
1 parent 556aac4 commit b975472

File tree

13 files changed

+1530
-472
lines changed

13 files changed

+1530
-472
lines changed

demo/data/sentence-1-odin.json

Lines changed: 662 additions & 0 deletions
Large diffs are not rendered by default.

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/index.html

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ <h4>Extended UI example</h4>
9696
href="#">
9797
Odin format test (test-odin.json)
9898
</a>
99+
<a class="dropdown-item tag-dataset" data-path="data/sentence-1-odin.json" data-format="odin"
100+
href="#">
101+
Sentence 1 (sentence-1-odin.json)
102+
</a>
99103
</div>
100104
</div>
101105

@@ -163,15 +167,30 @@ <h5 class="modal-title" id="options-title">Options</h5>
163167

164168
<div class="modal-body">
165169
<div class="p-3">
170+
Show the following category of top links:
171+
<select id="tag-option-top-links" class="custom-select mb-3">
172+
<!-- Options will be added at run time in `demo.js` based on the categories available in the
173+
data loaded -->
174+
</select>
175+
176+
Show the following category of bottom links:
177+
<select id="tag-option-bottom-links" class="custom-select mb-3">
178+
<!-- Options will be added at run time in `demo.js` based on the categories available in the
179+
data loaded -->
180+
</select>
181+
166182
<div class="custom-control custom-checkbox">
167-
<input type="checkbox" class="custom-control-input" id="tag-option-syntax">
168-
<label class="custom-control-label" for="tag-option-syntax">Show syntax tree</label>
183+
<input type="checkbox" class="custom-control-input" id="tag-option-top-links-on-move">
184+
<label class="custom-control-label" for="tag-option-top-links-on-move">
185+
Show top links when moving words
186+
</label>
169187
</div>
170188

171189
<div class="custom-control custom-checkbox">
172-
<input type="checkbox" class="custom-control-input" id="tag-option-links-on-move">
173-
<label class="custom-control-label" for="tag-option-links-on-move">Show syntax links when moving
174-
words</label>
190+
<input type="checkbox" class="custom-control-input" id="tag-option-bottom-links-on-move">
191+
<label class="custom-control-label" for="tag-option-bottom-links-on-move">
192+
Show bottom links when moving words
193+
</label>
175194
</div>
176195
</div>
177196

demo/src/demo.js

Lines changed: 79 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,18 @@ $(async () => {
7070

7171
// Data can be loaded after initialisation using the `.loadData()` function,
7272
// or from a remote URL via the asynchronous `.loadUrlAsync()` function.
73-
await uiTag.loadUrlAsync("data/test-brat.ann", "brat");
73+
await uiTag.loadUrlAsync("data/sentence-1-odin.json", "odin");
7474

7575
// --------------------------------------------------------------------------
7676

7777
// Data from an external URL can also be loaded into the visualisation
7878
// using the `.loadUrlAsync()` function. The data will be read and displayed
7979
// asynchronously.
80-
$("#tag-change-dataset").on("click", ".tag-dataset", (event) => {
80+
$("#tag-change-dataset").on("click", ".tag-dataset", async (event) => {
8181
event.preventDefault();
8282
const $link = $(event.target);
83-
return uiTag.loadUrlAsync($link.data("path"), $link.data("format"));
83+
await uiTag.loadUrlAsync($link.data("path"), $link.data("format"));
84+
refreshLinkCategories();
8485
});
8586

8687
// --------------------------------------------------------------------------
@@ -105,6 +106,7 @@ $(async () => {
105106
// (In that order: We need to load the files before resetting the
106107
// form, or the reference to the FileList gets lost)
107108
await uiTag.loadFilesAsync(files, format);
109+
refreshLinkCategories();
108110

109111
const $modal = $("#tag-upload");
110112

@@ -118,30 +120,90 @@ $(async () => {
118120

119121
// --------------------------------------------------------------------------
120122

121-
// The `.setOption()` function can be used to change various advanced
122-
// options. The visualisation will need to be redrawn to show any
123-
// changes, if applicable.
124-
const $optionSyntax = $("#tag-option-syntax");
125-
$optionSyntax
126-
.prop("checked", uiTag.getOption("showSyntax"))
123+
// The `.getOption()` and `.setOption()` function can be used to change
124+
// various advanced options.
125+
// There are also some direct functions available that directly modify the
126+
// visualisation, like `.setTopLinkCategory()` and `.setBottomLinkCategory()`
127+
128+
129+
/**
130+
* The categories available for the top and bottom Links depends on the
131+
* currently loaded data, so we call for a refresh any time the data changes
132+
*/
133+
function refreshLinkCategories() {
134+
// [Categories for top Links]
135+
// We will populate the select menu and add a change handler
136+
const $optionTopLinks = $("#tag-option-top-links")
137+
.empty()
138+
.append($("<option value='none'>None</option>"));
139+
140+
const currentTop = uiTag.getOption("topLinksCategory");
141+
for (const category of uiTag.getTopLinkCategories()) {
142+
const $option = $("<option></option>")
143+
.attr("value", category)
144+
.text(_.upperFirst(category));
145+
146+
if (category === currentTop) {
147+
$option.prop("selected", true);
148+
}
149+
150+
$optionTopLinks.append($option);
151+
}
152+
$optionTopLinks.on("change", () => {
153+
uiTag.setTopLinkCategory($optionTopLinks.val());
154+
});
155+
156+
// [Categories for bottom Links]
157+
// We will populate the select menu and add a change handler
158+
const $optionBottomLinks = $("#tag-option-bottom-links")
159+
.empty()
160+
.append($("<option value='none'>None</option>"));
161+
162+
const currentBottom = uiTag.getOption("bottomLinksCategory");
163+
for (const category of uiTag.getBottomLinkCategories()) {
164+
const $option = $("<option></option>")
165+
.attr("value", category)
166+
.text(_.upperFirst(category));
167+
168+
if (category === currentBottom) {
169+
$option.prop("selected", true);
170+
}
171+
172+
$optionBottomLinks.append($option);
173+
}
174+
$optionBottomLinks.on("change", () => {
175+
uiTag.setBottomLinkCategory($optionBottomLinks.val());
176+
});
177+
}
178+
179+
refreshLinkCategories();
180+
181+
const $optionTopLinksOnMove = $("#tag-option-top-links-on-move");
182+
$optionTopLinksOnMove
183+
.prop("checked", uiTag.getOption("showTopLinksOnMove"))
127184
.on("change", () => {
128-
uiTag.setOption("showSyntax", $optionSyntax[0].checked);
129-
uiTag.redraw();
185+
uiTag.setOption(
186+
"showTopLinksOnMove",
187+
$optionTopLinksOnMove[0].checked
188+
);
130189
});
131190

132-
const $optionLinksOnMove = $("#tag-option-links-on-move");
133-
$optionLinksOnMove
134-
.prop("checked", uiTag.getOption("showLinksOnMove"))
191+
const $optionBottomLinksOnMove = $("#tag-option-bottom-links-on-move");
192+
$optionBottomLinksOnMove
193+
.prop("checked", uiTag.getOption("showBottomLinksOnMove"))
135194
.on("change", () => {
136-
uiTag.setOption("showLinksOnMove", $optionLinksOnMove[0].checked);
195+
uiTag.setOption(
196+
"showBottomLinksOnMove",
197+
$optionBottomLinksOnMove[0].checked
198+
);
137199
});
138200

139201
// --------------------------------------------------------------------------
140202

141-
// The `.exportFile()` function can be used to save the current
203+
// The `.exportSvg()` function can be used to save the current
142204
// visualisation as an SVG file
143205
$("#tag-download").on("click", () => {
144-
uiTag.exportFile();
206+
uiTag.exportSvg();
145207
});
146208

147209
// --------------------------------------------------------------------------

0 commit comments

Comments
 (0)