Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
gpui-d3rs
A comprehensive D3.js-inspired data visualization library for GPUI, bringing the power of D3's API to Rust with idiomatic patterns and native GPUI rendering.
Overview
d3rs is a modern data visualization library that translates D3.js concepts into idiomatic Rust for the GPUI framework. Instead of D3's functional chaining style, gpui-d3rs uses Rust's builder patterns and type system to provide a safe, performant, and ergonomic API for creating interactive visualizations.
Examples
Two showcases are provided that demonstrate the capabilities of the library. Here are few examples:
| Lines | IsoLines |
|---|---|
![]() |
![]() |
| Contour 3d | Contour 3d |
![]() |
![]() |
| Radar | Polar |
![]() |
![]() |
Features
Core Modules
-
Scales (
d3rs::scale) - Map data domains to visual rangesLinearScale- Continuous linear mappingLogScale- Logarithmic scaling for wide-range data- Automatic tick generation with Wilkinson's algorithm
- Domain/range inversion
-
Shapes (
d3rs::shape) - Visual marks for data representation- Bar charts with customizable styling
- Line charts with multiple curve types
- Scatter plots with configurable points
- Areas, arcs, pies, symbols, stacks
- Support for negative values and multiple series
-
Colors (
d3rs::color) - Rich color system- RGB/RGBA color representation
- HSL color space support
- Color interpolation for gradients
- Categorical schemes (Category10, Tableau10, Pastel, Set1-3)
- GPUI
Rgbaconversion
-
Axes (
d3rs::axis) - Cartesian coordinate system rendering- Four orientations: Top, Right, Bottom, Left
- Custom tick formatters
- Configurable tick size, padding, styling
- Domain line rendering
- Theme integration
-
Grids (
d3rs::grid) - Background grid overlays- Dot grids at tick intersections
- Horizontal and vertical line grids
- Configurable opacity and styling
- Multiple preset configurations
Classical Algorithms and Plots
-
Curves (
d3rs::shape::curve) - Line interpolation methods- Linear, Step, StepBefore, StepAfter
- Basis (B-spline)
- Cardinal, Catmull-Rom
- Monotone (monotonic cubic interpolation)
- Natural (natural cubic spline)
-
Geographic (
d3rs::geo) - Map projections and geographic computations- Mercator, Equirectangular, Orthographic projections
- Great circle distance calculations
- Point-in-polygon tests
- Graticule generation
- GeoPath rendering
-
Arrays (
d3rs::array) - Data manipulation utilities (d3-array)- Statistics: min, max, mean, median, quantile, variance
- Binning and histograms
- Search: bisect, quickselect
- Set operations: union, intersection, difference
- Transformations: group, rollup, flatMap
-
Interpolation (
d3rs::interpolate) - Value interpolation (d3-interpolate)- Numeric interpolation
- Color interpolation (HSL, LAB, HCL, Cubehelix)
- Transform (2D affine transformations)
- String interpolation with number detection
- Zoom interpolation for smooth scaling
- Piecewise interpolation
-
️ Contours (
d3rs::contour) - Density and contour visualization (d3-contour)- Marching squares algorithm
- Density estimation
- Contour generation with configurable thresholds
- Multiple rendering modes: Isoline, Surface, Heatmap
-
Spatial - Spatial data structures
QuadTree- 2D spatial indexing for fast nearest-neighbor queriesDelaunay- Delaunay triangulation and Voronoi diagramsPolygon- Polygon area, centroid, and containment tests
-
Time & Transitions - Animation and timing
d3rs::transition- Smooth value transitions with easing functionsd3rs::ease- Comprehensive easing function libraryd3rs::timer- High-precision timing utilities- Lifecycle callbacks (on_start, on_end, on_interrupt)
- Named transition management
-
Interaction - User interaction primitives
d3rs::brush- 1D and 2D selection brushesd3rs::zoom- Pan and zoom behaviors with constraints
-
Data - Data loading and parsing
d3rs::fetch- CSV/TSV/JSON utilities (d3-fetch)d3rs::format- Number formatting with SI prefixes and locales (d3-format)- Auto-type detection for CSV parsing
-
Utilities
d3rs::random- Random number generatorsd3rs::text- Text measurement and rendering utilities
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
= { ="0.2.2", = "https://github.com/zed-industries/zed.git" }
Basic Example - Linear Scale
use ;
let scale = new
.domain
.range;
assert_eq!; // Map 50 to 250
assert_eq!; // Inverse mapping
// Generate nice tick values
let ticks = scale.ticks; // [0, 10, 20, 30, ..., 100]
Bar Chart Example
use *;
use *;
Line Chart with Curves
use *;
use CurveType;
let points = vec!;
let config = default
.curve // Smooth monotonic curve
.stroke_color
.stroke_width;
render_line
Transitions Example
use Transition;
use ease_cubic_in_out;
let mut transition = new
.duration // 1 second
.ease
.from_to
.on_end;
// In your animation loop (60 FPS)
let value = transition.tick; // Delta time in ms
Geographic Projections
use ;
let projection = new
.scale
.translate;
// Project longitude/latitude to screen coordinates
let = projection.project; // New York City
println!;
QuadTree Spatial Index
use QuadTree;
let mut tree: = new;
tree.add;
tree.add;
tree.add;
// Find nearest neighbor
if let Some = tree.find
// Range query
let nearby = tree.find_all; // Within radius 10
Examples
The library includes comprehensive examples demonstrating all features. Run them with:
# Showcase application (all features in one interactive demo)
# Individual feature demos (CLI output)
# Spinorama demo (requires spinorama feature)
# Generate showcase snapshots (macOS only)
# This will iterate through all demos and save screenshots to docs/images/
API Philosophy: D3.js vs gpui-d3rs
Functional Chaining (D3.js)
const scale = d3.
.
.;
Builder Pattern (gpui-d3rs)
let scale = new
.domain
.range;
Key Differences
| Aspect | D3.js | gpui-d3rs |
|---|---|---|
| Chaining | Functional .domain().range() |
Builder pattern |
| Type Safety | Runtime checks | Compile-time guarantees |
| Rendering | SVG/Canvas DOM manipulation | GPUI div-based rendering |
| Performance | JavaScript runtime | Native Rust performance |
| Error Handling | Exceptions | Result<T, E> |
| Mutability | Implicit | Explicit mut |
Architecture
gpui-d3rs is built on these principles:
- Builder Pattern API - Idiomatic Rust with compile-time safety
- GPUI Native - First-class GPUI integration, not a wrapper
- Type-Driven - Leverage Rust's type system for correctness
- Zero-Cost Abstractions - Performance comparable to hand-written code
- Modular - Use only what you need via feature flags
Module Organization
d3rs/
├── array/ # d3-array: Data manipulation and statistics
├── axis/ # d3-axis: Cartesian axes rendering
├── brush/ # d3-brush: Selection brushes
├── color/ # d3-color: Color spaces and manipulation
├── contour/ # d3-contour: Contour generation and density
├── delaunay/ # d3-delaunay: Delaunay triangulation
├── ease/ # d3-ease: Easing functions
├── fetch/ # d3-fetch: Data loading (CSV, TSV, JSON)
├── format/ # d3-format: Number formatting
├── geo/ # d3-geo: Geographic projections
├── grid/ # Grid rendering for charts
├── interpolate/ # d3-interpolate: Value interpolation
├── legend/ # Legend rendering
├── polygon/ # d3-polygon: Polygon operations
├── quadtree/ # d3-quadtree: 2D spatial indexing
├── random/ # d3-random: Random number generators
├── scale/ # d3-scale: Scale functions
├── shape/ # d3-shape: Shape generators
├── text/ # Text rendering utilities
├── time/ # d3-time: Time utilities
├── timer/ # d3-timer: Animation timing
├── transition/ # d3-transition: Value transitions
└── zoom/ # d3-zoom: Pan and zoom behaviors
Features and Cargo Flags
[]
= ["gpui"]
= ["dep:gpui", "dep:gpui-ui-kit"] # GPUI rendering support
= [...] # Speaker measurement visualization
Testing
# Run all tests (non-GPUI modules)
# Check compilation
# Run clippy
Comparison with D3.js
| D3.js Module | gpui-d3rs Status | Notes |
|---|---|---|
| d3-array | ✅ Complete | Statistics, binning, transformations |
| d3-axis | ✅ Complete | All four orientations, custom formatting |
| d3-brush | ✅ Complete | 1D and 2D brushes |
| d3-chord | ✅ Complete | Specialized layout |
| d3-color | ✅ Complete | RGB, HSL with interpolation |
| d3-contour | ✅ Complete | Marching squares, density estimation |
| d3-delaunay | ✅ Complete | Delaunay triangulation, Voronoi |
| d3-dispatch | ❌ Not needed | Use GPUI's event system |
| d3-drag | ❌ Not needed | Use GPUI's mouse events |
| d3-dsv | ✅ Complete | CSV/TSV parsing (via d3-fetch) |
| d3-ease | ✅ Complete | All standard easing functions |
| d3-fetch | ✅ Complete | CSV, TSV, JSON loading |
| d3-force | 🚧 Planned | Force-directed graphs |
| d3-format | ✅ Complete | Number formatting, SI prefixes |
| d3-geo | ✅ Complete | Projections, paths, graticules |
| d3-hierarchy | 🚧 Planned | Tree layouts |
| d3-interpolate | ✅ Complete | Number, color, transform, zoom |
| d3-path | ✅ Integrated | Path rendering via GPUI |
| d3-polygon | ✅ Complete | Polygon operations |
| d3-quadtree | ✅ Complete | 2D spatial indexing |
| d3-random | ✅ Complete | Random number generators |
| d3-scale | ✅ Complete | Linear, log scales |
| d3-scale-chromatic | 🚧 Planned | Color schemes |
| d3-selection | ❌ Not needed | Use GPUI's component model |
| d3-shape | ✅ Complete | Lines, areas, arcs, pies, symbols |
| d3-time | ✅ Complete | Time utilities |
| d3-time-format | 🚧 Planned | Time formatting |
| d3-timer | ✅ Complete | Animation timing |
| d3-transition | ✅ Complete | Value transitions with easing |
| d3-zoom | ✅ Complete | Pan and zoom behaviors |
Legend: ✅ Complete | 🚧 Planned | ❌ Not needed/planned
Roadmap
- Core infrastructure (scales, colors, axes, grids)
- Basic shapes (bars, lines, scatter, areas)
- Curves (linear, step, basis, cardinal, monotone, natural)
- Contours and density estimation
- Geographic projections
- Spatial data structures (quadtree, delaunay)
- Transitions and animations
- Brush and zoom interactions
- Array utilities and data manipulation
- Interpolation (numeric, color, transform, zoom)
- Force-directed layouts
- Hierarchical layouts (tree, treemap, partition)
- Additional color schemes
- Time formatting
- Documentation improvements
- Performance benchmarks
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
Acknowledgments
- D3.js - The original inspiration and API design
- GPUI - The Zed editor's UI framework
- Observable Plot - Additional inspiration for declarative syntax
Resources
Data Sources and Licenses
The showcase application includes example datasets from various sources:
Old Faithful Geyser Dataset
- Source: R datasets package (originally from Härdle, W. (1991) "Smoothing Techniques with Implementation in S")
- Reference: R Documentation
- JSON version: GitHub Gist (curran)
- License: Public domain - factual measurements of a natural phenomenon at a U.S. National Park
- Used in: Kernel Density Estimation example
Volcano Terrain Data
- Source: Synthetic data generated to match the structure of Maunga Whau volcano
- License: Generated data, no license restrictions
- Used in: Volcano Contours example
Flare.js Package Hierarchy
- Source: Flare visualization toolkit package structure
- Reference: D3 Hierarchy Test Data
- Original: Flare Visualization Toolkit (BSD License)
- License: Package structure/file sizes are factual data, non-copyrightable
- Used in: Treemap example
Made with love for data visualization in Rust.





