Skip to main content

Crate forge_charts

Crate forge_charts 

Source
Expand description

Pure-Rust + SVG interactive charts for Leptos CSR.

v0.1 ships one chart type — AreaChart — with the visual style of ApexCharts (gradient fills, soft axes, modern legend) but implemented entirely in Rust + SVG. No JS, no canvas, no Tailwind. Designed to be project-agnostic: no consumer types leak into the public API.

§Quick start

use leptos::prelude::*;
use forge_charts::{AreaChart, Series, CHART_CSS};

#[derive(Clone)]
struct Datum { date: String, opened: u32, closed: u32 }

#[component]
fn MyChart(data: Signal<Vec<Datum>>) -> impl IntoView {
    view! {
        <Stylesheet text=CHART_CSS />
        <AreaChart
            data=data
            x_label=|d: &Datum| d.date.clone()
            y_values=|d: &Datum| vec![f64::from(d.opened), f64::from(d.closed)]
            series=vec![
                Series::area("Opened", "opened"),
                Series::area("Closed", "closed"),
            ]
            height=320
        />
    }
}

§Styling

The crate ships a default stylesheet exposed as the CHART_CSS constant. Consumers inject it once via Leptos <Stylesheet /> at the app root. CSS variables (--charts-fg, --charts-grid-color, --charts-series-opened, --charts-series-closed, …) let consumers theme without forking the stylesheet.

§Roadmap

  • Phase B (shipped): hover crosshair + consumer-provided tooltip slot.
  • Phase C (shipped): drag-to-zoom + reset.
  • Future: Bar / Line variants, smooth Bezier curves, stacked areas. Extract shared math when the second chart needs it.

Structs§

HoverState
Snapshot of where the cursor is in the chart.
Series
One series in a chart. Carries display name + a CSS-class fragment consumers use to theme color.
ZoomRange
A committed zoom range in data index space, inclusive at both ends. from_index and to_index index into the chart’s original unsliced data array; the chart slices the rendered view by this range and offsets the hovered index back to the original space when handing it to the tooltip slot.

Enums§

SeriesKind
What kind of geometry a Series renders.

Constants§

CHART_CSS
Default stylesheet bundled with the crate. Inject once at the app root via <Stylesheet text=CHART_CSS /> (Leptos meta).
MIN_ZOOM_SPAN
Minimum span (in data points) that a drag must cover before we commit it as a zoom. Drags shorter than this are treated as a click and ignored. Keeps accidental tiny drags from snapping the chart to a single point.

Functions§

AreaChart
Interactive area chart component.

Type Aliases§

TooltipSlot
Boxed tooltip slot. Receives the hovered data-point index and returns whatever Leptos view the consumer wants to render.
YFormat
Formats a y-axis tick value into its display label. When unset the chart renders a plain number. Provide one to label the axis in real units — durations, bytes, percentages — so a raw 6000000 reads as 1h 40m instead.
ZoomCommit
Callback fired when the user commits a drag-to-zoom. Receives the inclusive original-index bounds of the selected range (already composed with any prior internal slice, if the chart is uncontrolled).