Skip to content

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

Closed
akysil wants to merge 1 commit into
factory-base/8205from
factory-final/8205
Closed

akysil wants to merge 1 commit into
factory-base/8205from
factory-final/8205

Conversation

@akysil

@akysil akysil commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Fixes.

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 closed this Nov 26, 2026
@akysil
akysil deleted the factory-final/8205 branch November 26, 2026 20:49
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.

1 participant