Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
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
66 changes: 66 additions & 0 deletions docs/components/tooltips.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,64 @@ def tooltip_title_demo():
return reflex_xy.chart(tooltip_title_chart, height="320px")
~~~

## Show Every Series at One X

Line and area charts use unified hover by default (`hover_mode="x unified"`,
Plotly's `hovermode` spelling): the cursor only has to be somewhere over the
plot. It snaps to the nearest x, a vertical spike line marks it, and one
tooltip lists each series with a point within 20 px of that x, under the x
Comment thread
FarhanAliRaza marked this conversation as resolved.
Resolved
value as its heading. Other charts report the mark under the cursor (`"closest"`); pass
`hover_mode="x unified"` to opt them in, or `hover_mode="closest"` to opt a
line or area chart out. A line or area chart whose tooltip sets `title=`,
`fields=`, or `render=` also keeps `"closest"`.
Comment thread
FarhanAliRaza marked this conversation as resolved.
Resolved
Plotly's per-series `"x"`/`"y"` modes are not available; passing either raises
an error naming `"x unified"`/`"y unified"`.

~~~python demo exec
import reflex_xy
import xy

unified_days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]

unified_hover_chart = xy.line_chart(
xy.line(unified_days, [5, 5, 5, 11, 0, 0, 0], name="Booked"),
xy.line(unified_days, [0, 2, 5, 5, 0, 0, 0], name="Held"),
xy.line(unified_days, [0, 1, 4, 3, 0, 0, 0], name="Qualified held"),
xy.legend(),
title="Weekly momentum",
)


def unified_hover_demo():
return reflex_xy.chart(unified_hover_chart, height="320px")
~~~

- `"x unified"` snaps along x; `"y unified"` snaps along y and draws a
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
horizontal spike. `"closest"` reports only the mark under the cursor.
- Line, scatter, area, and bar/column series take part. A series whose nearest
point is more than 20 px from the snapped position along the hover dimension
(x for `"x unified"`, y for `"y unified"`) is left out rather than reported
at the wrong coordinate. Charts with no such series, and polar charts, keep
closest-point hover.
- Each row shows a color chip (`tooltip_swatch` slot), the series name
(`tooltip_label`), and its value (`tooltip_value`). `tooltip(format=...)`
formats the heading and values. A series' name labels its row; for an
unnamed series, `labels=` supplies the label from the other axis
(`labels["y"]` under `"x unified"`, `labels["x"]` under `"y unified"`). Both
accept the channel name or the source column, e.g.
`xy.tooltip(labels={"revenue": "Revenue"}, format={"revenue": ".1f"})`. A
source-column key applies only to the series drawn from that column.
`title=` and `fields=` templates and a custom `render=` describe one hovered
row and are not used by the unified readout, so a line or area chart with
any of them keeps `"closest"` unless you set `hover_mode` yourself.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
- The spike line is the crosshair line, so the `crosshair_x`/`crosshair_y`
slots and the `--chart-crosshair` token style it.
- The `xy:hover` event lists every reported series in `points`. Python
`on_hover` still fires once per hover, with the row that set the snapped
position (the one nearest the cursor along the hover dimension).

The same setting is available as `xy.interaction_config(hover_mode=...)`.

## Exact and Resident Readout

Standalone HTML composes tooltips from the values resident in its payload.
Expand Down Expand Up @@ -214,6 +272,14 @@ heatmap value) can be used as tooltip fields.
Use braced field names in `title=`, e.g. `xy.tooltip(title="Month {month}")` —
each placeholder is replaced with the value from the hovered row.

### How do I show all series values at the hovered x, like Plotly's unified hover?

Line and area charts already do this by default. For other charts, pass
`hover_mode="x unified"`, e.g. `xy.scatter_chart(..., hover_mode="x unified")`.
The cursor snaps to the nearest x anywhere over the plot and one tooltip lists
each series whose nearest point is within 20 px of that x. Pass `hover_mode="closest"` to turn it
off on a line or area chart.

### How do I disable tooltips on a chart?

