Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f7387f6
Collapse an axis's layout slot when its text is switched off
sselvakumaran Sep 22, 2026
1b8798d
Name the news fragment for its PR
sselvakumaran Sep 22, 2026
3d9ebb6
Reserve a gutter for a visible axis title, and check parity on every …
sselvakumaran Sep 22, 2026
b3e9c9c
Ask whether a title is drawn before reserving its gutter
sselvakumaran Sep 22, 2026
e99e1f8
Let the tick-label strategy decide tick-label room only
sselvakumaran Sep 22, 2026
06670f6
Ask the colorbar's right-axis room the same question layout asks
sselvakumaran Sep 22, 2026
e2bc976
Read the polar recut's insets from the same visibility rules
sselvakumaran Sep 22, 2026
2bc8b0d
Reserve for tick marks and for the title band they sit beside
sselvakumaran Sep 22, 2026
c1e562b
Say in the styling spec that a drawn title reserves its measured band
sselvakumaran Sep 22, 2026
765f126
Keep the x-axis band whole, and grow a top title inward
sselvakumaran Sep 22, 2026
ce0baed
Tick geometry is not tick ink
sselvakumaran Sep 22, 2026
e7a7cc2
Reserve tick marks per side, and stop clamping what the renderers do not
sselvakumaran Sep 22, 2026
72c62bb
Round only the title band, not the tick-label band beside it
sselvakumaran Sep 22, 2026
c951089
Make a zero-width tick mean the same thing in every renderer
sselvakumaran Sep 22, 2026
13c7dd8
Let the gutter being asked about name its own dimension
sselvakumaran Sep 22, 2026
aaf39b6
Measure the two tick tiers apart, because they are drawn apart
sselvakumaran Sep 22, 2026
721a4f5
A named axis has no minor tier to reserve for
sselvakumaran Sep 22, 2026
fb8e445
Reference the tier's own length in the minor-gutter thresholds
sselvakumaran Sep 22, 2026
e9b1867
Marks with no label reserve the marks, not a label
sselvakumaran Sep 22, 2026
0114718
Merge branch 'main' into fix-axis-show
FarhanAliRaza Oct 26, 2026
4f7f3b1
Fix axis paint initialization and per-side export layout
FarhanAliRaza Nov 2, 2026
8ac457a
Relayout detached charts when their styled roots connect
FarhanAliRaza Nov 2, 2026
65e9020
Merge main into fix-axis-show and unify layout updates
FarhanAliRaza Nov 4, 2026
00ce368
Remeasure axis gutters when the chart theme changes
FarhanAliRaza Nov 4, 2026
b0b036f
Merge main into fix-axis-show and preserve font-aware gutter layout
FarhanAliRaza Nov 4, 2026
3357da5
Preserve retained chart frames during lost-context theme refreshes
FarhanAliRaza Nov 4, 2026
bae09d5
Update spec/design-dossier.md
FarhanAliRaza Nov 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/components/axes.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,13 @@ xy.x_axis(line=False, ticks=False) # tick labels, no baseline or ticks

The switches compile to ordinary axis `style` properties, so they work in HTML,
SVG, and native PNG alike, and an explicit `style=` property still wins over a
switch. `text` controls whether axis text is *drawn*; `tick_labels=` supplies
switch. An axis with nothing left to draw also reserves nothing: its tick-label
gutter collapses, on either side, so `show=False` on both axes plus `padding=0`
gives a plot that reaches the container edge — the sparkline case. Authored
`padding` is still reserved, and with no `padding` at all the label-aware
default margins still apply; what a switched-off axis no longer adds is a
gutter of its own. A grid survives that, since it
is drawn inside the plot and never needed a gutter. `text` controls whether axis text is *drawn*; `tick_labels=` supplies
the label strings.

