Skip to content

plot

Mojo module 🡭

plot

Plot, the entry point of every chart: settings only, until a mark_*() call picks the mark and the chain becomes a Chart of that mark’s type (#828). Plot().mark_gantt() is a Chart[Gantt], and from there encode_gantt() exists and encode_categorical() does not, which the compiler says rather than render().

Each mark_*() setter builds the mark struct, applies the setter’s own arguments to it or to the shared settings, and returns Chart[<mark>](mark, settings, style). The one-call functions (bar(), gantt(), …) go through the same setters and end in _finished(), which applies the theme, size and titles.

Where the rest lives:

  • chart.mojo – Chart[M] and AnyChart, the type-erased chart that layers, facets and figures hold in one list
  • mark_type.mojo – the MarkType trait every mark implements
  • marks.mojo – one struct per mark, over the renderers and encoders in the mark packages
  • rendering.mojo – render(), render_svg(), render_pdf(), save() and the tight and accessible variants, generic over any chart
  • layers.mojo, facets.mojo, layout.mojo – composition over List[AnyChart]
  • core/chart_settings.mojo – _ChartSettings, what every mark shares

This module exports only what it defines, Plot and _finished (#825); scripts/check_import_direction.py keeps it so.

Adding a mark

  1. Its Mark constant in core/mark.mojo, Self(<value>, "<NAME>"), Mark.COUNT one past it, and the constant in _every_mark() (tests/_mark_registry.mojo); the digest and backend sweeps walk that list.
  2. Its struct in marks.mojo: the columns it owns, render over them, an override of each encode_*() it accepts (the trait’s default refuses at compile time), and every MarkType constant – the supports_* features and the drawing facts after them (straight_edged, continuous_path, layerable, …). They are required, so a missing one is a compile error rather than a list the new mark was left out of.
  3. Its mark_*() setter here, returning Chart[<mark>].
  4. Its one-call function in its package, exported from dataviz/__init__.mojo.
  5. A representative chart in tests/_mark_registry.mojo, then pixi run digest-update.
  6. An ExamplePage in scripts/_example_docstrings.mojo and its entry in scripts/gen_example_docs.mojo, then pixi run example.

Structs

  • Plot: The entry point: what a chart is before its mark is chosen.