akselharting library
aksel is a charting library that provides coordinate transformations and scale mappings
for data visualization. It focuses on the mathematical foundations of charting:
mapping data values to screen coordinates and generating axis tick marks.
Core Concepts
Scales
Scales map data values (domain) to a normalized [0, 1] range. They support:
- Linear and logarithmic mappings
- Pan and zoom operations
- Automatic tick generation for axis labels
- Bidirectional mapping (normalize and denormalize)
Available scale types:
- [
scale::Linear] - Affine mapping for linear data - [
scale::Logarithmic] - Logarithmic mapping for exponential data
Transforms
Transforms connect scales to screen coordinates, converting between:
- [
PlotPoint] - Data values in chart space - [
ScreenPoint] - Pixel coordinates in screen space
The [Transform] type handles y-axis inversion (screen coordinates typically
increase downward, while chart coordinates increase upward).
Examples
Basic Linear Scale
use ;
// Create a scale mapping [0.0, 100.0] to [0.0, 1.0]
let scale = new;
// Normalize values to [0.0, 1.0]
assert_eq!;
assert_eq!;
assert_eq!;
// Denormalize back to domain
assert_eq!;
Pan and Zoom
use ;
let mut scale = new;
// Pan by 10% (shifts by 10 units)
scale.pan;
assert_eq!;
// Zoom in by 2x at center
let mut scale = new;
scale.zoom;
assert_eq!;
Coordinate Transformation
use ;
let x_scale = new;
let y_scale = new;
let screen = ScreenRect ;
let transform = new;
// Convert plot coordinates to screen pixels
let plot_point = new;
let screen_point = transform.chart_to_screen;
// screen_point is at (400.0, 200.0) - center of screen
Generating Ticks
use ;
let scale = new;
let ticks = scale.ticks;
// Ticks include both major (level 0) and minor (level 1) marks
for tick in ticks