Version: 1.0.0
Date: 2025-12-05
Audience: Developers integrating SPARQL CONSTRUCT graph visualization
- Node.js: v16+ (for development)
- Browser: Latest Chrome, Firefox, Safari, or Edge
- YASGUI/YASR: v4.x (@zazuko/yasgui)
- Basic knowledge: JavaScript ES2018+, SPARQL, RDF
npm install yasgui-graph-pluginimport GraphPlugin from 'yasgui-graph-plugin';
import Yasgui from '@zazuko/yasgui';
import '@zazuko/yasgui/build/yasgui.min.css';
// Register plugin
Yasgui.Yasr.registerPlugin('graph', GraphPlugin);
// Create YASGUI instance
const yasgui = new Yasgui(document.getElementById('yasgui'), {
requestConfig: { endpoint: 'https://your-sparql-endpoint.example/sparql' },
yasqe: { /* YASQE config */ },
yasr: {
defaultPlugin: 'graph' // Optional: Set as default visualization
}
});<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/@zazuko/yasgui/build/yasgui.min.css"/>
<style>
#yasgui { height: 100vh; }
</style>
</head>
<body>
<div id="yasgui"></div>
<script src="https://unpkg.com/@zazuko/yasgui/build/yasgui.min.js"></script>
<script src="https://unpkg.com/yasgui-graph-plugin/dist/yasgui-graph-plugin.min.js"></script>
<script>
// Plugin auto-registers when loaded
const yasgui = new Yasgui(document.getElementById('yasgui'), {
requestConfig: { endpoint: 'https://your-sparql-endpoint.example/sparql' }
});
</script>
</body>
</html>The plugin automatically activates for SPARQL CONSTRUCT queries that return triples:
PREFIX ex: <http://example.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
CONSTRUCT {
?person rdf:type ex:Person .
?person ex:name ?name .
?person ex:knows ?friend .
}
WHERE {
?person rdf:type ex:Person .
?person ex:name ?name .
OPTIONAL { ?person ex:knows ?friend }
}
LIMIT 100- Execute the query in YASGUI
- Click the "Graph" tab in the results panel
- Interact with the visualization:
- Zoom: Mouse wheel or pinch gesture
- Pan: Click and drag on empty space
- Drag nodes: Click and drag individual nodes
- Inspect: Hover over nodes/edges to see tooltips
PREFIX schema: <https://schema.org/>
CONSTRUCT {
?person a schema:Person .
?person schema:name ?name .
?person schema:worksFor ?org .
?org a schema:Organization .
?org schema:name ?orgName .
}
WHERE {
?person a schema:Person ;
schema:name ?name ;
schema:worksFor ?org .
?org schema:name ?orgName .
}
LIMIT 50PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
CONSTRUCT {
?class rdf:type rdfs:Class .
?class rdfs:label ?label .
?class rdfs:subClassOf ?parent .
}
WHERE {
?class rdf:type rdfs:Class .
OPTIONAL { ?class rdfs:label ?label }
OPTIONAL { ?class rdfs:subClassOf ?parent }
}
LIMIT 100PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
CONSTRUCT {
dbr:Paris dbo:country ?country .
?country dbo:capital dbr:Paris .
dbr:Paris dbo:populationTotal ?population .
}
WHERE {
dbr:Paris dbo:country ?country .
OPTIONAL { dbr:Paris dbo:populationTotal ?population }
}// Register plugin with lower priority (further left in tab bar)
class CustomGraphPlugin extends GraphPlugin {
constructor(yasr) {
super(yasr);
this.priority = 10; // Default is 20
}
}
Yasgui.Yasr.registerPlugin('graph', CustomGraphPlugin);Modify GraphPlugin class to customize vis-network options:
class CustomGraphPlugin extends GraphPlugin {
getNetworkOptions() {
return {
...super.getNetworkOptions(),
physics: {
enabled: true,
stabilization: { iterations: 300 }, // More iterations for better layout
solver: 'forceAtlas2' // Different physics engine
},
nodes: {
shape: 'circle', // Change node shape
font: { size: 16, color: '#000000' }
}
};
}
}Problem: Graph tab doesn't appear after executing CONSTRUCT query.
Solution: Ensure query returns triples in bindings format with subject, predicate, object columns:
// Check results format in browser console
console.log(yasgui.getTab().yasr.results.getBindings());
// Should return: [{subject: {value: '...', type: '...'}, predicate: {...}, object: {...}}]Problem: Graph tab shows but no nodes/edges appear.
Solution:
- Check if query returns results (>0 triples)
- Verify container has explicit height:
#yasgui { height: 600px; } /* Or 100vh */
- Open browser console for error messages
Problem: Visualization is slow or unresponsive with large result sets.
Solution:
- Limit query results (use
LIMIT 100orLIMIT 1000) - Wait for layout stabilization
- If still slow, manually disable physics:
// In browser console const network = yasgui.getTab().yasr.plugins.graph.network; network.setOptions({physics: {enabled: false}});
Problem: Hovering over nodes/edges doesn't show details.
Solution: Ensure browser allows tooltips (not blocked by extensions). Tooltips are built-in to vis-network and display the title attribute.
# Clone repository
git clone https://github.com/Matdata-eu/yasgui-graph-plugin.git
cd yasgui-graph-plugin
# Install dependencies
npm install
# Build plugin
npm run build
# Run development server (if available)
npm run devyasgui-graph-plugin/
├── src/
│ ├── GraphPlugin.js # Main plugin class
│ ├── parsers.js # RDF triple parsing
│ ├── transformers.js # Triple → graph transformation
│ ├── prefixUtils.js # Prefix handling
│ └── index.js # Entry point
├── dist/
│ └── yasgui-graph-plugin.min.js # UMD bundle
├── example/
│ └── index.html # Demo page
├── package.json
└── README.md
# Start local server (e.g., with Python)
python -m http.server 8000
# Open in browser
# http://localhost:8000/example/See detailed contracts:
- Read Constitution: .specify/memory/constitution.md - Project principles and standards
- Review Feature Spec: specs/001-construct-graph-viz/spec.md - Complete requirements
- Explore Examples: example/index.html - Working demos
- Contribute: See CONTRIBUTING.md - Development workflow
- Issues: https://github.com/Matdata-eu/yasgui-graph-plugin/issues
- Discussions: https://github.com/Matdata-eu/yasgui-graph-plugin/discussions
Apache 2.0 - See LICENSE