Repository navigation
fix(data): a Date x on a non-datetime axis, and an invalid Date - #5279
Conversation
Two problems the review of apexcharts#5277 named and left for their own change. A Date x on a numeric or category axis went through parseFloat(), which reads the Date through toString(), so every point became NaN even though the surrounding lines had just set dataFormatXNumeric and isXNumeric. A Date's numeric value is its epoch, the same one the datetime branch directly above already reads. isValidDate(new Date('garbage')) threw instead of answering false: parseDate()'s salvage pass calls .replace() on its argument, and an invalid Date has no such method. A single bad x took the whole render down with a TypeError. Only a string has an alternate spelling to try, so anything else is simply not a date. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Verified both fixes against One wording fix for the description, not the code: an invalid Worth mentioning too, since it's the one thing here with no test on it: the same guard un-breaks Thanks, merging. |
|
You're right on the wording, and the measurement is a bit sharper than "looks like a plain numeric x". Failing The Two refinements to the axis part, from probing each type rather than reasoning about it: The empty axis is not category-only: Your With the guard in place: Assertions are up as #5281, tests only, no Not verified: all of this is jsdom, I did not open a real browser, and I did not run the e2e or interaction suites. |
Four new chart types.
streamgraph stacked areas on a shifting baseline that keeps the bands
readable; band-sized labels, legend and hover fading included
waterfall running totals accumulated from deltas, with subtotals,
totals and connectors
dumbbell two or more measures per category on a shared axis, without
zipping the pairs by hand
raincloud half violin, box and raw observations in one look (premium,
loaded via features/raincloud)
streamgraph, waterfall and dumbbell ship in the default bundle and as their
own entry points; raincloud is an explicit import from either channel:
import 'apexcharts/raincloud'
<script src=".../dist/features/raincloud.js"></script>
chart.print lays the chart out for the printed sheet instead of letting the
browser cut it (#3352).
Fixes: a container resize arriving mid-animation is kept, and each resize
draws once (#1584); autoScaleYaxis skips series with nothing in the window
and scales stacked totals (#1260); bar slots size from the axis, not from
the smallest gap inside one series (#4885); pie and radial charts centre in
the height they have, not in the square they fit (#4875); Date x values on
a non-datetime axis and invalid Dates are handled (#5279); the tooltip
resolves the hovered index past a series' leading nulls.
Verified against the built dist: unit 3307, interaction 568, e2e 314/314
with zero snapshot diffs, all 57 entry points resolve, and each new type
renders painted ink from the shipped bundles over file://.
The guard in #5279 was written for an invalid Date, but the line it replaced threw on anything without .replace(). null and undefined go through the same path, and a gap in a data set is spelt null far more often than a Date is built from garbage: without the guard, [{x: 1}, {x: null}, {x: 3}] renders nothing at all. Three assertions, all red when the guard is reverted: isValidDate answers false instead of throwing, the points either side of the gap keep their x, and the render survives an undefined x. Co-Authored-By: Claude Opus 5 <[email protected]>
Picking up the two adjacent problems you named at the end of your review of #5277 and deliberately did not fold in:
Both still reproduce on
main(b0dc6af).1. A
Datex on a non-datetime axis becomesNaNData.jssetsdataFormatXNumericandisXNumericand then reads the value withparseFloat(x).parseFloatstringifies its argument first, andDate.prototype.toString()starts with a weekday name:Those two lines have already decided the x is numeric, and a
Date's numeric value is its epoch — the same value thedatetimebranch three lines above reads. So this is the same shape as the fix in #5277, applied to the branch that was left out.2. An invalid
Datethrows instead of answering "not a date"isValidDatehands its argument straight toparseDate. For an invalidDate,Date.parsereturnsNaN, so it falls into the salvage pass, which calls.replace()on it:Data.js:309callsisValidDate(x)for every x, so a single bad point takes the whole render down with aTypeError. Only a string has an alternate spelling worth trying, so anything else now returnsNaNandisValidDatecan answerfalse.Correction (per @junedchhipa's review): an earlier draft of this paragraph said the bad x then falls through to the category path. It does not. Failing
isValidDatemeans it misses theisXString || isXDatebranch entirely and lands in the finalelse, which pushesxunconverted and setsisXNumeric/dataFormatXNumeric, sofallbackToCategoryis never set andcategoryLabelsstays empty. Measured on a category axis:raw pushed = [object Date],categoryLabels = [], 0 x axis label texts against 2 for the equivalent numeric x. Still much better than the blank chart it replaces, but it is the numeric path, not the category one.Evidence
New spec
tests/unit/date-x-edge-cases.spec.js, 5 tests. Revertingsrc/and keeping the spec, onmain:The test that passes before the fix is the control:
isValidDatestill says yes tonew Date(...),'2010-01-01T00:00:00.000Z'and'01/01/2017', and no to'not a date'. It stays green throughout, so the guard does not widen what counts as a date.Each fix was then reverted on its own, to check that neither test is vacuous:
DateTime.jsguard onlyData.jsDatebranch onlyFull unit suite: 134 files, 3181 tests, 0 failures.
npm run lintis clean.npm run typecheckreports 23 errors with and without this change — all inDrilldown.js, all pre-existing.Prettier: I left the pre-existing deviations in both files alone, the way you did on #5277.
prettier --writeon these two files touches onlyDateTime.js:432,DateTime.js:685,Data.js:898andData.js:1775; none of them are lines this PR adds.Not included
Nothing else moved.
getTimeStampandparseDateWithTimezonekeep the string path they always had, and a validDatenever reaches the new guard becauseDate.parsesucceeds before it.