Skip to content

Theme

Mojo struct 🡭

Theme

@memory_only
struct Theme

Fields

  • background (Color): The canvas’s fill color, drawn behind everything else.
  • mark_color (Color): The default ink a mark draws in – bar fill, line stroke, point fill, … – whenever no data-driven color/color_categories channel or per-mark override (mark_color_negative, a palette, …) applies instead.
  • axis_color (Color): The axis line/tick/frame color.
  • gridline_color (Color): Gridline color, drawn when show_gridlines is True.
  • text_color (Color): The default text color – tick labels, the chart title, and anywhere else no more specific color field (subtitle_color, annotation_color, …) applies.
  • font_size (Float64): The base font size, in points, for tick/legend labels – scaled by Theme.scale the same as every other pixel-sized quantity (see _Scaled’s docstring, plot.mojo).
  • point_radius (Float64): The default pixel radius for Mark.POINT/EFFECT_SCATTER markers, before any data-driven size channel overrides it.
  • line_width (Float64): The default stroke width, in pixels, for Mark.LINE/AREA and every other stroked mark.
  • margin_left (Int): Reserved pixel space along the plot’s left edge, before the y-axis’s own tick-label width/margin_buffer are added on top.
  • margin_right (Int): Reserved pixel space along the plot’s right edge, before a legend’s own reserved width (if any) is added on top.
  • margin_top (Int): Reserved pixel space along the plot’s top edge, before a title/subtitle’s own reserved height (if any) is added on top.
  • margin_bottom (Int): Reserved pixel space along the plot’s bottom edge, before an x-axis title’s own reserved height (if any) is added on top.
  • show_gridlines (Bool): Whether to draw gridlines at all; defaults to True.
  • color_scale_low (Color): The low end of the default continuous color gradient (Plot. encode(color=...), Mark.HEATMAP/CORRPLOT/CALENDAR_HEATMAP).
  • color_scale_mid (Color): The midpoint of the default continuous color gradient – a deliberate third stop, not a two-color blend; see this struct’s own module docstring for why a plain low/high interpolation reads as a muddy, desaturated middle.
  • color_scale_high (Color): The high end of the default continuous color gradient.
  • size_range_min (Float64): The smallest pixel radius a data-driven size channel maps its column’s minimum value to.
  • size_range_max (Float64): The largest pixel radius a data-driven size channel maps its column’s maximum value to.
  • show_legend (Bool): Whether to draw a legend at all, for every mark that has one; defaults to True.
  • scale (Float64): Uniformly multiplies every other pixel-sized quantity render() computes (font size, margins, point radius, line width, tick length, legend layout, …); see this struct’s own module docstring for the full HiDPI-rendering reasoning.
  • donut_inner_radius_fraction (Float64): A fraction ([0.0, 1.0)) of Mark.ARC’s outer radius to leave as a hole – 0.0 (the default) draws an ordinary pie; any positive value draws a donut.
  • color_by_sign (Bool): Whether Mark.BAR colors each bar by whether its value is negative (mark_color_negative) or not (mark_color); defaults to False (every bar stays mark_color).
  • mark_color_negative (Color): The ink for a negative value – Mark.BAR when color_by_sign is True, and unconditionally for Mark.WATERFALL/CANDLESTICK, whose falling/down coloring isn’t optional.
  • bullet_range_color_light (Color): The lightest end of Mark.BULLET’s grayscale qualitative-range band gradient (lowest range index).
  • bullet_range_color_dark (Color): The darkest end of Mark.BULLET’s grayscale qualitative-range band gradient (highest range index).
  • line_smoothing (Float64): How much Mark.LINE/AREA curves through its data points, via a Catmull-Rom-derived spline – 0.0 (the default) draws plain straight segments; 1.0 the full curve; must be in [0.0, 1.0].
  • title_font_size (Float64): The chart title’s font size, in points; defaults larger than font_size since a title reads as a heading.
  • subtitle_font_size (Float64): The subtitle’s font size, in points – the same size an axis title uses, both reading as a subordinate label under the title.
  • subtitle_color (Color): The subtitle’s dedicated color, distinct from text_color so it recedes as supporting context rather than competing with the title.
  • axis_title_font_size (Float64): The x/y-axis title’s font size, in points.
  • waterfall_total_color (Color): Mark.WATERFALL’s third color, for a row encode_waterfall()’s is_total marks as a running-total checkpoint – deliberately distinct from mark_color/mark_color_negative since a total bar is a different kind of thing, not a big increase or decrease.
  • annotation_color (Color): Plot.annotate_line()/annotate_vline()/annotate_point()’s color – the reference mark itself and its optional label.
  • annotation_area_color (Color): Plot.annotate_area()’s fill – a separate field from annotation_color since a filled band needs real partial opacity to let the mark underneath keep showing through, unlike a line.
  • font_family (String): Every _TextRequest’s typeface; defaults to "sans-serif", a generic keyword both the raster (fontconfig) and SVG (CSS) text backends resolve consistently.
  • title_bold (Bool): Whether the chart title draws bold; defaults to True. The one field in this struct whose default isn’t backward-compatible with pre-existing renders – see this struct’s own module docstring.
  • waterfall_delta_width_fraction (Float64): How much of its band a rising/falling Mark.WATERFALL delta bar occupies; a total bar always spans the full band.
  • bullet_measure_width_fraction (Float64): How thick Mark.BULLET’s measure bar is relative to its band.
  • chord_ring_fraction (Float64): How thick Mark.CHORD’s node ring is relative to the outer radius.
  • radialbar_track_color (Color): The unfilled background track Mark.RADIALBAR sweeps its rings over.
  • treemap_label_color (Color): The label color drawn on a Mark.TREEMAP leaf rectangle.
  • halo_alpha (UInt8): The opacity Mark.EFFECT_SCATTER blends each point’s halo at, before flattening it against white.
  • radar_fill_alpha (UInt8): The opacity Mark.RADAR blends each series’ filled polygon at, before flattening it against white – a separate field from halo_alpha even though both default to the same value, so retheming one never silently moves the other.
  • radialbar_ring_gap_fraction (Float64): The gap between adjacent Mark.RADIALBAR rings, as a fraction of each ring’s own slot.
  • violin_width_fraction (Float64): How much of its category’s band width a Mark.VIOLIN’s peak density maps to, by default (ggplot2’s scale = "width").
  • corrplot_bubble_fraction (Float64): How much of a Mark.CORRPLOT cell’s smaller dimension its bubble’s maximum radius (at abs(correlation) == 1.0) fills.
  • gauge_band_inner_fraction (Float64): Mark.GAUGE’s color-banded dial ring’s inner radius, as a fraction of the dial’s outer radius.
  • gauge_needle_fraction (Float64): Mark.GAUGE’s needle length, as a fraction of the dial’s outer radius.
  • ridgeline_overlap (Float64): How far a Mark.RIDGELINE row’s curve may rise into the row above it, as a multiple of one row’s own height.
  • polar_bar_padding (Float64): The gap Mark.POLAR_BAR leaves out of each bar’s angular slot, as a fraction of that slot.
  • polar_grid_rings (Int): How many evenly spaced concentric gridline rings Mark.POLAR draws.
  • polar_grid_spokes (Int): How many straight radial gridline spokes Mark.POLAR draws.
  • radar_grid_rings (Int): How many concentric gridline rings Mark.RADAR draws.
  • gauge_start_angle (Float64): Mark.GAUGE’s dial start angle, in radians (this package’s usual clockwise-from-3-o’clock convention).
  • gauge_sweep_angle (Float64): Mark.GAUGE’s total dial sweep, in radians, from gauge_start_angle.
  • tick_length (Int): The pixel length of each axis tick mark.
  • label_gap (Int): The pixel gap between a tick mark and its label.
  • legend_width (Int): The reserved pixel width for a legend’s swatch-plus-label column, when its dynamic width can’t be computed some other way.
  • legend_swatch_size (Int): The pixel size of each legend entry’s color swatch.
  • legend_row_gap (Int): The pixel gap between consecutive legend entries.
  • continuous_legend_bar_width (Int): The pixel width of a continuous (gradient) legend’s color bar.
  • continuous_legend_bar_height (Int): The pixel height of a continuous (gradient) legend’s color bar.
  • margin_buffer (Int): Extra breathing-room padding, in pixels, added after a margin’s own tick-label-width/tick-length/label-gap computation.
  • sankey_node_width (Float64): The pixel width of each Mark.SANKEY node column’s bar.
  • output_format (OutputFormat): The file format save() (plot.mojo) writes when given a Plot and a path, with no canvas_mojo backend named at the call site – defaults to OutputFormat.SVG (see that struct’s docstring for why vector is the default). render()/render_svg() ignore this field entirely; it only governs save()’s own choice.

Implemented traits

AnyType, Copyable, Deinitable, ImplicitlyCopyable, Movable

Methods

__init__

fn def __init__(out self, background: Color = WHITE, mark_color: Color = Color(UInt8(30), UInt8(100), UInt8(180), UInt8(255)), axis_color: Color = Color(UInt8(80), UInt8(80), UInt8(80), UInt8(255)), gridline_color: Color = Color(UInt8(225), UInt8(225), UInt8(225), UInt8(255)), text_color: Color = Color(UInt8(40), UInt8(40), UInt8(40), UInt8(255)), font_size: Float64 = 12, point_radius: Float64 = 3.5, line_width: Float64 = 2, margin_left: Int = Int(60), margin_right: Int = Int(20), margin_top: Int = Int(20), margin_bottom: Int = Int(50), show_gridlines: Bool = True, color_scale_low: Color = Color(UInt8(60), UInt8(110), UInt8(200), UInt8(255)), color_scale_mid: Color = Color(UInt8(235), UInt8(235), UInt8(235), UInt8(255)), color_scale_high: Color = Color(UInt8(220), UInt8(90), UInt8(40), UInt8(255)), size_range_min: Float64 = 3, size_range_max: Float64 = 15, show_legend: Bool = True, scale: Float64 = 1, donut_inner_radius_fraction: Float64 = 0, color_by_sign: Bool = False, mark_color_negative: Color = Color(UInt8(200), UInt8(60), UInt8(60), UInt8(255)), bullet_range_color_light: Color = Color(UInt8(224), UInt8(224), UInt8(224), UInt8(255)), bullet_range_color_dark: Color = Color(UInt8(120), UInt8(120), UInt8(120), UInt8(255)), line_smoothing: Float64 = 0, title_font_size: Float64 = 18, subtitle_font_size: Float64 = 14, subtitle_color: Color = Color(UInt8(110), UInt8(110), UInt8(110), UInt8(255)), axis_title_font_size: Float64 = 14, waterfall_total_color: Color = Color(UInt8(100), UInt8(100), UInt8(100), UInt8(255)), annotation_color: Color = Color(UInt8(150), UInt8(150), UInt8(150), UInt8(255)), annotation_area_color: Color = Color(UInt8(224), UInt8(236), UInt8(246), UInt8(200)), font_family: String = "sans-serif", title_bold: Bool = True, waterfall_delta_width_fraction: Float64 = 0.59999999999999998, bullet_measure_width_fraction: Float64 = 0.34999999999999998, chord_ring_fraction: Float64 = 0.080000000000000002, radialbar_track_color: Color = Color(UInt8(230), UInt8(230), UInt8(230), UInt8(255)), treemap_label_color: Color = Color(UInt8(255), UInt8(255), UInt8(255), UInt8(255)), halo_alpha: UInt8 = UInt8(90), radar_fill_alpha: UInt8 = UInt8(90), radialbar_ring_gap_fraction: Float64 = 0.25, violin_width_fraction: Float64 = 0.40000000000000002, corrplot_bubble_fraction: Float64 = 0.41999999999999998, gauge_band_inner_fraction: Float64 = 0.69999999999999996, gauge_needle_fraction: Float64 = 0.90000000000000002, ridgeline_overlap: Float64 = 1.3, polar_bar_padding: Float64 = 0.20000000000000001, polar_grid_rings: Int = Int(4), polar_grid_spokes: Int = Int(12), radar_grid_rings: Int = Int(4), gauge_start_angle: Float64 = 2.3561944901923448, gauge_sweep_angle: Float64 = 4.7123889803846897, tick_length: Int = Int(5), label_gap: Int = Int(4), legend_width: Int = Int(130), legend_swatch_size: Int = Int(14), legend_row_gap: Int = Int(8), continuous_legend_bar_width: Int = Int(14), continuous_legend_bar_height: Int = Int(100), margin_buffer: Int = Int(8), sankey_node_width: Float64 = 12, output_format: OutputFormat = OutputFormat.SVG)

