Sign in

    ihb2032/MoonFrame/chart does not have a README file

    ChartKind

    pub(all) enum ChartKind {
    Bar
    Line
    Point
    Area
    } derive(Eq,
    Debug
    )

    The mark type of a chart, mapped to a Vega-Lite top-level mark: Bar → "bar", Line → "line", Point → "point", Area → "area". pub(all) so callers can name the variants when building a ChartSpec (though the ChartSpec::bar / line / point / area constructors set the kind for you).

    ChartKind::equal

    fn ChartKind::equal(ChartKind, ChartKind) -> Bool

    ChartKind::not_equal

    fn ChartKind::not_equal(x : ChartKind, y : ChartKind) -> Bool

    ChartSpec

    pub struct ChartSpec {
    kind : ChartKind
    x : String
    y : String
    color : String?
    title : String?
    color_type : VegaType?
    } derive(Eq,
    Debug
    )

    A chart specification: the mark kind, the x / y encoding columns, an optional color grouping column, and an optional title. Fields are read-only outside the package — build a spec through one of the mark-named constructors (ChartSpec::bar(x, y) / line / point / area), naming color / color_type / title as needed:

    ChartSpec::bar("region", "revenue", title="Revenue by region")

    x / y / color are column names resolved against the frame at format_vega_lite time (a missing name raises ColumnNotFound); each column's dtype decides its Vega-Lite field type — the rule format_vega_lite's doc states (numeric → quantitative, Date → temporal, otherwise → nominal) — unless color_type overrides the color channel: e.g. a numeric grouping column (a cluster id) rendered as Nominal distinct colors rather than a continuous gradient (only color honours an override; x / y keep dtype inference).

    ChartSpec::area

    fn ChartSpec::area(x : String, y : String, color? : String, color_type? : VegaType, title? : String) -> ChartSpec

    An area chart of y against x (Vega-Lite mark: "area").

    The optional color / color_type / title parameters carry the ChartSpec doc's colour-encoding and title contract (only color honours a color_type override; x / y keep dtype inference).

    ChartSpec::bar

    fn ChartSpec::bar(x : String, y : String, color? : String, color_type? : VegaType, title? : String) -> ChartSpec

    A bar chart of y against x (Vega-Lite mark: "bar").

    The optional color / color_type / title parameters carry the ChartSpec doc's colour-encoding and title contract (only color honours a color_type override; x / y keep dtype inference).

    ChartSpec::equal

    fn ChartSpec::equal(ChartSpec, ChartSpec) -> Bool

    ChartSpec::line

    fn ChartSpec::line(x : String, y : String, color? : String, color_type? : VegaType, title? : String) -> ChartSpec

    A line chart of y against x (Vega-Lite mark: "line").

    The optional color / color_type / title parameters carry the ChartSpec doc's colour-encoding and title contract (only color honours a color_type override; x / y keep dtype inference).

    ChartSpec::not_equal

    fn ChartSpec::not_equal(x : ChartSpec, y : ChartSpec) -> Bool

    ChartSpec::point

    fn ChartSpec::point(x : String, y : String, color? : String, color_type? : VegaType, title? : String) -> ChartSpec

    A scatter (point) chart of y against x (Vega-Lite mark: "point").

    The optional color / color_type / title parameters carry the ChartSpec doc's colour-encoding and title contract (only color honours a color_type override; x / y keep dtype inference).

    VegaType

    pub(all) enum VegaType {
    Quantitative
    Nominal
    Ordinal
    Temporal
    } derive(Eq,
    Debug
    )

    A Vega-Lite field type, used to override the dtype-based inference for the color channel. pub(all) so callers can name the variants in a constructor's color_type. Quantitative is a continuous measure (a color gradient), Nominal an unordered category (distinct colors per value), Ordinal an ordered category, and Temporal a time field.

    VegaType::equal

    fn VegaType::equal(VegaType, VegaType) -> Bool

    VegaType::not_equal

    fn VegaType::not_equal(x : VegaType, y : VegaType) -> Bool

    VegaType::to_repr

    format_vega_lite

    Render df and spec as a complete Vega-Lite v5 specification JSON string: $schema (pinned to the Vega-Lite v5 schema URL) + optional title + mark (from spec.kind) + encoding (x / y and, when set, color, each {field, type}) + data.values (the frame inlined as JSON records, sharing format_json's cell mapping — null and non-finite-float cells become JSON null). A frame with the encoded columns but zero rows yields "data":{"values":[]}.

    Each encoding channel's field type follows its column's dtype — the single statement of the dtype→type rule: a numeric column (Int / Float) is "quantitative", a Date column is "temporal" (its ISO cells — data.values' date units, via the JSON records' ISO mapping — sort chronologically), and every other dtype is "nominal" — unless the channel carries an explicit color_type override.

    The spec's x / y / color columns are resolved left-to-right; the first name absent from df raises ColumnNotFound(name) — this is the one reason the function is not total (it accepts column names, and a name can be wrong). The emitted text is always valid JSON (it is built through @json and stringified), so it round-trips through any standards-compliant JSON / Vega-Lite reader.

    write_vega_lite

    fn write_vega_lite(path : String, df :
    DataFrame
    , spec : ChartSpec) -> Unit raise
    DataError

    Write a Vega-Lite v5 spec for df / spec to path. Mirrors write_json: a ColumnNotFound from format_vega_lite (a spec column absent from df) propagates unchanged, a filesystem failure surfaces as raise IoError(message), and content holding an unpaired UTF-16 surrogate is refused with raise InvalidOperation.

    Source Files