Skip to content
/ yapl Public

Graph mathematical functions using linear interpolation and SVG.

Notifications You must be signed in to change notification settings

duncpro/yapl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yapl

Experimental SVG plotting library for the purpose of mathematical exposition.

sin(1/x)

Features

Axis

sinx

use std::f64::consts::PI;
use yapl::elements::{Function, CoordinatePlane, Axis, TickLabelKind, SymbolicTickLabel, TickLabel};
use yapl::math::{NonDecreasing, ClosedInterval};
use yapl::typography::MathJaxProcessTeXRenderer;
use yapl::codegen::codegen;
use yapl::style::Stylesheet;

fn main() -> std::io::Result<()> {
    let mut cplane = CoordinatePlane::new_elementary();

    let mut x_axis = Axis::new_default(0.0, PI, 0.0);
    x_axis.tick_label = Some(TickLabel::new_default(TickLabelKind::Symbolic(SymbolicTickLabel {
        offset_symbol_tex: None,
        stride_symbol_tex: "\\pi",
    })));
    cplane.horizontal_axis = Some(x_axis);
    
    cplane.extent.brect.x = ClosedInterval::new(NonDecreasing::new(-2.0 * PI - 1.0, 2.0 * PI + 1.0));
    cplane.extent.brect.y = ClosedInterval::new(NonDecreasing::new(-1.5, 1.5));

    cplane.fns.push(Function::new_default(|x| x.sin()));
    
    let stylesheet = Stylesheet::new_default();
    let mut tex_renderer = MathJaxProcessTeXRenderer::new()?;
    codegen(&mut std::io::stdout(), &cplane, stylesheet, &mut tex_renderer)
}

To Do

  • Draw grid.
  • Draw axis labels (not axis tick labels, we already draw those).
  • Draw labeled points of interest.
  • Draw labeled line segments.
  • Draw basic shapes.

Philosophy

Styling

All styles are applied using CSS and not a Rust-based styling API. For instance there is no Axis#color field or the like. CSS is quite ergonmic already, and I see no need to implement a clunky Rust API on top of it.

This library provides a minimal default stylesheet. This is so that ledigble diagrams are generated even if the user provides no explicit styling. The stylesheet is small enough to fit in only a few lines so that it is very clear what is going on and how the behavior can be changed.

This library exposes a simple flag-based API for opting out of default style rules and default style classes on per-element and global basis. This provide a way for the user to omit a default styling rule entirely if they wish to override it with a rule in their own custom stylesheet. This keeps redundant default styles out of the finished SVG.

A custom stylesheet can be applied in addition to the default stylesheet using yapl::style::Stylesheet#custom. The default stylesheet can be thinned or purged entirely using yapl::style::Stylesheet#defaults.

About

Graph mathematical functions using linear interpolation and SVG.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published