## Style Axes
Expand Down
153 changes: 133 additions & 20 deletions js/src/50_chartview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ export class ChartView {
const bottomAxes = Object.values<any>(this.axes || {}).filter((axis: any) =>
axis && String(axis.id || "").startsWith("x") &&
(this._axisTickLabelSides(axis).includes("bottom") || axis.side !== "top") &&
this._axisTickLabelStrategy(axis) !== "none");
this._axisGutterVisible(axis));
const hasBottomAxis = bottomAxes.length > 0;
// A named x axis can own the top edge even when the primary x axis stays
// on the bottom. Reserve one shared gutter for every top-side x axis;
Expand All @@ -798,7 +798,7 @@ export class ChartView {
const topAxes = Object.values<any>(this.axes || {}).filter((axis: any) =>
axis && String(axis.id || "").startsWith("x") &&
(this._axisTickLabelSides(axis).includes("top") || axis.side === "top") &&
this._axisTickLabelStrategy(axis) !== "none");
this._axisGutterVisible(axis));
const hasTopAxis = topAxes.length > 0;
const authoredLeft = pad
? (responsivePad ? Math.min(pad[3], 46) : pad[3])
Expand Down Expand Up @@ -843,7 +843,7 @@ export class ChartView {
const rightAxes = Object.values<any>(this.axes || {}).filter((axis: any) =>
axis && String(axis.id || "").startsWith("y") &&
(this._axisTickLabelSides(axis).includes("right") || axis.side === "right") &&
this._axisTickLabelStrategy(axis) !== "none");
this._axisGutterVisible(axis));
// The vertical colorbar shifts right by this room (see _positionColorbar);
// the Python SVG/raster exporters apply the identical 42/54 rule.
this._rightAxisRoom = rightAxes.length ? (compact ? 42 : 54) : 0;
Expand Down Expand Up @@ -946,7 +946,9 @@ export class ChartView {
// `_layout` clears `_legendRect` just before this call, legend sizing and
// positioning then fell back to `this.plot` and drew the legend on top of
// the marks. Track it and skip only the inset.
const labelsHidden = this._axisTickLabelStrategy(xAxisSpec) === "none";
// The same question every cartesian gutter asks: `"off"` draws no angular
// label any more than `"none"` does, and neither does a transparent paint.
const labelsHidden = !this._axisTickLabelsVisible(xAxisSpec);
// A legend gutter comes off the canvas edge FIRST, before the disc is fitted
// to what remains, so the disc never occupies the gutter and the legend
// never occupies the disc. Mirrors the same block in `_recut_polar_plot`.
Expand Down Expand Up @@ -995,7 +997,7 @@ export class ChartView {
// natural home — and it is placed outward past the tick-label room, so a
// titled radial axis keeps its gutter whole rather than part-reclaimed.
const yAxis = this._axis("y") || {};
const titled = !!yAxis.label;
const titled = this._axisTitleVisible(yAxis);
// `canvasX0` is a left legend gutter; the label room still applies inside
// it. With no gutter it is 0 and `side >= room`, so this is the old value.
const left = Math.max(titled ? Math.max(side, p.x) : side, canvasX0 + room);
Expand All @@ -1006,7 +1008,8 @@ export class ChartView {
const xAxis = this._axis("x") || {};
// A horizontal colorbar hangs off the plot's bottom edge; extending the
// rect downward would walk it off the canvas.
const keepsBottom = !!xAxis.label || this.spec?.colorbar?.orientation === "horizontal";
const keepsBottom = this._axisTitleVisible(xAxis)
|| this.spec?.colorbar?.orientation === "horizontal";
const bottomReserve = keepsBottom ? reservedBottom : Math.min(reservedBottom, reservedTop);
const bottom = canvasH - Math.max(room, bottomReserve);
const top = reservedTop + room;
Expand Down Expand Up @@ -1074,10 +1077,12 @@ export class ChartView {
let room = 0;
for (const axis of Object.values<any>(this.axes || {})) {
if (!axis || !String(axis.id || "").startsWith("y")) continue;
const labelsOnLeft = this._axisTickLabelSides(axis).includes("left");
const titleOnLeft = axis.side !== "right";
const labelsOnLeft = this._axisTickLabelSides(axis).includes("left")
&& this._axisTickLabelsVisible(axis);
// The title is reserved separately from the tick labels, so it answers to
// its own paint: `show=False, grid=True` keeps the grid and neither text.
const titleOnLeft = axis.side !== "right" && this._axisTitleVisible(axis);
if (!labelsOnLeft && !titleOnLeft) continue;
if (this._axisTickLabelStrategy(axis) === "none") continue;
const size = Math.max(
8,
this._axisStyleNumber(
Expand Down Expand Up @@ -1109,9 +1114,7 @@ export class ChartView {
? outward + Math.max(0, this._axisStyleNumber(axis, "tick_padding", 4))
: 0;
let needed = labelsOnLeft ? 4 + tickOffset + tickRoom : 0;
const rawPosition = axis.label_position;
const position = typeof rawPosition === "string" ? rawPosition.replace(/-/g, "_") : "";
if (titleOnLeft && axis.label && !position.startsWith("inside_")) {
if (titleOnLeft) {
const labelSize = Math.max(8, this._axisStyleNumber(axis, "label_size", 12));
const gap = Number.isFinite(Number(axis.label_offset))
? Number(axis.label_offset)
Expand Down Expand Up @@ -1146,10 +1149,21 @@ export class ChartView {
for (const axis of Object.values<any>(this.axes || {})) {
if (!axis || !String(axis.id || "").startsWith("x")) continue;
const titleSide = axis.side === "top" ? "top" : "bottom";
const labelsOnSide = this._axisTickLabelSides(axis).includes(side);
if (!labelsOnSide && titleSide !== side) continue;
// Tick labels and the title each answer to their own paint. Measuring
// text that is switched off reintroduces the gutter `_axisGutterVisible`
// just collapsed: `marginBottom` below takes the MEASURED room, not the
// gated `bottomAxisRoom`, so a rotated, wrapped, or collision-stacked
// label kept its band after `show=False`.
const labelsOnSide = this._axisTickLabelSides(axis).includes(side)
&& this._axisTickLabelsVisible(axis);
const titleOnSide = titleSide === side && this._axisTitleVisible(axis);
if (!labelsOnSide && !titleOnSide) continue;
// The tick-label strategy decides tick-label room and nothing else. It
// is already folded into `labelsOnSide` through `_axisTickLabelsVisible`,
// so re-testing it here only dropped the TITLE's room: `"off"` keeps its
// title (unlike `"none"`, which suppresses it), and the exporter's
// `_x_tick_label_room` returns `title_room` for exactly that case.
const strategy = this._axisTickLabelStrategy(axis);
if (["none", "off"].includes(strategy)) continue;
const sideAxis = { ...axis, side };
const size = Math.max(
8,
Expand Down Expand Up @@ -1177,18 +1191,36 @@ export class ChartView {
const hasMultilineTicks = items.some(
(item) => this._estimateTickLabel(item.text, size).lines.length > 1,
);
const position = typeof axis.label_position === "string"
? axis.label_position.replace(/-/g, "_") : "center";
const labelSize = Math.max(8, this._axisStyleNumber(axis, "label_size", 12));
const labelBlock = titleSide === side && axis.label && !position.startsWith("inside_")
const labelBlock = titleOnSide
? this._estimateTickLabel(axis.label, labelSize) : null;
const labelExtra = labelBlock
? Math.max(0, labelBlock.h - labelSize * 1.2) : 0;
// The band the title itself needs, measured from where it is drawn:
// `p.y + p.h + 24` on the bottom, `p.y - 34` on the top (the two
// branches in `_drawAxisChrome`), plus the same 4 px canvas-edge pad the
// exporter's `_x_axis_title_room` uses. Measuring only the overflow past
// one line (`labelExtra`) reserved nothing for an ordinary one-line
// title, so at a small authored padding the title was drawn past the
// canvas edge while the exporter fitted it.
const titleOffset = Number.isFinite(Number(axis.label_offset))
? Math.max(0, Number(axis.label_offset)) : 0;
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
const titleRoom = labelBlock
? 4 + titleOffset + (side === "top" ? 34 : 24 + labelBlock.h)
Comment thread
sselvakumaran marked this conversation as resolved.
Resolved
: 0;
Comment thread
sselvakumaran marked this conversation as resolved.
Resolved
// Preserve the long-standing flat band for ordinary horizontal text.
// An axis drawing no tick label at all qualifies as much as `auto` does:
// there is no label to force a taller band, so it keeps the flat one
// rather than measuring a tick offset for rows that do not exist. A
// title is measured either way — it is not tick-label geometry, and the
// flat band is not always big enough to hold it.
const flatTickBand = !labelsOnSide || strategy === "auto";
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
if (
!hasAdaptiveLayout
&& !hasMultilineTicks
&& !labelExtra
&& strategy === "auto"
&& !titleRoom
&& flatTickBand
&& this._axisTickLabelAngle(axis) === null
) {
continue;
Expand Down Expand Up @@ -1218,7 +1250,9 @@ export class ChartView {
offset = outward + this._axisStyleNumber(axis, "tick_padding", 4)
+ (side === "top" ? size * 0.2 : size * 0.8);
}
room = Math.max(room, 4 + offset + rows * (size + 4) + extent + labelExtra);
// The title's band and the tick labels' band both start at the plot
// edge, so the axis needs the larger, not their sum.
room = Math.max(room, titleRoom, 4 + offset + rows * (size + 4) + extent + labelExtra);
}
return room;
}
Expand Down Expand Up @@ -7524,6 +7558,85 @@ export class ChartView {
return style && Object.prototype.hasOwnProperty.call(style, key) ? style[key] : undefined;
}

// Whether an axis text paint can contribute visible ink. The visibility
// shorthands compile to TRANSPARENT CSS colors rather than to a flag
// (`_axis_visibility_style`, python/xy/components.py), so layout has to ask
// the paint whether anything will be seen — otherwise `show=False` reserves
// a gutter for text nobody can read and cannot produce the documented
// edge-to-edge sparkline. An unknown or browser-only paint stays
// conservative and keeps its room.
// Mirrors `_axis_text_paint_visible` in python/xy/_svg.py, which is why the
// SVG and PNG exporters already collapse this gutter and the browser did not.
_axisTextPaintVisible(axis, key, fallbackKey?) {
let paint = this._axisStyleValue(axis, key);
if (paint === undefined && fallbackKey) paint = this._axisStyleValue(axis, fallbackKey);
if (paint === undefined || paint === null) return true;
return parseColor(this.root, paint, [0, 0, 0, 1])[3] !== 0;
Comment thread
FarhanAliRaza marked this conversation as resolved.
Resolved
}

// Whether this axis's tick labels claim gutter room at all: a strategy that
// draws none, or a paint that shows none, claims nothing. `none` and `off`
// are the two strategies that draw no label, and `_xAxisRoom` and
// `_axis_tick_label_room` (python/xy/_svg.py) already skip both.
_axisTickLabelsVisible(axis) {
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
return !["none", "off"].includes(this._axisTickLabelStrategy(axis))
&& this._axisTextPaintVisible(axis, "tick_label_color", "tick_color");
}

// Whether this axis claims a gutter at all. Tick labels and the axis title
// are separate paints, so either one being visible reserves the band: with
// transparent ticks and an opaque title, gating on the ticks alone drew the
// title into a gutter that no longer existed — off the canvas for a top or
// bottom axis, over the plot for a right-side one. The left gutter already
// measured the two separately (`_yAxisLeftRoom`); this is the same rule for
// the sides that reserve a flat or measured band instead.
_axisGutterVisible(axis) {
return this._axisTickLabelsVisible(axis)
|| this._axisTitleVisible(axis)
|| this._axisOutwardTickRoom(axis) > 0;
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
}

// How far this axis's tick marks reach outside the plot, in px. Tick marks
// are chrome of their own: they answer to no text paint, so an axis with its
// labels switched off can still need the gutter for them, and the colorbar
// beside it still has to clear them. The core default `tick_length` is 0, so
// an unstyled axis reaches nothing, and the `ticks=False`/`show=False`
// shorthand's `tick_length: 0, tick_width: 0` sentinel reaches nothing
// either. Mirrors `_axis_outward_tick_room` in python/xy/_svg.py.
_axisOutwardTickRoom(axis) {
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
const length = Math.max(0, this._axisStyleNumber(axis, "tick_length", 0));
if (length <= 0 || this._axisStyleNumber(axis, "tick_width", 1) <= 0) return 0;
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
const direction = String(this._axisStyleValue(axis, "tick_direction") || "out");
if (direction === "in") return 0;
return direction === "inout" ? length / 2 : length;
}

// Whether this axis draws a title into the gutter, which is what makes the
// title worth reserving room for. Three separate conditions, each matched to
// what the renderers actually do:
//
// - `tick_label_strategy: "none"` suppresses the title as well as the
// labels, in both renderers (the two title branches in `_drawAxisChrome`
// below, and `_axis_label_geometry` in python/xy/_svg.py). Crediting a
// title there reserves a band nothing is drawn into. `"off"` is the
// narrower switch and keeps the title.
// - The title answers to `label_color` and nothing else: both renderers
// paint it from that key alone (`kind === "label"` below, and
// `_css(axis_style.get("label_color"), ...)`), with no `tick_color`
// fallback. Reading a transparent `tick_color` as a hidden title drops
// the gutter out from under a title that is still drawn.
// - An `inside_*` title is drawn over the plot and needs no gutter at all.
//
// Mirrors `_axis_title_visible` in python/xy/_svg.py.
_axisTitleVisible(axis) {
if (!axis || !axis.label) return false;
if (this._axisTickLabelStrategy(axis) === "none") return false;
const raw = axis.label_position;
const position = typeof raw === "string" ? raw.replace(/-/g, "_") : "center";
if (position.startsWith("inside_")) return false;
return this._axisTextPaintVisible(axis, "label_color");
}

_axisGridDash(axis) {
const value = String(this._axisStyleValue(axis, "grid_dash") || "solid");
if (value === "dashed") return [6, 4];
Expand Down
23 changes: 23 additions & 0 deletions news/522.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
`xy.x_axis(show=False)` and `xy.y_axis(show=False)` now collapse the axis's
layout slot instead of painting an invisible axis in a gutter it still
occupies. With `padding=0` a chart whose axes are switched off reaches the
container edge — the sparkline case the axes docs describe — rather than
sitting 25 px in, and a hidden right-side axis no longer reserves its flat
54 px. Without an authored `padding` the label-aware default margins still
apply, as they always have; what changes is that a hidden axis no longer adds
its own gutter on top. The visibility shorthands compile to transparent paints
rather than to a flag, and the browser was measuring that invisible text back
into the gutter; the SVG and PNG exporters already skipped it on the left, so
the same chart exported flush and rendered inset. Both renderers now ask the
same question about the paint, on every side. `tick_label_strategy="off"` now
claims no tick-label room, the way `"none"` already did, while keeping the room
for the title it still draws — `"none"` suppresses that title too. Outward tick
marks answer to no text paint at all, so an axis that draws only those keeps
its band. A gutter is kept for an axis title only where a title is actually
drawn — not under
`tick_label_strategy="none"`, which suppresses the title as well, and not for an
`inside_*` title, which is drawn over the plot. Polar charts read the same
rules: switching the angular labels off reclaims the disc's inset whichever
switch does it, and the radial and angular titles keep their gutters only while
they are drawn. Axes that draw their text reserve exactly the room they did
before.
Loading
Loading