Repository navigation
Conversation
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.
Author
|
Pushed a follow-up commit: with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #8205.
xperiod/yperiodon a category or linear axis madePlotly.newPlotthrowTypeError: 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.alignPeriodreturns periodstarts/endsonly on date axes, but the calc steps read them whenever*periodalignmentwas 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 whenalignPeriodreturned 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 checkorig_pfor each point.fx/hover.jsorderRangePoints: rank a trace with a period behind ordinary points only on date axes, so addingxperiodon a linear axis no longer changes which point wins hover.Alternatives considered: making
alignPeriodreturn placeholder bounds on non-date axes (changes a shared helper, and scatter hover would only match at the exact pixel), or dropping*periodalignmentin 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:
After, this branch:
Tests
bar_test.js,waterfall_test.js(calc): category and linear axes,xperiodand horizontalyperiod.scatter_test.js(trace-levelhoverPoints): category and linear axes,xperiodandyperiod, with the point found by hover.hover_test.js(publicFx.hover, unified hover, fixed plot geometry): the closest point wins with and withoutxperiodon a linear axis.The calc and scatter tests fail on
mainwith the reported TypeError; the unified hover test fails without theorderRangePointschange.Draftlog
draftlogs/XXXX_fix.mdis a placeholder; it will be renamed to this PR's number.Follow-ups (not in this PR)
funnel/calc.jshas the samehasPeriod = !!trace.*periodalignmentpattern and probably fails the same way.scattergl/hover.jsreadstrace._xStarts[k]/_yStarts[k]whenever*periodalignmentis set, which is probably undefined on non-date axes.🐦