Package Exports
- @matdata/yasgui-graph-plugin
- @matdata/yasgui-graph-plugin/dist/yasgui-graph-plugin.cjs.js
- @matdata/yasgui-graph-plugin/dist/yasgui-graph-plugin.esm.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@matdata/yasgui-graph-plugin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
YASGUI Graph Plugin
A YASGUI plugin for visualizing SPARQL CONSTRUCT and DESCRIBE query results as interactive graphs with nodes (subjects/objects) and edges (predicates).
โจ Features
- ๐ท Interactive Graph Visualization: Automatic force-directed layout with smooth physics-based positioning
- ๐จ Smart Color Coding:
- ๐ต Light Blue (#97C2FC) = URIs
- ๐ข Light Green (#a6c8a6ff) = Literals
- โช Light Grey (#c5c5c5ff) = Blank nodes
- ๐ Orange (#e15b13ff) = rdf:type objects (classes)
- ๐ Navigation: Mouse wheel zoom, drag to pan, "Zoom to Fit" button
- โ Drag & Drop: Reorganize nodes by dragging them to new positions
- ๐ฌ Tooltips: Hover for full URI/literal details (300ms delay)
- ๐ Theme Support: Automatic light/dark mode detection and dynamic color switching
- โก Performance: Handles up to 1,000 nodes with <2s render time
- โฟ Accessible: WCAG AA color contrast, keyboard navigation support
๐ฆ Installation
NPM
npm install @matdata/yasgui-graph-pluginimport Yasgui from '@matdata/yasgui';
import GraphPlugin from '@matdata/yasgui-graph-plugin';
Yasgui.Yasr.registerPlugin('Graph', GraphPlugin);
const yasgui = new Yasgui(document.getElementById('yasgui'));CDN (UMD)
<!-- YASGUI -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@matdata/yasgui/build/yasgui.min.css">
<script src="https://cdn.jsdelivr.net/npm/@matdata/yasgui/build/yasgui.min.js"></script>
<!-- Graph Plugin -->
<script src="https://cdn.jsdelivr.net/npm/@matdata/yasgui-graph-plugin/dist/yasgui-graph-plugin.min.js"></script>
<script>
// Plugin auto-registers as 'graph'
const yasgui = new Yasgui(document.getElementById('yasgui'));
</script>๐ Quick Start
See the complete working example in demo/index.html.
Basic Usage
const yasgui = new Yasgui(document.getElementById('yasgui'), {
requestConfig: {
endpoint: 'https://dbpedia.org/sparql'
}
});Sample Queries
CONSTRUCT Query:
PREFIX ex: <http://example.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
CONSTRUCT {
ex:Alice rdf:type ex:Person .
ex:Alice ex:knows ex:Bob .
ex:Alice ex:name "Alice" .
ex:Bob rdf:type ex:Person .
ex:Bob ex:name "Bob" .
}
WHERE {}DESCRIBE Query:
PREFIX ex: <http://example.org/>
# Returns all triples about the specified resources
DESCRIBE ex:Alice ex:BobAfter running the query, click the "Graph" tab to see the visualization.
๐ฎ User Guide
Navigation
- Zoom: Mouse wheel (scroll up = zoom in, scroll down = zoom out)
- Pan: Click and drag the background
- Fit to View: Click the "Zoom to Fit" button to center the entire graph
Interaction
- Drag Nodes: Click and drag any node to reposition it
- Tooltips: Hover over nodes/edges for 300ms to see full details
Understanding Colors
| Color | Meaning | Example |
|-------|---------|---------||
| ๐ต Light Blue (#97C2FC) | URI nodes | ex:Person, ex:Alice |
| ๐ข Light Green (#a6c8a6ff) | Literal values | "Alice", "30"^^xsd:integer |
| โช Light Grey (#c5c5c5ff) | Blank nodes | _:b1, _:addr1 |
| ๐ Orange (#e15b13ff) | rdf:type objects (classes) | ex:Person in ex:Alice rdf:type ex:Person |
โ๏ธ Configuration
The plugin uses sensible defaults but can be customized by extending the GraphPlugin class:
class CustomGraphPlugin extends GraphPlugin {
constructor(yasr) {
super(yasr);
}
// Override network options
getNetworkOptions() {
return {
...super.getNetworkOptions(),
physics: {
enabled: true,
stabilization: { iterations: 100 } // Faster but less optimal layout
}
};
}
}
Yasgui.Yasr.registerPlugin('customGraph', CustomGraphPlugin);๐ง Development
Build
npm install
npm run buildOutput:
dist/yasgui-graph-plugin.esm.js(ES Module for bundlers)dist/yasgui-graph-plugin.cjs.js(CommonJS for Node.js)dist/yasgui-graph-plugin.min.js(IIFE for browsers/unpkg)dist/index.d.ts(TypeScript declarations)
Local Testing
- Build the plugin:
npm run build - Open
demo/index.htmlin a browser (or runnpm run dev) - Try the sample queries in different tabs
Code Quality
npm run lint # ESLint check
npm run format # Prettier format๐ Documentation
- Quickstart Guide - Installation, usage, troubleshooting
- Data Model - Entity definitions and relationships
- Contracts - API specifications for YASR plugin and vis-network integration
- Specification - Complete feature specification
- [Constitution](./. specify/memory/constitution.md) - Project governance and principles
๐งช Browser Compatibility
Tested on latest 2 versions of:
- โ Chrome
- โ Firefox
- โ Safari
- โ Edge
Requires ES2018+ support and Canvas API.
๐ค Contributing
Contributions welcome! Please follow the project constitution (.specify/memory/constitution.md) for governance principles:
- Plugin-First Architecture - No YASGUI core modifications
- Visualization Quality - Performance (<2s for 1k nodes), accessibility (WCAG AA)
- Configuration Flexibility - Sensible defaults, but customizable
- Browser Compatibility - ES2018+, latest 2 browser versions
- Documentation - Keep docs updated with changes
๐ License
๐ Acknowledgments
- Built with vis-network for graph rendering
- Integrates with YASGUI SPARQL editor
- Follows the yasgui-geo plugin pattern
๐ Project Status
Current Version: 0.1.0 (MVP)
Implemented Features (v0.1.0):
- โ Basic graph visualization (US1)
- โ Navigation controls (US2)
- โ Color-coded nodes
- โ Prefix abbreviation
- โ Blank node support
- โ Performance optimization
Planned Features (Future):
- โณ Enhanced tooltips with datatype display (US4)
- โณ Manual testing across all browsers (US3 verification)
- โณ Large graph optimization (>1k nodes)
- โณ Custom color schemes
- โณ Layout algorithm selection
๐ Troubleshooting
Plugin tab not showing
- Verify plugin is registered correctly
- Check browser console for errors
- Ensure you're running a CONSTRUCT or DESCRIBE query
Empty visualization
- Ensure query type is CONSTRUCT or DESCRIBE
- Confirm query returns triples (check "Table" or "Response" tab)
- Verify results have RDF structure
Performance issues
- Limit results to <1000 nodes for best performance
- Disable physics after initial layout
- Consider using LIMIT clause in SPARQL query
For more help, see Quickstart Guide - Troubleshooting.
๐ ๏ธ Development
Setup
git clone https://github.com/yourusername/yasgui-graph-plugin.git
cd yasgui-graph-plugin
npm installDev Workflow (Live Reload)
The project supports live development - edit source files and see changes immediately without rebuilding:
Start a local dev server (any HTTP server will work):
# Using Python python -m http.server 8000 # Using Node.js (http-server) npx http-server -p 8000 # Using VS Code Live Server extension # Right-click demo/index.html โ "Open with Live Server"
Open demo in browser:
http://localhost:8000/demo/index.htmlEdit source files (e.g.,
src/colorUtils.js):export function getNodeColor(node) { // Change colors here if (node.isBlankNode) return '#FF00FF'; // Magenta // ... }
Refresh browser - changes appear immediately! โก
The demo automatically loads ES modules directly from src/ in development mode, so no rebuild is needed.
Production Build
Build all distribution formats:
npm run buildOutputs:
dist/yasgui-graph-plugin.esm.js- ES Module format (bundled with vis-network)dist/yasgui-graph-plugin.cjs.js- CommonJS format (bundled with vis-network)dist/yasgui-graph-plugin.min.js- IIFE browser bundle (bundled with vis-network)dist/index.d.ts- TypeScript type declarations
Testing
npm test # Run all tests
npm run lint # Check code style
npm run format # Auto-fix formatting