Skip to content

Ignore xperiod/yperiod on non-date axes in bar, waterfall and scatter traces - #8206

Open
akysil wants to merge 3 commits into
plotly:mainfrom
akysil:fix/8205-bug-xperiod-yperiod-crashes-bar-scatter-
Open

akysil wants to merge 3 commits into
plotly:mainfrom
akysil:fix/8205-bug-xperiod-yperiod-crashes-bar-scatter-

Conversation

@akysil

@akysil akysil commented Nov 26, 2026

Copy link
Copy Markdown

Fixes #8205.

xperiod/yperiod on a category or linear axis made Plotly.newPlot throw TypeError: Cannot read properties of undefined (reading '0') for bar, waterfall and scatter traces (vertical and horizontal). These attributes are now ignored on non-date axes, as their description says.

alignPeriod returns period starts/ends only on date axes, but the calc steps read them whenever *periodalignment was set, and that attribute is set whenever a period is given (the axis type isn't known yet when trace defaults run).

Approach

  • bar/calc.js, waterfall/calc.js, scatter/calc.js: use the period fields only when alignPeriod returned them (!!pObj.ends).
  • scatter/hover.js: use the period hover distance only on date axes. Otherwise hover would look for period bounds that no longer exist and never find a point. Bar and waterfall hover already check orig_p for each point.
  • fx/hover.js orderRangePoints: rank a trace with a period behind ordinary points only on date axes, so adding xperiod on a linear axis no longer changes which point wins hover.

Alternatives considered: making alignPeriod return placeholder bounds on non-date axes (changes a shared helper, and scatter hover would only match at the exact pixel), or dropping *periodalignment in the defaults (not possible: the axis type is decided after the trace defaults).

Screenshots

The issue's three examples, one Plotly.newPlot call each (a red line is the error newPlot threw): the period attribute on a category or linear axis either throws the TypeError and draws no data, or is ignored and the three bars or points render (screenshots of the running app):

Before, upstream at cf771fa:

The issue's three examples, one Plotly.newPlot call each (a red line is the error newPlot threw): the period attribute on a category or linear axis either throws the TypeError and draws no data, or is ignored and the three bars or points render, before

After, this branch:

The issue's three examples, one Plotly.newPlot call each (a red line is the error newPlot threw): the period attribute on a category or linear axis either throws the TypeError and draws no data, or is ignored and the three bars or points render

Tests

  • bar_test.js, waterfall_test.js (calc): category and linear axes, xperiod and horizontal yperiod.
  • scatter_test.js (trace-level hoverPoints): category and linear axes, xperiod and yperiod, with the point found by hover.
  • hover_test.js (public Fx.hover, unified hover, fixed plot geometry): the closest point wins with and without xperiod on a linear axis.

The calc and scatter tests fail on main with the reported TypeError; the unified hover test fails without the orderRangePoints change.

Draftlog

draftlogs/XXXX_fix.md is a placeholder; it will be renamed to this PR's number.

Follow-ups (not in this PR)

  • funnel/calc.js has the same hasPeriod = !!trace.*periodalignment pattern and probably fails the same way.
  • scattergl/hover.js reads trace._xStarts[k] / _yStarts[k] whenever *periodalignment is set, which is probably undefined on non-date axes.

🐦

Calc wrote period start/end values whenever the period alignment flag
was set, but alignPeriod returns them only on date axes, so a period on
a category or linear axis threw a TypeError. Only use the period fields
when alignPeriod returned them, and treat scatter points with a period
like ordinary points in hover when the axis is not a date axis.
@akysil

akysil commented Nov 27, 2026

Copy link
Copy Markdown
Author

Pushed a follow-up commit: with xperiod/yperiod on a non-date axis, compare and unified hover found no bar for bar and waterfall traces. hoverOnBars still used the period hover box, but calc no longer writes the period bounds on those axes, so the box was NaN. bar/hover.js now uses the period box only when calc wrote the bounds, and bar_test.js / waterfall_test.js cover hover on category and linear axes. The draftlog is renamed to 8206_fix.md.

Bar trace with xperiod 2 on a linear axis, hovering the middle bar in x unified mode: the hover label shows the bar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: xperiod/yperiod crashes bar, scatter and waterfall on non-date axes

1 participant