Skip to content

fix(fill): keep stacked fills when interpolate() matches multiple segments - #12326

Open
ump45nose wants to merge 1 commit into
chartjs:masterfrom
ump45nose:fix/stack-fill-tiny-x-offset
Open

ump45nose wants to merge 1 commit into
chartjs:masterfrom
ump45nose:fix/stack-fill-tiny-x-offset

Conversation

@ump45nose

Copy link
Copy Markdown

Fixes #12325.

Description

When fill: 'stack' builds the stack target, findPoint passed the result of LineElement.interpolate() straight to point[property]. interpolate() returns one point per matching segment, and when the source point's x sits within rounding error of a shared segment boundary it matches two segments at once and returns an array. In that case point[property] is undefined, the raw array is pushed into the stack target's points, and the dataset's fill disappears completely (reproducible deterministically by nudging a point's x by 1e-9, and visible as a flicker at the end of animated chart.update() calls, as in the jsfiddle in the issue).

The points of the matching segments are equal within rounding error of the source point, so taking the first one is safe. Analysis and the proposed approach are from @reporter in #12325 (the issue includes a deterministic repro); this PR implements the fix and adds a regression test.

Changes

  • src/plugins/plugin.filler/filler.target.stack.js: in findPoint, take the first point when interpolate() returns an array.
  • test/specs/plugin.filler.tests.js: regression test rendering the deterministic repro from the issue (a stacked area chart where a point of the upper dataset is nudged by 1e-9) and asserting the canvas is unchanged compared to the un-nudged render — without the fix, the upper band's fill vanishes and the canvas differs.

Testing

  • New regression test passes with the fix and fails without it (verified by reverting the source change locally).
  • pnpm test-ci-karma --grep=filler: all filler specs pass except the pre-existing drawTimeFillFalse/beforeDatasetDraw fixture pixel failure (0.46% difference, also fails on unmodified master with Chrome 154 — environmental, unrelated to this change).
  • eslint clean on the changed files.

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.

fill: 'stack': a dataset's whole fill disappears when its x differs from the line below by ≤ 1e-6 px (happens in animations)

1 participant