Skip to content

kuva v0.4.0

Choose a tag to compare

@Psy-Fer Psy-Fer released this 09 Jul 08:37
· 143 commits to main since this release
7778472

[0.4.0] — 2026-07-09

Added

  • Black & white / accessibility mode (resolves #14) — Layout::with_bw_mode() / CLI --bw redraws any plot so it stays legible without relying on color: discrete series (bar, box, violin, pie, area, …) cycle through 5 grey shades × 7 hatch patterns (35 combinations before any repeat), line plots cycle through 4 dash styles, scatter/point plots cycle through 6 marker shapes, and continuous colormaps (heatmap, hexbin, contour, calendar, …) are forced to a grayscale ramp. Works on every plot type, including pixel-space/composite plots (Chord, Sankey, PhyloTree, Synteny, Network, Treemap, Sunburst, Clustermap) which each needed a bespoke fill/stroke treatment. See Reference → Black & White / Accessibility Mode.

Changed

  • Text width is now measured from real DejaVu Sans glyph advances instead of a per-call-site char_count × font_size × factor heuristic. A single text_metrics module measures every axis tick label, legend entry, title, and in-plot label against the bundled font's actual advance widths (shipped as a precompiled table, so the SVG-only default build gains real metrics with no new runtime dependency). Layout reservations now match what is rendered — exact for PNG/PDF and embed_font SVG, a close fails-safe estimate for bare SVG — which removes a class of label-clipping and label-overlap issues and tightens over-wide legend boxes. Non-ASCII/multi-byte labels are measured by glyph rather than UTF-8 byte length, so they are no longer over-reserved 2–3×.
  • Default font cascade now lists Verdana before the Arial-family fallbacks — DEFAULT_FONT_FAMILY is now "DejaVu Sans, Verdana, Liberation Sans, Arial, sans-serif". Layout reserves space using DejaVu Sans metrics, but when DejaVu is unavailable (the common case for bare SVG on Windows/macOS, where it is not installed) the consumer substitutes the next family in the cascade. Verdana shares DejaVu's Bitstream Vera lineage and is a near-exact metric match (~1.5% mean width difference vs. ~12% for Arial/Liberation/Helvetica), and ships on essentially all Windows and macOS systems — so labels render at close to the reserved size. Linux still resolves to DejaVu (exact) or Liberation as before.
  • Vertical text is now positioned from real DejaVu Sans metrics instead of font_size × factor guesses. The text_metrics module gained ascent/descent/cap-height/x-height/line-height accessors (measured from the bundled face and shipped in the precompiled table alongside the advance widths), and the vertical text quantities — line heights, title/axis/tick-label baselines, reserved band and box heights, and cap-height centring — are now driven by them, across both the core layout and the individual plot types (axis ticks, dice, venn, bump, streamgraph, calendar, multi-panel figure labels, …). Cap-height-based centring (cap_height / 2) replaces the ubiquitous font_size × 0.35 guess, so text sits on its true optical centre and tracks the font instead of assuming a fixed ratio. Deliberately-loose leading (e.g. TextPlot, radar, legend list spacing) is left as a typographic choice, not a metric.

Fixed

  • Colorbar tick labels no longer clip at the canvas edge — the colorbar's right-margin reservation was a fixed 90 px, so a wide tick label (e.g. a 6-digit 100000 on a large-count hexbin) overran the 30 px label allotment and clipped against the canvas edge. The reservation and the colorbar's horizontal inset are now sized to the widest tick label, measured after applying with_colorbar_tick_format (Layout::auto_from_plots collects the colorbar's tick values so the width can be computed once the final format is known). When the canvas width is fixed too narrow for the full reservation, the tick-label font is shrunk to fit the available band rather than clipping. Hand-built layouts (no auto_from_plots) keep the previous fixed reservation.
  • Log/count colorbars now honour Layout::with_colorbar_tick_format — the log-scale colorbar used by HexbinPlot and Histogram2D (with log colouring) generated its own hard-coded power-of-ten integer labels and ignored the configured colorbar tick format, so a custom formatter (e.g. an SI formatter producing 1k, 10k, 100k) had no effect. ColorBarInfo gains a tick_values field carrying (position, value) pairs; the value is formatted through with_colorbar_tick_format at render time, matching how the linear colorbar already behaved. Default (TickFormat::Auto) output is unchanged for integer count labels.
  • Colorbar tick overprint on log/count colorbars — the log-scale colorbar (hexbin and 2-D histogram with log colouring) appends a tick at the exact data maximum in addition to the nearest power-of-ten tick. In log space the two can sit a fraction of a decade apart, so their labels overprinted at the top of the bar. Adjacent colorbar tick labels closer than one label height are now thinned — entries are drawn bottom-to-top and the first of any too-close pair is kept, so the round decade tick survives and the redundant data-max label is dropped only when it would actually collide.
  • Figure-embedded colorbars lost the width-aware label reservation — clone_layout didn't copy the new colorbar_tick_values field, so any colorbar inside a multi-panel Figure silently fell back to the legacy fixed reservation instead of sizing to its widest label.
  • Treemap/Sunburst colorbars were excluded from the width-aware label reservation — both set up a colorbar but had no arm in the estimator that collects tick values for sizing, so large values (7+ digit labels) relied entirely on the render-time font-shrink fallback instead of a properly sized reservation.
  • PopulationPyramid single-series legend width ignored the actual label text — the left_label/right_label legend never measured real text width, leaving the legend box pinned at a bare 40px offset regardless of label length, so long labels could overflow the box.
  • HorizonPlot +/- sign-to-value spacing used an average character width instead of the actual glyph width, producing a visibly inconsistent gap after + vs -.
  • Figure's shared multi-panel legend kept a stale 80px minimum width after the rest of the legend-sizing code moved to content-hugging real-metric widths, so short shared legends were padded wider than necessary.
  • Titles and labels no longer clip or overlap when enlarged — figure and jointplot title bands now scale with title_size (they were fixed 30/35 px and clipped larger titles); wrapped title and axis-label lines stack by real line height; and rotated x-tick labels and staggered second rows reserve their true vertical extent, fixing clipping at steep angles and crowding of the x-axis title.
  • Heatmap and brick in-cell value labels are centred on their true cap-height midpoint (they previously rode high). Heatmap labels also shrink uniformly to fit the cell and drop rather than overflow into neighbours when cells are too short to render legibly — and a single wide outlier value no longer shrinks the whole grid below the floor and blanks every label (the too-wide value is dropped instead).
  • Legend boxes hug their contents — comfortable body_size-scaled row leading with the box sized to the rows actually drawn, so legends no longer carry uneven top/bottom padding or a fixed row height that overflowed at larger body sizes; applied consistently across the main, standalone, and figure legend paths.
  • The x-axis title renders on tick-suppressed plots — Manhattan plots (which draw their own chromosome labels) keep the "Chromosome" title, and the bottom margin reserves room for it so it clears those labels instead of overprinting them.
  • scatter3d --color-by legend box was over-wide — the CLI sized the box with a char-count proxy plus a hard 80px floor, leaving dead space beside short group labels. Now routes through the shared Layout::with_legend_entries, which measures the widest label (box 80 → 49px for typical short labels).
  • Colorbar tick-label band was mildly under-reserved for long labels — the last width estimate left over from before the text-metrics work used max_chars × tick_size × 0.6; DejaVu's digit advance is closer to 0.636em, so 6-digit labels were reserved a couple of px narrower than needed. Now measures each formatted label directly.
  • Minor gridlines now cover the whole plot area — minor ticks were only generated between consecutive major ticks, so when an axis range didn't start or end on a major tick (explicit with_x_axis_min/with_x_axis_max, clamped, histogram bin-edge, or log ranges) the leading and trailing bands beyond the outer majors had no minor gridlines (or minor tick marks). Minors are now generated as if one more major tick existed just past each end — a geometric step on log axes (the next power of ten, preserving the familiar wide-to-squished 2..9 per-decade spacing) and an arithmetic step otherwise — then filtered to the axis range, so the partial intervals fill correctly without anything drawn outside the plot.
  • Categorical axes no longer leave dead space past the last category — the render-time axis-range step ran auto_nice_range on every axis without a log/clamp/histogram guard, so a categorical axis (bar, box, violin, waterfall, candlestick, pyramid, strip, dot plot, …) had its exact [0.5, n+0.5] slot extent rounded outward to a "nice" number — e.g. [0.5, 20.5] → [0, 25] for a 20-bar chart, leaving ~108 px of empty plot area to the right of the last bar (and the analogous gap on the categorical axis of other layouts). Categorical axes now use their exact category extent (mirroring the existing histogram guard); their tick marks come from the category list rather than the numeric range, so the bars/boxes fill the plot width.
  • Continuous axes no longer over-provision when the data's max already lands on a "nice" tick (resolves #98) — a small breathing-room pad is added to the raw data range before nice-rounding so a data point at the exact boundary doesn't render flush against the plot edge, but when the raw max was itself already a multiple of the chosen tick step, even that tiny pad was enough to round a whole extra major tick onto the axis — e.g. data spanning [0, 20] on a step-5 grid rounded out to (0, 25), a phantom tick with a quarter of the plot as dead space. The margin added in that specific case is now capped at min(half a tick step, 5% of the data's span) instead of a full tick, and the resulting boundary may not itself land on a tick (ticks are generated separately and simply stop at the boundary). Axes where the data does not land exactly on a tick are unaffected — ordinary nice-rounding already provides natural headroom there.
  • Legend line swatches truncated multi-segment dash patterns — the swatch line for a LegendShape::Line entry was a fixed 12px regardless of dash pattern, so LineStyle::DashDot's "8 4 2 4" cycle (18px per repeat) was cut off right after its dash and gap — the dot segment never rendered, making the legend swatch look like a plain dash. The swatch now sizes to fit at least one full pattern repeat (capped so it can't run into the label text); solid and short patterns (Dashed, Dotted) are unaffected since they already fit within 12px.

Pull Requests

  • Fix data-max tick overprinting the top decade on log/count colorbars by @tfenne in #91
  • Honor with_colorbar_tick_format on log/count colorbars by @tfenne in #92
  • Size colorbar tick-label reservation to the widest label (+ shrink-to-fit) by @tfenne in #93
  • Add Verdana as the first fallback font after DejaVu Sans by @tfenne in #94
  • Measure text width from real font metrics to reduce clipping and/or over-sizing text areas by @tfenne in #95
  • Calculate text height from font metrics, and use it in as many places as possible vs. proxies/estimates by @tfenne in #96
  • A small handful of width fixes I missed on the first pass by @tfenne in #97
  • Don't nice-round categorical axes past their exact [0.5, n+0.5] extent by @tfenne in #99
  • Ensure minor ticks and gridlines are rendered beyond last major tick/grid when needed by @tfenne in #101
  • v0.4.0 release candidate by @Psy-Fer in #103

Full Changelog: v0.3.0...v0.4.0