Skip to content

fix: guard collection-mark matching in filterGraphicsByDatum - #4693

Merged
xile611 merged 3 commits into
VisActor:developfrom
dyk1454683243-sudo:cursor/fix-filtergraphicsbydatum-collection-4678-12a3
Sep 20, 2026
Merged

xile611 merged 3 commits into
VisActor:developfrom
dyk1454683243-sudo:cursor/fix-filtergraphicsbydatum-collection-4678-12a3

Conversation

@dyk1454683243-sudo

@dyk1454683243-sudo dyk1454683243-sudo commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4678

🤔 This is a ...

  • Bug fix
  • Test Case

🔗 Related issue link

Fixes #4678

💡 Background and solution

setHovered with datums from multiple series (or any hovered list longer than a collection mark's internal datum array) crashed in filterGraphicsByDatum.

In the isCollectionMark branch, the match predicate did:

elDatum && datum.every((d, index) => keys.every(k => d[k] == elDatum[index][k]))

When elDatum[index] was missing, reading elDatum[index][k] threw (Cannot read properties of undefined).

This change short-circuits when elDatum[index] is absent, so unmatched datums are ignored and no exception is thrown. Non-collection matching is unchanged, so point graphics that do match still highlight.

Repro from the issue gist: a line chart plus setHovered([...data, extraUnmatchedDatum]) no longer throws.

📝 Changelog

Language Changelog
🇺🇸 English fix: ignore unmatched datums when matching collection marks in filterGraphicsByDatum, so setHovered with a longer multi-series datum list does not throw
🇨🇳 Chinese 修复:filterGraphicsByDatum 在集合图元匹配时忽略越界/未匹配 datum,避免多系列 setHovered 抛错

☑️ Self-Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

Verification

  • eslint --quiet on packages/vchart/src/chart/base/base-chart.ts and the new test: clean
  • jest __tests__/unit/chart/filter-graphics-by-datum.test.ts --runner=jest-runner --testEnvironment=node: 3 passed
  • Package jest-electron runner hung in this Linux environment (CI uses macos-latest); the node runner is enough for this non-render regression.

Manual repro (if needed)

  1. Render a line chart (collection mark) as in https://gist.github.com/CrazyBucket/0b6018dd186c1921ba85165c1bbf177b
  2. Call vchart.setHovered([...data, { time: '20:00', value: 12 }])
  3. Expected: no throw; unmatched extra datum is ignored
  4. For a multi-series BP chart, setHovered([systolicDatum, diastolicDatum]) should highlight matched point graphics and skip collection marks whose internal datum array is shorter

Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
@xile611 xile611 added this to the 2.1.8 milestone Sep 20, 2026
@xile611
xile611 merged commit 9c4e225 into VisActor:develop Sep 20, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Crash in filterGraphicsByDatum when setHovered receives datums from multiple series (out-of-bounds access on collection marks)

3 participants