@@ -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