Add `xy.tooltip(show=False)` to the chart. When several tooltip components are
Expand Down
8 changes: 8 additions & 0 deletions docs/core-concepts/interactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def browser_behavior_demo():
return reflex_xy.chart(chart, height="360px")
~~~

`hover_mode` chooses what hover reports. `"closest"`, the default for most
charts, reads the mark under the cursor. `"x unified"`, the default for line
and area charts (unless their tooltip sets `title=`, `fields=`, or `render=`),
snaps to the nearest x anywhere over the plot and lists the series with a
point within 20 px of it in one tooltip, with a spike line at that x; `"y unified"` does the same along y. Polar charts keep
`"closest"`. See
[Show Every Series at One X](/docs/xy/components/tooltips/#show-every-series-at-one-x).

Standalone HTML keeps these local browser behaviors. It cannot invoke Python
because no kernel or server is attached.

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_swatch` | full | none | none |
| `modebar` | full | none | none |
| `modebar_drag_handle` | full | none | none |
| `modebar_control_group` | full | none | none |
Expand Down
8 changes: 5 additions & 3 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_swatch` | Series color chip on a unified-hover row (`--xy-tooltip-swatch-paint`) |
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
| `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 @@ -232,7 +233,8 @@ portable file.
## One tooltip, three styling approaches

All three examples target the tooltip container. The same mechanisms also
target `tooltip_title`, `tooltip_row`, `tooltip_label`, and `tooltip_value`.
target `tooltip_title`, `tooltip_row`, `tooltip_label`, `tooltip_value`, and
the unified-hover `tooltip_swatch`.
Choose based on where the style originates; do not combine them unless you
intentionally want normal CSS cascade precedence.

Expand Down Expand Up @@ -358,8 +360,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 docs/styling/component-variations.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ styles it.
| Surface | Configure content or behavior | Style it |
| --- | --- | --- |
| Built-in legend | `legend(loc=..., ncols=..., title=...)` | `legend(class_name=..., style=...)`; `legend`, `legend_title`, `legend_item`, `legend_swatch`, and `legend_label` slots |
| Built-in tooltip | `tooltip(fields=..., labels=..., title=..., format=...)` | `tooltip(class_name=..., style=...)`; `tooltip`, `tooltip_title`, `tooltip_row`, `tooltip_label`, and `tooltip_value` slots |
| Built-in tooltip | `tooltip(fields=..., labels=..., title=..., format=...)` | `tooltip(class_name=..., style=...)`; `tooltip`, `tooltip_title`, `tooltip_row`, `tooltip_label`, `tooltip_value`, and `tooltip_swatch` slots |
| Colorbar chrome | `colorbar(title=..., orientation=..., ticks=...)` on a supported continuous mark | `colorbar`, `colorbar_bar`, `colorbar_tick`, `colorbar_title`, `colorbar_extension`, `colorbar_line`, and `colorbar_minor_tick` slots |
| X and Y axes | `x_axis(...)`, `y_axis(...)`, including named secondary axes | Validated axis `style`; `axis_line`, `tick_mark`, `tick_label`, `axis_title`, and `axis_band` DOM slots |
| Reference lines | `vline(x)` and `hline(y)` | Geometry through `color`, `width`, and `opacity`; label through `class_name` and `style` |
Expand Down
4 changes: 2 additions & 2 deletions docs/styling/customize.md
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,8 @@ beside it. Host-owned UI is not included in standalone XY exports.
Tooltip fields must already be resident in a rendered data channel. Use named
data columns for stable lookup, map them to readable display text with
`labels=`, and format them with `format=`. Style the built-in container
directly or target `tooltip_title`, `tooltip_row`, `tooltip_label`, and
`tooltip_value` independently.
directly or target `tooltip_title`, `tooltip_row`, `tooltip_label`,
`tooltip_value`, and the unified-hover `tooltip_swatch` independently.

~~~python demo exec toggle preview-code id=customize-tooltip-demo
data = {
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 @@ -125,6 +125,7 @@ export const XY_CHROME_CSS = `
:where(.xy [data-xy-slot="tooltip"]){max-width:calc(100% - 8px);max-height:calc(100% - 8px);box-sizing:border-box;white-space:normal;overflow-wrap:anywhere;overflow:auto;background:var(--chart-tooltip-bg,rgba(20,24,33,.92));color:var(--chart-tooltip-text,#fff);padding:5px 8px;border-radius:4px;font-size:11px;line-height:1.35;box-shadow:0 2px 8px rgba(0,0,0,.3)}
:where(.xy [data-xy-slot="tooltip"][data-xy-custom-tooltip]){background:transparent;border:none;padding:0;box-shadow:none}
:where(.xy [data-xy-slot="tooltip_label"])::after{content:": "}
:where(.xy [data-xy-slot="tooltip_swatch"]){display:inline-block;width:8px;height:8px;border-radius:50%;margin-right:6px;vertical-align:0;background:var(--xy-tooltip-swatch-paint,currentColor)}
:where(.xy [data-xy-slot="legend"]){left:var(--xy-legend-left,auto);right:var(--xy-legend-right,auto);top:var(--xy-legend-top,auto);bottom:var(--xy-legend-bottom,auto);transform:var(--xy-legend-transform,none);max-width:var(--xy-legend-max-width);max-height:var(--xy-legend-max-height);gap:2px;font-size:11px;background:var(--chart-legend-bg,rgba(128,128,128,.08));border-radius:4px;padding:4px 8px;color:var(--chart-text,inherit)}
:where(.xy [data-xy-slot="legend_title"]){font-weight:400;text-align:center}
:where(.xy [data-xy-slot="legend_swatch"]){display:inline-block;width:var(--xy-legend-swatch-width,12px);height:var(--xy-legend-swatch-height,10px);vertical-align:-1px;background:var(--xy-legend-swatch-paint,transparent);border-radius:2px;margin-right:var(--xy-legend-swatch-margin-right,5px);fill:var(--xy-legend-swatch-fill);stroke:var(--xy-legend-swatch-stroke);stroke-width:var(--xy-legend-swatch-stroke-width);stroke-dasharray:var(--xy-legend-swatch-dasharray)}
Expand Down
20 changes: 19 additions & 1 deletion js/src/50_chartview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4959,6 +4959,7 @@ export class ChartView {
// Build transactionally. A lost context or allocation failure midway
// through a trace list must not strand the buffers/programs already made
// for its prefix — shared-host recovery may retry this client in place.
this._dropHoverForRebuild?.();
this.gpuTraces = [];
try {
for (const trace of this.spec.traces) {
Expand Down Expand Up @@ -7280,7 +7281,12 @@ export class ChartView {
}

_drawHoverState() {
const hit = this._hoverTarget;
// A unified readout marks every reported point, not only the winner.
const hits = this._unified ? this._unified.hits : [this._hoverTarget];
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
for (const hit of hits) this._drawHoverTarget(hit);
}

_drawHoverTarget(hit) {
if (!hit || !hit.g) return;
const g = hit.g;
if (g.trace.kind !== "scatter" || g.tier === "density" || g._legendHidden) return;
Expand Down Expand Up @@ -9659,6 +9665,18 @@ export class ChartView {
const rect = this.canvas.getBoundingClientRect();
const cssX = e.clientX - rect.left;
const cssY = e.clientY - rect.top;
if (this._unifiedHover(e, cssX, cssY)) return;
// Nothing answered a unified readout here (or the mode is closest): drop
// any unified state so the closest-point path below starts clean rather
// than treating the old winner as "still hovered".
if (this._unified) {
Comment thread
FarhanAliRaza marked this conversation as resolved.
Resolved
this._hideTooltip();
this._hoverId = -1;
Comment thread
FarhanAliRaza marked this conversation as resolved.
Resolved
this._hoverTarget = null;
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
// Repaint so the dropped readout's point highlights go with it; the
// `!hit` branch below no longer sees a hover to clear.
this._drawKeepPick();
}
const hit = this._pickAt(cssX, cssY) || this._hoverAt(cssX, cssY);
if (!hit) {
const hadHover = this._hoverId !== -1;
Expand Down
Loading
Loading