Skip to content

Fixes issue with trying to access tick.label when using Sankey chart#177

Merged
K009 merged 2 commits intoblacklabel:masterfrom
FadhlurZ:master
Mar 3, 2026
Merged

Fixes issue with trying to access tick.label when using Sankey chart#177
K009 merged 2 commits intoblacklabel:masterfrom
FadhlurZ:master

Conversation

@FadhlurZ
Copy link
Contributor

@FadhlurZ FadhlurZ commented Jan 29, 2026

Fix: Add null checks for Sankey chart compatibility

Problem:
The plugin crashes when rendering Sankey charts with the following error:
TypeError: Cannot read properties of undefined (reading 'label')

Root Cause:
In the bindChartEvents function, the code assumes all chart axes have tickPositions and that axis.ticks[pos] will always return a valid tick object. However, Sankey charts don't use traditional axes with ticks, causing:

  • axis.tickPositions to be undefined
  • axis.ticks[pos] to return undefined for certain positions

Solution:
Added null/undefined checks before accessing tick properties:

// Before
if (axis.ticks) {
    const tickPositions = axis.tickPositions;
    tickPositions.forEach(pos => {
        const tick = axis.ticks[pos];
        if (tick.label?.element) { // ❌ Crashes if tick is undefined

// After
if (axis.ticks && axis.tickPositions) {
    const tickPositions = axis.tickPositions;
    tickPositions.forEach(pos => {
        const tick = axis.ticks[pos];
        if (tick && tick.label?.element) { // ✅ Safe

Demo where issue is visible in browser console:
https://jsfiddle.net/241fkqr6/

Impact:
This fix ensures the plugin works correctly with Sankey charts and other chart types that don't have traditional axes, while maintaining backward compatibility with all existing chart types.

@PaultjeScholes
Copy link

@FadhlurZ Can we add a label Type: Bug and perhaps add reviewers to get this merged, we are running into the same issue

@FadhlurZ
Copy link
Contributor Author

FadhlurZ commented Mar 3, 2026

@PaultjeScholes Unfortunately it looks like I am not able to add reviewers and a label to this PR. Could you @K009 @mfilipiec maybe take a look at this PR? I think it has quite a big impact for some users of this package.

@K009 K009 self-requested a review March 3, 2026 09:26
@K009
Copy link
Collaborator

K009 commented Mar 3, 2026

Hi, thanks a lot for your contribution and for catching this bug. The fix looks solid, happy to merge!

@K009 K009 merged commit 66bd60b into blacklabel:master Mar 3, 2026
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.

3 participants