Construct a Theme, overriding any subset of its fields by keyword – every parameter here is one field, same name, same default; see each field’s own docstring above for what it controls rather than this method repeating it, so a change to one never has a second copy elsewhere to fall out of sync.

Args:

  • background (Color)
  • mark_color (Color)
  • axis_color (Color)
  • gridline_color (Color)
  • text_color (Color)
  • font_size (Float64)
  • point_radius (Float64)
  • line_width (Float64)
  • margin_left (Int)
  • margin_right (Int)
  • margin_top (Int)
  • margin_bottom (Int)
  • show_gridlines (Bool)
  • color_scale_low (Color)
  • color_scale_mid (Color)
  • color_scale_high (Color)
  • size_range_min (Float64)
  • size_range_max (Float64)
  • show_legend (Bool)
  • scale (Float64)
  • donut_inner_radius_fraction (Float64)
  • color_by_sign (Bool)
  • mark_color_negative (Color)
  • bullet_range_color_light (Color)
  • bullet_range_color_dark (Color)
  • line_smoothing (Float64)
  • title_font_size (Float64)
  • subtitle_font_size (Float64)
  • subtitle_color (Color)
  • axis_title_font_size (Float64)
  • waterfall_total_color (Color)
  • annotation_color (Color)
  • annotation_area_color (Color)
  • font_family (String)
  • title_bold (Bool)
  • waterfall_delta_width_fraction (Float64)
  • bullet_measure_width_fraction (Float64)
  • chord_ring_fraction (Float64)
  • radialbar_track_color (Color)
  • treemap_label_color (Color)
  • halo_alpha (UInt8)
  • radar_fill_alpha (UInt8)
  • radialbar_ring_gap_fraction (Float64)
  • violin_width_fraction (Float64)
  • corrplot_bubble_fraction (Float64)
  • gauge_band_inner_fraction (Float64)
  • gauge_needle_fraction (Float64)
  • ridgeline_overlap (Float64)
  • polar_bar_padding (Float64)
  • polar_grid_rings (Int)
  • polar_grid_spokes (Int)
  • radar_grid_rings (Int)
  • gauge_start_angle (Float64)
  • gauge_sweep_angle (Float64)
  • tick_length (Int)
  • label_gap (Int)
  • legend_width (Int)
  • legend_swatch_size (Int)
  • legend_row_gap (Int)
  • continuous_legend_bar_width (Int)
  • continuous_legend_bar_height (Int)
  • margin_buffer (Int)
  • sankey_node_width (Float64)
  • output_format (OutputFormat)
  • self (Self)

Returns:

Self

default

@staticmethod
fn def default() -> Self

Named the same way FontSlant.NORMAL-style call sites in this workspace read – Theme.default() rather than relying on every caller remembering that Theme() alone already means the same thing (it does; this is purely for readability at call sites like .theme(Theme.default())).

Returns:

Self