1414 < title > YASGUI Graph Plugin Demo</ title >
1515
1616 <!-- YASGUI CSS -->
17- < link rel ="stylesheet " href ="https://cdn.jsdelivr.net/npm/@zazuko/yasgui@4/build/yasgui.min.css ">
17+ < link rel ="stylesheet " href ="https://cdn.jsdelivr.net/npm/@zazuko/yasgui@4.6.1 /build/yasgui.min.css ">
1818
1919 <!-- Font Awesome for icons -->
2020 < link rel ="stylesheet " href ="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css ">
@@ -136,7 +136,7 @@ <h2 onclick="toggleInstructions()">
136136 < div id ="yasgui "> </ div >
137137
138138 <!-- YASGUI JavaScript -->
139- < script src ="https://cdn.jsdelivr.net/npm/@zazuko/yasgui@4/build/yasgui.min.js "> </ script >
139+ < script src ="https://cdn.jsdelivr.net/npm/@zazuko/yasgui@4.6.1 /build/yasgui.min.js "> </ script >
140140
141141 <!-- vis-network (required dependency) -->
142142 < script src ="
https://unpkg.com/[email protected] /standalone/umd/vis-network.min.js "
> </ script > @@ -158,88 +158,36 @@ <h2 onclick="toggleInstructions()">
158158
159159 // Initialize YASGUI after plugin is registered
160160 const yasgui = new Yasgui ( document . getElementById ( 'yasgui' ) , {
161- endpoint : 'http://localhost:3030/g' ,
161+ // Set the SPARQL endpoint
162+ requestConfig : {
163+ endpoint : 'http://localhost:3030/g' ,
164+ } ,
165+ yasr : {
166+ pluginOrder : [ 'Table' , 'Response' , 'Graph' ] ,
167+ defaultPlugin : 'Graph' ,
168+ } ,
162169 copyEndpointOnNewTab : false ,
163170 } ) ;
164171
165- // Helper to create mock results from CONSTRUCT query
166- function createMockResults ( query ) {
167- const bindings = [ ] ;
168-
169- // Parse triples from CONSTRUCT clause
170- const constructMatch = query . match ( / C O N S T R U C T \s * { ( [ ^ } ] + ) } / i) ;
171- if ( ! constructMatch ) return { getBindings : ( ) => [ ] } ;
172-
173- const constructBody = constructMatch [ 1 ] ;
174- const tripleLines = constructBody . split ( '\n' )
175- . map ( line => line . trim ( ) )
176- . filter ( line => line && ! line . startsWith ( 'PREFIX' ) ) ;
177-
178- tripleLines . forEach ( line => {
179- // Simple triple parsing (subject predicate object .)
180- const match = line . match ( / ^ ( [ ^ \s ] + ) \s + ( [ ^ \s ] + ) \s + ( .+ ?) \s * \. ? \s * $ / ) ;
181- if ( match ) {
182- const [ , subject , predicate , objectStr ] = match ;
183-
184- // Parse object
185- let object ;
186- if ( objectStr . startsWith ( '"' ) ) {
187- // Literal
188- const literalMatch = objectStr . match ( / " ( [ ^ " ] + ) " (?: \^ \^ < ( [ ^ > ] + ) > ) ? / ) ;
189- if ( literalMatch ) {
190- object = {
191- value : literalMatch [ 1 ] ,
192- type : 'literal' ,
193- datatype : literalMatch [ 2 ]
194- } ;
195- } else {
196- object = { value : objectStr . replace ( / " / g, '' ) , type : 'literal' } ;
197- }
198- } else {
199- // URI or blank node
200- object = {
201- value : objectStr . replace ( / < | > / g, '' ) ,
202- type : objectStr . startsWith ( '_:' ) ? 'bnode' : 'uri'
203- } ;
204- }
205-
206- bindings . push ( {
207- subject : { value : subject . replace ( / < | > / g, '' ) , type : subject . startsWith ( '_:' ) ? 'bnode' : 'uri' } ,
208- predicate : { value : predicate . replace ( / < | > / g, '' ) , type : 'uri' } ,
209- object : object
210- } ) ;
211- }
212- } ) ;
213-
214- return {
215- getBindings : ( ) => bindings ,
216- getVariables : ( ) => ( { prefixes : {
217- 'ex' : 'http://example.org/' ,
218- 'rdf' : 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' ,
219- 'rdfs' : 'http://www.w3.org/2000/01/rdf-schema#' ,
220- 'owl' : 'http://www.w3.org/2002/07/owl#' ,
221- 'xsd' : 'http://www.w3.org/2001/XMLSchema#'
222- } } ) ,
223- getResponseTime : ( ) => 0 ,
224- getType : ( ) => 'construct' ,
225- getOriginalResponseAsString : ( ) => '' ,
226- getOriginalResponse : ( ) => null ,
227- getError : ( ) => null ,
228- getContentType : ( ) => 'text/turtle'
229- } ;
230- }
231-
232172 // Add sample query tabs
233173 const tabs = [
234- { name : 'Basic Graph' , query : queries . basic } ,
235174 { name : 'Ontology' , query : queries . ontology } ,
236175 { name : 'Blank Nodes' , query : queries . blankNodes } ,
237176 { name : 'Multiple Edges' , query : queries . multiplePredicates } ,
238- { name : 'DESCRIBE Query' , query : queries . describe }
177+ { name : 'DESCRIBE Query' , query : queries . describe } ,
178+ { name : 'Basic Graph' , query : queries . basic } ,
239179 ] ;
240180
241- // Clear default tab
242- yasgui . getTab ( ) . close ( ) ;
181+ // Close all existing tabs
182+ let tab ;
183+ while ( ( tab = yasgui . getTab ( ) ) != null ) {
184+ try {
185+ tab . close ( ) ;
186+ } catch ( e ) {
187+ console . error ( 'Failed to close tab:' , e ) ;
188+ break ;
189+ }
190+ }
243191
244192 // Add sample tabs
245193 tabs . forEach ( ( tab , index ) => {
@@ -249,14 +197,7 @@ <h2 onclick="toggleInstructions()">
249197 name : tab . name ,
250198 yasqe : { value : tab . query }
251199 }
252- ) ;
253-
254- // Simulate query results for demo (since we have no real endpoint)
255- setTimeout ( ( ) => {
256- // Mock CONSTRUCT results
257- yasguiTab . yasr . results = createMockResults ( tab . query ) ;
258- yasguiTab . yasr . draw ( ) ;
259- } , 100 ) ;
200+ ) ;
260201 } ) ;
261202 </ script >
262203</ body >
0 commit comments