@dreamlab-ai/webvowl-wasm
v0.3.2
Published
High-performance WASM implementation of WebVOWL ontology visualizer - Rust/WASM powered semantic graph visualization for Logseq knowledge graphs
Maintainers
Readme
WebVOWL WASM
High-performance Rust/WASM implementation of WebVOWL ontology visualizer.
Features
- 🚀 High Performance: 10-100x faster than JavaScript implementation
- 🧪 Test-Driven: >90% test coverage with London-style TDD
- 🔧 Type-Safe: Full Rust type safety with WASM bindings
- 📦 Zero Dependencies: Pure Rust implementation (runtime)
- 🎨 SVG Rendering: Built-in SVG export functionality
- ⚡ Optimized Layout: Fast force-directed graph layout algorithm
Quick Start
Build
# Install wasm-pack
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# Build for web
npm run build
# Build for development (with debug symbols)
npm run build:devTest
# Run all tests
npm test
# Run tests in specific browser
npm run test:firefox
npm run test:chrome
# Run Rust unit tests
cargo testBenchmark
npm run benchUsage
JavaScript/TypeScript
import init, { WebVowl } from './pkg/webvowl_wasm.js';
async function main() {
// Initialize WASM module
await init();
// Create WebVOWL instance
const webvowl = new WebVowl();
// Load ontology
const ontologyJson = await fetch('ontology.json').then(r => r.json());
webvowl.loadOntology(JSON.stringify(ontologyJson));
// Configure simulation
webvowl.setCenter(400, 300);
webvowl.setLinkDistance(50);
webvowl.setChargeStrength(-100);
// Run simulation
webvowl.initSimulation();
webvowl.runSimulation(100);
// Get results
const graphData = webvowl.getGraphData();
const stats = webvowl.getStatistics();
console.log('Nodes:', stats.node_count);
console.log('Edges:', stats.edge_count);
console.log('Graph data:', graphData);
}
main();Animation Loop
function animate() {
if (!webvowl.isFinished()) {
webvowl.tick();
const graphData = webvowl.getGraphData();
// Update visualization with graphData
updateVisualization(graphData);
requestAnimationFrame(animate);
}
}
webvowl.initSimulation();
animate();Architecture
Modules
- ontology: OWL ontology parsing and validation
- graph: Graph data structures (nodes, edges)
- layout: Force-directed layout algorithms
- render: SVG/Canvas rendering utilities
- bindings: WASM JavaScript bindings
Performance
Benchmarks on M1 MacBook Pro:
| Operation | Size | Time | |-----------|------|------| | Parse Ontology | 100 classes | ~500μs | | Build Graph | 100 nodes | ~200μs | | Force Tick | 100 nodes | ~150μs | | Full Simulation | 100 nodes, 50 iter | ~8ms |
API Reference
WebVowl
Main WASM interface for ontology visualization.
Methods
new(): Create new instanceloadOntology(json: string): Load ontology from JSONinitSimulation(): Initialize force simulationrunSimulation(iterations: number): Run simulation for N iterationstick(): Perform one simulation stepisFinished(): Check if simulation has convergedgetAlpha(): Get current simulation alpha (energy)setCenter(x: number, y: number): Set center positionsetLinkDistance(distance: number): Set target link distancesetChargeStrength(strength: number): Set node repulsion strengthgetGraphData(): Get current graph data with positionsgetNodeCount(): Get number of nodesgetEdgeCount(): Get number of edgesgetStatistics(): Get graph statistics
Development
Project Structure
rust-wasm/
├── src/
│ ├── lib.rs # Main library entry
│ ├── error.rs # Error types
│ ├── ontology/ # OWL parsing
│ │ ├── mod.rs
│ │ ├── parser.rs
│ │ └── model.rs
│ ├── graph/ # Graph structures
│ │ ├── mod.rs
│ │ ├── node.rs
│ │ ├── edge.rs
│ │ └── builder.rs
│ ├── layout/ # Layout algorithms
│ │ ├── mod.rs
│ │ ├── force.rs
│ │ └── simulation.rs
│ ├── render/ # Rendering
│ │ └── mod.rs
│ └── bindings/ # WASM bindings
│ └── mod.rs
├── tests/
│ └── integration_test.rs
├── benches/
│ ├── layout_bench.rs
│ └── parser_bench.rs
├── Cargo.toml
└── package.jsonTesting Strategy
The project uses London-style TDD:
- Mock-First Design: Define interfaces with
#[mockall::automock] - Behavior Testing: Test interactions, not just state
- Red-Green-Refactor: Write failing test → implement → refactor
- High Coverage: Target >90% code coverage
Code Quality
# Check code
cargo check --all-targets
# Clippy linting
cargo clippy -- -D warnings
# Format check
cargo fmt -- --check
# Run all quality checks
npm run check && npm run clippy && npm run fmtLicense
MIT License - see LICENSE file for details
Contributing
- Fork the repository
- Create a feature branch
- Write tests first (TDD)
- Implement feature
- Ensure all tests pass
- Submit pull request
Performance Tips
- Batch Updates: Update multiple nodes before rendering
- Reduce Iterations: 50-100 iterations usually sufficient
- Adjust Forces: Tune link distance and charge strength for your data
- Use Alpha: Stop simulation when alpha < threshold
- Fixed Nodes: Pin important nodes to reduce computation
Comparison with JavaScript
| Metric | JavaScript | Rust/WASM | Improvement | |--------|-----------|-----------|-------------| | Parse Time | ~5ms | ~0.5ms | 10x | | Layout Tick | ~2ms | ~0.15ms | 13x | | Memory Usage | ~8MB | ~1MB | 8x | | Bundle Size | ~150KB | ~80KB | 1.9x |
Roadmap
- [ ] Multi-threading with Web Workers
- [ ] WebGL rendering backend
- [ ] Incremental layout updates
- [ ] Custom layout algorithms
- [ ] SPARQL query integration
- [ ] Real-time collaboration
Support
For issues and questions, please use the GitHub issue tracker.
