Skip to content
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e789a1e
Add xy.tooltip(mode="x"|"y"): a shared-axis tooltip with cursor and a…
Alek99 Sep 2, 2026
2666988
Add news fragment for the shared-axis tooltip (#509)
Alek99 Sep 2, 2026
f34cd6d
Band tooltips: bars join by footprint, survive context loss, keep hov…
Alek99 Sep 2, 2026
9cf6b2f
Fix the band tooltip's hidden-row scan, stale picks, dot size and bar…
sselvakumaran Sep 22, 2026
6d33983
Merge main into the shared-axis tooltip branch
sselvakumaran Sep 22, 2026
ed01bdf
Pin the band tooltip fixes with browser regression tests
sselvakumaran Sep 22, 2026
80b1537
Keep the band inside the plot, out of retired traces, and intact when…
sselvakumaran Sep 22, 2026
4a542b6
Keep the cursor on a clipped bar, honor fields=["x"], drop the band o…
sselvakumaran Sep 22, 2026
872c139
Ask the perpendicular axis the same visibility question
sselvakumaran Oct 1, 2026
32bd953
Measure band visibility per axis, and keep the cursor's footprint in …
sselvakumaran Oct 1, 2026
736b3a1
Decode the animated baseline with the metadata it was written with
sselvakumaran Oct 1, 2026
ba2768a
Merge branch 'main' into alek/tooltip-x-band
FarhanAliRaza Oct 26, 2026
b74198a
Format dates and times in tooltips, in one grammar with the numbers (…
sselvakumaran Nov 4, 2026
ec77158
Merge remote-tracking branch 'origin/main' into alek/tooltip-x-band
sselvakumaran Dec 3, 2026
50c6d65
Fix decimated shared-axis tooltips with canonical coordinate picks
sselvakumaran Dec 3, 2026
3bcc347
Serve sibling module fixtures in HTTP browser probes
sselvakumaran Dec 3, 2026
74e4f08
Stop a timed-out benchmark worker before it makes its group
FarhanAliRaza Dec 3, 2026
8e60833
Default line and area charts to the shared-x tooltip
FarhanAliRaza Dec 3, 2026
90cf590
Let an excluded mark under the pointer win over the band
FarhanAliRaza Dec 3, 2026
2dcb098
Address shared-tooltip review findings and guard coordinate pick comp…
sselvakumaran Dec 3, 2026
0d79b06
Measure copied time fields on their supplier; skip polar default
FarhanAliRaza Dec 3, 2026
5ee1554
Merge concurrent tooltip fixes and retain protocol and regression saf…
sselvakumaran Dec 3, 2026
27f9c4d
Pin benchmark worker identity and restrict mixed-hover geometry scans
sselvakumaran Dec 3, 2026
7a92391
Place worker cleanup deadlines in benchmark methodology
sselvakumaran Dec 3, 2026
94aa414
Match animated bar hover footprints to shader width interpolation
sselvakumaran Dec 3, 2026
f94841c
Refresh animated bar cursor spans and verify pixel boundaries
sselvakumaran Dec 3, 2026
2801244
Clear band hover before releasing WebGL trace resources
sselvakumaran Dec 3, 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
40 changes: 24 additions & 16 deletions benchmarks/bench_vs.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from __future__ import annotations

import argparse
import contextlib
import gc
import io
import json
Expand All @@ -59,6 +60,7 @@
import time
import tracemalloc
from collections.abc import Callable
from multiprocessing.connection import wait as wait_for_process
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -244,25 +246,30 @@ def _measurement_worker(send, factory, x, y, n, capture_artifact, chromium) -> N


def _stop_process_tree(process) -> None:
"""Terminate a worker and renderer descendants, escalating to SIGKILL."""
if not process.is_alive():
process.join()
"""Stop the owned worker group before reaping its leader.

``is_alive``, ``exitcode`` and ``join`` can reap an exited worker. Until
group cleanup finishes, wait only on its sentinel: an unreaped leader pins
the numeric PID/PGID, so the final sweep cannot hit a recycled group.
The caller owns this child and must not poll/reap it before this function.
"""
if process._popen is None or process._popen.returncode is not None:
# Already reaped: its numeric identity is no longer safe to signal.
return
try:
os.killpg(process.pid, signal.SIGTERM)
except ProcessLookupError:
pass
except OSError:
process.terminate()
process.join(timeout=0.25)
if process.is_alive():
try:
os.killpg(process.pid, signal.SIGKILL)
except ProcessLookupError:
pass
except OSError:
process.kill()
process.join()
# The worker may not have called setsid yet. Signal its pinned PID,
# then sweep again before join in case a late setsid made a group.
with contextlib.suppress(ProcessLookupError):
os.kill(process.pid, signal.SIGTERM)
wait_for_process([process.sentinel], timeout=0.25)
try:
os.killpg(process.pid, signal.SIGKILL)
except ProcessLookupError:
with contextlib.suppress(ProcessLookupError):
os.kill(process.pid, signal.SIGKILL)
process.join()


def _run_measurement_process(
Expand Down Expand Up @@ -293,7 +300,8 @@ def _run_measurement_process(
try:
result = receive.recv()
except EOFError:
result = {"status": f"failed(worker exited with code {process.exitcode})"}
_stop_process_tree(process)
return {"status": f"failed(worker exited with code {process.exitcode})"}
_stop_process_tree(process)
return result
_stop_process_tree(process)
Expand Down
141 changes: 139 additions & 2 deletions docs/components/tooltips.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ angle out, since the cursor is already sitting on it. An authored spoke label
survives, so a radar category reads `power` rather than a number, and
`labels={"x": ...}` opts the angle back in formatted through the theta axis.
Explicit `title=` and `fields=` continue to control a customized readout.
Line and area charts are the exception: they default to the
[shared tooltip along x](#shared-tooltip-along-an-axis), which lists every
series at the hovered x.

~~~python demo exec
import reflex_xy
Expand Down Expand Up @@ -84,14 +87,90 @@ def tooltip_fields_demo():
~~~

Braced field names in `title` are replaced from the hovered row. `format` maps
source field names to the client's numeric format strings, while `labels` maps
those same source names to presentation text. Labels never change title
source field names to format strings — numeric specs such as `",.0f"` and
`".1%"`, or strftime patterns such as `"%b %d, %Y"` on date and time values
(see [Time and Date Values](#time-and-date-values)) — while `labels` maps those
same source names to presentation text. Labels never change title
placeholder lookup or the event payload. When `fields` is omitted, `labels`
renames the matching default x/y/color/size rows; direct array channels can use
the channel names `"x"`, `"y"`, `"color"`, and `"size"`. A source column that
is not bound to a rendered channel is not shipped merely because its name
appears in `fields`.

### Time and Date Values

A datetime column formats with a strftime pattern in the same `format=` map.
The tokens are `%Y %m %d %H %M %S %b %B`, the set the axis labels use:

~~~python demo exec
import datetime

import reflex_xy
import xy

tooltip_time_start = datetime.datetime(2026, 9, 17, 10, 0)
tooltip_time_data = {
"time": [tooltip_time_start + datetime.timedelta(hours=6 * i) for i in range(16)],
"yes": [0.41, 0.44, 0.43, 0.47, 0.52, 0.55, 0.53, 0.58,
0.61, 0.59, 0.64, 0.68, 0.66, 0.71, 0.74, 0.72],
}

tooltip_time_chart = xy.line_chart(
xy.line(x="time", y="yes", data=tooltip_time_data, name="Yes"),
xy.tooltip(
mode="x",
format={"time": "%b %d, %Y, %H:%M", "yes": ".0%"},
labels={"yes": "Yes"},
),
)


def tooltip_time_demo():
return reflex_xy.chart(tooltip_time_chart, height="320px")
~~~

With no `format=` for a time field, the tooltip does not fall back to a raw
timestamp. For a field on the x or y axis it uses that axis's own `format=`
when the axis has a strftime one, so the tooltip and the tick labels beneath it
read alike; otherwise it picks the pattern the visible span reads best in —
`Sep 17, 2026` for a span of 28 days or more, `Sep 17, 10:05` from a minute up
to that, and `10:05:00` from a second up to a minute. Zoom in and the tooltip
sharpens with the axis. Below a second the ISO timestamp stays, because it is
the only form that carries milliseconds.

How closely your data is sampled sharpens that clock: a pattern the chart
picks for you is never coarser than the gap between the hovered point and the
one beside it, so neighbouring points always read differently. Ten-second
readings over a three-minute window read `Sep 17, 10:00:10`, not the
`Sep 17, 10:00` the span alone would give them and that every point of that
minute would share. The date the window called for stays — precision is added
to it, never swapped for it, so a per-second series two months wide reads
`Sep 17, 2026, 10:00:10`. Sampled finer than a second, there is no pattern
left to sharpen to, so the ISO timestamp comes back whatever the window —
500 ms readings three minutes wide read the full stamp, not `Sep 17, 10:00`.

A pattern you wrote yourself is used exactly as written, including one the
tooltip inherits from the axis — that is the point of the inheritance, so the
tooltip and the ticks beneath it agree. If `xy.x_axis(format="%H:%M")` is too
coarse to tell your points apart, write the seconds in.

Because the format is chosen per field, one chart can carry a precise
timestamp in the tooltip and short labels on the axis:

~~~python
xy.line_chart(
xy.line(x="time", y="yes", data=data),
xy.x_axis(format="%b %d"), # axis: Sep 17
xy.tooltip(format={"time": "%b %d, %Y, %H:%M"}), # tooltip: Sep 17, 2026, 10:05
)
~~~

`format=` works on its own — without `fields=` or `title=` — in which case it
formats the default x/y/color/size rows in place. It addresses values: a
categorical colour row is a category name rather than a value, and the readouts
that compositions define for themselves (sankey flows and node totals, funnel
stages) carry their own text, so neither takes a format.

### Title Templates Across Multiple Series

One tooltip configuration serves every mark in the chart: the braced `{day}`
Expand Down Expand Up @@ -130,6 +209,9 @@ tooltip_title_chart = xy.line_chart(
title="Day {day}",
fields=["revenue", "forecast", "margin"],
format={"revenue": ",.0f", "forecast": ",.0f", "margin": ".1%"},
# One readout per hovered mark; a line chart otherwise lists every
# series at the hovered x.
mode="nearest",
),
xy.legend(loc="upper left"),
title="Daily revenue vs forecast",
Expand Down Expand Up @@ -193,6 +275,51 @@ See [Events and callbacks](/docs/xy/api-reference/events-and-callbacks/) for
hover payloads and [Marks and components reference](/docs/xy/api-reference/marks-and-components/)
for the exact tooltip signature.

## Shared Tooltip Along an Axis

`xy.tooltip(mode="x")` turns the tooltip into an axis tooltip, the model
Recharts uses by default and Plotly calls `hovermode="x unified"`. The pointer
only has to be inside the plot: its horizontal position snaps to the nearest x
value and every series' point at that x is listed at once, while the vertical
position is ignored. The plot divides into full-height bands with boundaries
halfway between adjacent points, a cursor line marks the selected x, each
series shows an active dot, and the tooltip follows the pointer. Bars join by
their footprint: a grouped bar chart lists every series of the category under
the pointer, with one cursor on the category centre — and no active dots, since
the bar is already the mark. `mode="y"` does the same along
the y axis — useful for horizontal layouts, but available on any Cartesian
chart. `mode="nearest"` keeps the 12 px nearest-point behavior.

`line_chart` and `area_chart` use `mode="x"` by default, as Plotly's line
charts use `"x unified"`, unless their tooltip has a custom `render`, which is
written for one hovered row, or the chart is polar. Every other chart defaults to `mode="nearest"`.
An explicit `mode` always wins, so `xy.tooltip(mode="nearest")` returns a line
chart to the single-point tooltip.

~~~python demo exec
import reflex_xy
import xy

pages = ["Page A", "Page B", "Page C", "Page D", "Page E", "Page F", "Page G"]
shared_tooltip_chart = xy.line_chart(
xy.line(pages, [2400, 1398, 9800, 3908, 4800, 3800, 4300], name="pv", color="#8884d8", width=2),
xy.line(pages, [4000, 3000, 2000, 2780, 1890, 2390, 3490], name="uv", color="#82ca9d", width=2),
xy.tooltip(mode="x"),
xy.legend(loc="upper right"),
title="Hover anywhere above a page",
)


def shared_tooltip_demo():
return reflex_xy.chart(shared_tooltip_chart, height="320px")
~~~

`fields=`, `format=`, and `title=` keep their meaning: the title template
resolves against the first series' row, and each series row shows the
requested fields (minus the band axis, which is already the title). Style the
cursor line through the `tooltip_cursor` slot or the `--chart-crosshair`
token it shares with the crosshair.

## FAQ

### How do I show values on hover in a Python chart?
Expand All @@ -202,6 +329,16 @@ the available x/y values plus any encoded color or size values. Add
`xy.tooltip()` as a chart child only when you want to choose fields, formats,
or a title template.

### How do I show a formatted date or time in a tooltip?

Pass a strftime pattern for that column, e.g.
`xy.tooltip(format={"time": "%b %d, %Y, %H:%M"})`. It applies wherever the value
appears — a field row, a `title=` placeholder, or the band title under
`mode="x"`. With nothing passed, a time value follows the axis `format=` if
there is one, and otherwise the visible span, never coarser than your data's
own sampling. See
[Time and Date Values](#time-and-date-values).

### How do I customize which fields a tooltip shows and how numbers are formatted?

Pass `fields=` and `format=` to `xy.tooltip()`, e.g.
Expand Down
3 changes: 2 additions & 1 deletion docs/styling/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and *does the change survive where I need it*. This page answers both from the
registry the implementation is checked against.

- **11** mark style properties across **22** mark kinds, drawn by all three renderers.
- **48** stable chrome slots for CSS and Tailwind in the browser.
- **49** stable chrome slots for CSS and Tailwind in the browser.
- **1** way to add a mark kind XY does not ship, without forking it.

## Mark style properties
Expand Down Expand Up @@ -79,6 +79,7 @@ token bag or in mark and axis `style=`, which every renderer reads.
| `tooltip_row` | full | none | none |
| `tooltip_label` | full | none | none |
| `tooltip_value` | full | none | none |
| `tooltip_cursor` | full | none | none |
| `modebar` | full | none | none |
| `modebar_drag_handle` | full | none | none |
| `modebar_control_group` | full | none | none |
Expand Down
5 changes: 3 additions & 2 deletions docs/styling/chrome-slots.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ primitive or structural descendant is a separate DOM element.
| `tooltip_row` | One tooltip field row |
| `tooltip_label` | One tooltip field label |
| `tooltip_value` | One formatted tooltip value |
| `tooltip_cursor` | Line across the plot at the shared-tooltip band coordinate — vertical for `xy.tooltip(mode="x")`, horizontal for `mode="y"` |
| `modebar` | Mode/tool bar container |
| `modebar_drag_handle` | Draggable grip revealed beside the toolbar |
| `modebar_control_group` | Selection, pan, and export control group |
Expand Down Expand Up @@ -358,8 +359,8 @@ apply it with. Rather than leave that to be discovered, it is a contract:
| --- | --- | --- | --- |
| mark / axis `style=` | yes | yes | yes |
| chart-level `style=` (design tokens) | yes | yes | yes |
| `styles={slot: {...}}` | yes, all 48 slots | text subset, 9 slots | text subset, 9 slots |
| `class_names={slot: "..."}` | yes, all 48 slots | dropped | dropped |
| `styles={slot: {...}}` | yes, all 49 slots | text subset, 9 slots | text subset, 9 slots |
| `class_names={slot: "..."}` | yes, all 49 slots | dropped | dropped |
| `custom_css=` | yes | raises | raises |
| `xy.legend(style=...)` | yes | 6 keys | 6 keys |
| `xy.colorbar(style=...)` | yes | dropped | dropped |
Expand Down
2 changes: 1 addition & 1 deletion js/src/00_header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// v14: `legend.loc = "outside top"`, a legend band the plot shrinks for. A v13
// client token-matches `top` and draws an in-plot `upper center` legend over
// the marks the band exists to keep clear.
export const PROTOCOL = 14;
export const PROTOCOL = 15;

// One wire-column -> generic GL-slot contract for funnel geometry. Object
// insertion order is also the instance-attribute order used by build, filter,
Expand Down
1 change: 1 addition & 0 deletions js/src/20_theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export const XY_CHROME_CSS = `
:where(.xy [data-xy-selection-lasso-handle]){fill:var(--chart-bg,#fff);stroke:var(--chart-selection,var(--xy-selection));stroke-width:1.5;cursor:grab;pointer-events:all}
:where(.xy [data-xy-selection-lasso-handle][data-xy-active]){cursor:grabbing;fill:var(--chart-selection,var(--xy-selection))}
:where(.xy [data-xy-slot="crosshair_x"],.xy [data-xy-slot="crosshair_y"]){background:var(--chart-crosshair,rgba(15,23,42,.42))}
:where(.xy [data-xy-slot="tooltip_cursor"]){background:var(--chart-crosshair,rgba(15,23,42,.42))}
:where(.xy [data-xy-slot="axis_band"]){cursor:var(--xy-axis-band-cursor)}
:where(.xy [data-xy-slot="axis_line"],.xy [data-xy-slot="tick_mark"]){width:var(--xy-axis-rule-width);height:var(--xy-axis-rule-height);background:var(--xy-axis-rule-paint)}
:where(.xy [data-xy-slot="tick_label"]){color:var(--chart-text,inherit)}
Expand Down
62 changes: 61 additions & 1 deletion js/src/30_ticks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,67 @@ export function fmtNumberSpec(v, format) {
return `${prefix}${text}${percent ? "%" : ""}${suffix}`;
}

function fmtTimeSpec(ms, format) {
// Whether a `format=` string is a strftime pattern rather than a numeric spec.
// `%` alone is the number grammar's percent suffix (`".0%"`), so the test is a
// `%` followed by one of the tokens `fmtTimeSpec` actually replaces — that way
// `format=".0%"` on a time-kinded value still means "as a number".
export function isTimeFormat(format) {
return typeof format === "string" && /%[YmdHMSbB]/.test(format);
}

// The strftime pattern a time value reads best in when nothing was authored.
// Two independent questions, which one ladder of whole patterns could not keep
// apart:
//
// How much CONTEXT — whether the year, the date, or neither belongs on the
// value — is the span's to answer. A month-wide window wants the year, a
// three-minute one does not.
//
// How much PRECISION is the span's answer FLOORED by the data's own spacing. A
// tooltip names ONE point, and a pattern that prints the same string for a
// point and the one beside it names neither; the span cannot know, because it
// says nothing about how close the samples are. Ten-second samples in a
// three-minute window share a minute, and hourly samples over a month share a
// date.
//
// Composing the two is what keeps them from trading off: refining a ladder of
// patterns instead would have bought the precision by dropping the date, so
// per-second samples in a month-wide window read `10:00:10` and never said
// which day.
const SPAN_TIERS = [
{ min: 28 * MS.d, date: "%b %d, %Y", precision: 0 },
{ min: MS.m, date: "%b %d", precision: 1 },
{ min: MS.s, date: null, precision: 2 },
];
// Indexed by precision: the clock a value needs to separate it from the next.
// Past the end is finer than any strftime token, so the caller keeps the ISO
// stamp, which is the only form carrying milliseconds.
const TIME_PARTS = [null, "%H:%M", "%H:%M:%S"];

// The coarsest clock that still tells apart two samples `gap` ms apart. The
// comparison is >=, so a gap that equals a unit is separated by it: points a
// day apart differ in date, and a month-wide window of them is not given a
// clock it has no use for.
function gapPrecision(gap) {
if (gap >= MS.d) return 0;
if (gap >= MS.m) return 1;
if (gap >= MS.s) return 2;
return TIME_PARTS.length;
}

export function defaultTimeFormat(span, resolution) {
if (!Number.isFinite(span) || span <= 0) return null;
const tier = SPAN_TIERS.find((t) => span >= t.min);
if (!tier) return null;
const precision = Math.max(
tier.precision,
Number.isFinite(resolution) && resolution > 0 ? gapPrecision(resolution) : 0,
);
if (precision >= TIME_PARTS.length) return null;
return [tier.date, TIME_PARTS[precision]].filter(Boolean).join(", ") || null;
}

export function fmtTimeSpec(ms, format) {
if (typeof format !== "string") return null;
const d = new Date(ms);
if (!Number.isFinite(d.getTime())) return null;
Expand Down
Loading
Loading