Skip to content

mark

Mojo module 🡭

mark

The geometric primitive a data row becomes: the grammar-of-graphics mark. Same small-struct-with-comptime-constants-and-__eq__ pattern as canvas.FillRule/canvas.TextAlign.

Each mark renders in its own file (rendering.mojo for POINT/LINE/AREA/ EFFECT_SCATTER, <mark>.mojo otherwise); its _render_* docstring describes the drawing. By data shape:

  • encode() (continuous x/y): POINT, LINE, AREA, EFFECT_SCATTER. HISTOGRAM takes encode_histogram_bins() (a HistogramBins) and draws one rectangle per bin at numeric x positions (histogram.mojo); it follows AREA’s zero-baseline and layering rules. BARBS and QUIVER take encode_barbs()/encode_quiver() (position plus u/v components), the same field as barbs or as arrows. CONTOUR and CONTOURF take encode_contour() (a rectangular grid of values, in grid-index coordinates); TRICONTOUR and TRICONTOURF take encode_tricontour() (scattered x/y/z samples, triangulated). TRIPLOT and TRIPCOLOR take encode_triplot() (the same scattered samples, drawn as the triangulation itself). POLAR takes encode_polar()/encode_polar_series() (angle + radius); SINGLE_AXIS takes encode_single_axis() (x only).
  • encode_categorical() (category + value): BAR, LOLLIPOP, POINTPLOT, ARC (pie/donut), FUNNEL, NIGHTINGALE, POLAR_BAR, RADIALBAR. WATERFALL takes encode_waterfall() (signed deltas); encode_binned_categories() bins raw values into BAR’s labeled categories.
  • Category + several values: BOX (encode_boxplot()), BEESWARM/ VIOLIN/RIDGELINE (encode_distribution()), CANDLESTICK (encode_candlestick()), BULLET (encode_bullet()), GANTT and SPAN_CHART (encode_gantt(), horizontal and vertical), POPULATION_PYRAMID (encode_population_pyramid()).
  • One flat ungrouped column of observations, drawn on a continuous frame: KDE and RUG (encode_kde()), ECDF (encode_ecdf()). POPULATION_PYRAMID (encode_population_pyramid()). EVENTPLOT takes encode_eventplot() (one list of event positions per row, any of which may be empty).
  • encode_grouped_bar() (category x series): GROUPED_BAR, STACKED_BAR, BUMP (ranks), STREAMGRAPH. MARIMEKKO takes encode_marimekko(); RADAR encode_radar(); PARALLEL encode_parallel(); GAUGE encode_gauge() (one value).
  • Two categorical axes: HEATMAP (encode_heatmap()), CORRPLOT (encode_corrplot()), PUNCHCARD (encode_punchcard()), CALENDAR_HEATMAP (encode_calendar()).
  • A 2D array on continuous axes (image.mojo): IMSHOW (encode_imshow(), cell centers on the grid indices) and PCOLORMESH (encode_pcolormesh(), explicit cell boundaries), and HIST2D (encode_hist2d(), a grid of counts binned from points, hist2d.mojo).
  • Points counted into a hexagonal lattice (hexbin.mojo): HEXBIN (encode_hexbin()).
  • A vector field on a grid, integrated into streamlines (streamplot.mojo): STREAMPLOT (encode_streamplot()). Not HEATMAP, which needs one category label per row and column.
  • encode_hierarchy() (hierarchy.mojo): SUNBURST, TREE, TREEMAP.
  • encode_dendrogram() (dendrogram.mojo): DENDROGRAM.
  • encode_chord() (edge list, edges.mojo): CHORD, ARC_DIAGRAM, GRAPH, SANKEY.

Vertical categorical marks share _draw_categorical_axis_frame (frame.mojo), horizontal ones _draw_horizontal_categorical_axis_frame (gantt.mojo; EVENTPLOT is one of these), and the two-categorical-axis marks _draw_grid_axis_frame (heatmap.mojo). BAR/BOX/VIOLIN/BEESWARM/ LOLLIPOP/GROUPED_BAR/STACKED_BAR each have a horizontal=True variant.

Adding a mark requires its constant (value and name), an updated COUNT, an entry in _every_mark() and a representative plot in tests/_mark_registry.mojo, and a reviewed output digest, and a Plot.mark_*() setter that binds its renderer with Plot._bind; see the checklist in plot.mojo.

Structs

  • Mark: A mark’s runtime identity: its value, and its name, which the constant states itself so no table maps one to the other (#854).