Technology
The plot module provides data visualization capabilities for Project Forge applications using Observable Plot. It enables developers to create interactive, responsive charts and graphs with minimal code.
Overview
This module provides:
- Observable Plot Integration: Pre-configured Observable Plot and D3.js libraries
- Template Components: Ready-to-use chart templates and helper functions
- Responsive Design: Charts that automatically resize with the browser window
- TypeScript Support: Full TypeScript integration for type-safe chart development
Key Features
Performance
- Minified D3.js and Observable Plot libraries
- Efficient chart rendering with automatic cleanup
- Responsive charts that adapt to container size
- Progressive enhancement (graceful degradation without JavaScript)
Developer Experience
- Pre-built chart templates for common use cases
- Simple API for creating custom visualizations
- Automatic asset loading and script management
- Integration with Project Forge’s templating system
Chart Types
- Horizontal bar charts with customizable styling
- Extensible framework for additional chart types
- Built-in tooltips and interactions
- Responsive legends and axes
Package Structure
Assets
assets/plot/d3.min.js- Minified D3.js library for data manipulationassets/plot/plot.min.js- Minified Observable Plot library for visualization
Components
views/components/Plot.html- Template functions for chart creationPlotAssets()- Loads required JavaScript librariesPlotCall()- Creates responsive chart containersPlotHorizontalBar()- Pre-built horizontal bar chart template
Usage
Basic Setup
First, include the plot assets in your template:
{%= PlotAssets() %}
Creating a Horizontal Bar Chart
1 | |
Custom Charts
Use the PlotCall() function to create custom visualizations:
1 | |
Configuration
The module automatically handles: - Asset loading and caching - Responsive behavior on window resize - Memory cleanup when charts are destroyed - Integration with Project Forge’s asset pipeline
Dependencies
- D3.js: Data manipulation and DOM interaction
- Observable Plot: High-level charting grammar
- Project Forge Core: Template system and utilities
Source Code
- Repository: https://github.com/kyleu/projectforge/tree/main/module/plot
- License: CC0 (Public Domain)
- Author: Kyle U (kyle@kyleu.com)
See Also
- Observable Plot Documentation - Complete Observable Plot reference
- D3.js Documentation - D3.js API reference
- Project Forge Documentation - Complete framework documentation