fix(heatmap): add eventData handler for proper click event data - #7920
fix(heatmap): add eventData handler for proper click event data#7920ubertidavide wants to merge 1 commit into
Conversation
|
Thanks for the PR! Our team will review and follow up. |
bfc7e8a to
711d73b
Compare
|
I've force-pushed an update to
|
711d73b to
e6d6823
Compare
|
Added |
|
Hi @ubertidavide, thanks for the contribution! The original issue doesn't contain steps for reproducing the bug, which makes it hard to verify a fix. Can you provide a JavaScript code snippet which demonstrates the bug? |
|
Hi @emilykl, Here is a minimal reproduction showing the issue and how registering BackgroundWhen receiving click/select events on a heatmap, event points can be constructed from raw point objects where Because
Other trace types (like Minimal Reproducible Exampleconst gd = document.createElement('div');
document.body.appendChild(gd);
Plotly.newPlot(gd, [{
type: 'heatmap',
z: [[10, 20], [30, 40]],
x: ['ColA', 'ColB'],
y: ['RowA', 'RowB']
}]);
gd.on('plotly_click', function(data) {
const pt = data.points[0];
console.log('pointNumber:', pt.pointNumber);
console.log('pointIndex:', pt.pointIndex);
console.log('z:', pt.z);
});Behavior SummaryWhen event data is extracted from point targets containing
Implementation NoteAdding |
Description
When interacting with heatmaps, the standard
plotly_clickevent previously lacked properly formatted 2D matrix indices and explicitzvalues. This made it difficult for downstream wrappers (such as Streamlit or Marimo) to identify the exact clicked cell natively.Architecture Note:
plotly_clickvsplotly_heatmapclickWhile introducing a trace-specific event like
plotly_heatmapclick(similar toplotly_treemapclickorplotly_sunburstclick) was originally discussed in #7685, doing so for heatmaps is an anti-pattern. Heatmaps are Cartesian trace types that reside on standard 2D Cartesian subplots. Introducing trace-specific click events on Cartesian subplots breaks consistency across Cartesian traces. The correct architectural approach is to rely on the standardplotly_clickevent and delegate trace-specific payload formatting to a dedicatedeventDatahandler.Summary of Changes
This PR introduces the missing
eventDatahandler for the heatmap trace:pointNumberandpointIndexare properly exposed as a 2D array[row, col].zvalues are explicitly attached to the event payload.This PR completes and supersedes #7686 (which was stalled). Unlike #7686, this implementation cleanly exposes the 2D
pointNumber: [row, col]matrix indices andzvalues viaeventDatawithout modifyinghover.js(avoiding category axis regressions), and includes complete Jasmine unit tests.Closes #7685.
Testing
test/jasmine/tests/heatmap_test.jsto verify that standardplotly_clickevents emit 2DpointNumberandzvalues.npm run test-jasmine -- test/jasmine/tests/heatmap_test.js) with 51/51 specs passing successfully.