Skip to content

Fix behavior of customdata when using typed arrays#7608

Merged
emilykl merged 4 commits into
masterfrom
fix-typed-array-hoverdata
Oct 27, 2025
Merged

Fix behavior of customdata when using typed arrays#7608
emilykl merged 4 commits into
masterfrom
fix-typed-array-hoverdata

Conversation

@emilykl

@emilykl emilykl commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

Closes #7607

Some logic in a helper function was not updated to handle typed arrays, causing a regression in customdata behavior in Plotly.js and Plotly.py.

As described in the linked issue, this bug made it impossible to reference a 2D customdata array passed from Plotly.py in the heatmap hover template, when previously that was possible.

On the Plotly.js level, the 2D customdata array passed from Plotly.py was translated into a JavaScript Array containing two JavaScript typed arrays, like this: [new Float64Array([101,103]), new Float64Array([102,104])]

That specific data structure was not handled properly by the getPointData() function which retrieves values to insert into the hovertemplate.

Note: most of the diff in this PR is due to the Biome formatter. Check the second commit for the meaningful change.

How to test

  1. Create a plot using the following code:
var data = [{
            z: [[1,3],[2,4]],
            customdata: [new Float64Array([101,103]), new Float64Array([102,104])], 
            hovertemplate: '<b>z: %{z:.3f}</b><br>custom: %{customdata:.3f}',
            type: 'heatmap',
        }];
        var layout = {
            title: {text: 'Heatmap customdata'},
        };
        Plotly.newPlot('plot', data, layout);
  1. On this branch, it works as expected: customdata is shown in hover tooltip
Screenshot 2025-10-27 at 10 21 53 AM
  1. On master (and Plotly.js >=3.0), it's broken: customdata is not found by hover tooltip and template is shown instead
Screenshot 2025-10-27 at 10 23 26 AM

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. Could you please add a test for getPointData with a typed array? Also, could you please add a draftlog?

@emilykl

emilykl commented Oct 27, 2025

Copy link
Copy Markdown
Contributor Author

@camdecoster Done -- draftlog and tests added. I've added 2 tests; the first passes already on master, but the second fails on master and passes on this branch.

@emilykl emilykl merged commit 3767140 into master Oct 27, 2025
6 checks passed
@emilykl emilykl deleted the fix-typed-array-hoverdata branch October 27, 2025 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants