Grid Plot Layout#
Grid plot layout drives the --shape grid mode in blobtk, which renders a multi-panel scatter plot where each panel shows a windowed slice of a sequence. The feature was introduced in PR #12 "Feature/grid-plot-shape". The two primary source files are:
rust/src/plot.rsβ grid dimension calculation,GridSizestruct, and the top-levelplot_grid()orchestratorrust/src/plot/blob.rsβ SVG rendering of the grid viablob::plot_grid()
Grid Dimension Calculation#
calculate_grid_size(num_items) returns (num_cols, num_rows) targeting the most square layout possible:
- Start from
floor(sqrt(num_items))for both dimensions. - If items don't fit, increment
num_rows(up to twice) to form annΓ(n+1)ornΓ(n+2)rectangle. - If still not enough, increment
num_colsand revertnum_rowsto produce an(n+1)Γ(n+1)square.
Cells are iterated column-major: col = i / num_rows, row = i % num_rows .
GridSize Struct#
GridSize is the central layout descriptor:
| Field | Purpose |
|---|---|
col_widths: Vec<f64> | Per-column widths (may be non-uniform) |
row_height: f64 | Uniform row height |
ratios: Vec<f64> | Proportional width ratios per column |
margin | Per-cell inner margin (TopRightBottomLeft) |
padding | Per-cell padding (TopRightBottomLeft) |
outer_margin | Outer margin for the whole grid |
GridSize::new() computes these values with the following hard-coded defaults :
- Inner margin (bottom/left): 25 px
- Padding: 10 px on all sides
- Outer margin (bottom/left): 50 px
row_height is (height β outer_bottom β outer_top) / num_rows .
Column Width Calculation#
Column widths support two modes :
- Uniform (no ratios):
col_width = (width β outer_margins) / num_cols. Each column gets the same width. - Proportional (ratios provided): Each column width is scaled by
ratio[i] / sum(ratios) Γ num_cols, then padded with margin/padding. This is used whenx_field = "position"and no explicitx_limitis set, so columns reflect actual genomic span .
When x_field = "position", ratios are derived from the per-column maximum x-value relative to the global x-max, rounded to the nearest tenth . Axis x-limits are then scaled per column by limits["x"][1] * ratio[col] so each panel's x-axis reflects only the span of its column's sequences .
Sequence Title Truncation#
Each subplot optionally displays a sequence title sourced from BlobData.title . Truncation logic in blob::plot_grid():
- Condition:
title.len() > 3ANDtitle.len() * 10.0 > col_widths[col] - Truncation:
title[..(col_width / 10.0) as usize β 3]+"..." - Heuristic: ~10 pixels per character (no actual font measurement)
Titles are rendered as SVG <text> elements at 75% of the base font size (20 px β 15 px), centered horizontally at the top of each cell using text-anchor: middle and dominant-baseline: hanging .
Axis Label Suppression#
To reduce clutter, tick labels are suppressed selectively :
- X-axis tick labels: shown only on the last row, or the final item.
- Y-axis tick labels: shown only on the first column (
col == 0).
Global x/y axis labels are rendered once, outside all cells, centered against the full grid dimensions .