redash
redash copied to clipboard
Closes #3497: Show correct values on hover of scatterplot.
What type of PR is this? (check all applicable)
- [ ] Refactor
- [ ] Feature
- [X] Bug Fix
Description
Scatterplots should now "show closest data on hover" by default and also use the correct values for the hover text. This fixes the issues described in the ticket below.
Related Tickets & Documents
https://github.com/getredash/redash/issues/3497
Mobile & Desktop Screenshots/Recordings (if there are UI changes)
@emtwo Thanks for reporting this bug and for proposed solution. But in fact the only correct way to deal with this but is to properly aggregate the data, either with query (which is possible) or in visualization itself (which is currently not implemented). This bug also exists in other chart types, and IMO such patches will introduce some code that does not solve the issue, but add some complexity in supporting and (later) refactoring.
@arikfr WDYT?
@kravets-levko I would agree that it might be nice to aggregate other charts in the visualization itself to help users (or to suggest to them to do the aggregation), but I don't think aggregation is the only correct solution for scatter plots.
I think that scatter plots are a little different than the other plot types. They're meant to show individual data points (e.g. imagine the x-axis is years and y-axis is house prices, there should be a point on the graph for each house price in that year). This way, a trend can be observed in a scatter plot by looking at its shape rather than looking at aggregated values. Whereas, in a chart such as a bar graph, for example, it only makes sense to have one y-value per series.
Unfortunately, it seems that the plotly implementation does show the individual data points (which is correct) but the default hover doesn't show the correct values nor does it show all of them.
@arikfr any input on this?
@arikfr thanks for pointing out those issues. I didn't realize we had such comprehensive examples in netlify to test with, that's very useful!
I've adjusted the code so it should have no impact on any other chart type except for scatter and bubble to fix the specific issues in them.
All, I support this PR too.
@arikfr just wanted to resurface this and see if there are any outstanding issues. Thanks!
@arikfr, @kravets-levko, @ranbena,
I would like to discuss this further. I suspect the issue here is "how many y-values a single x-value can have in one series"? Line, Area, Bar charts are fine with one y-value for one x-value per series. But Scatter, Bubble, Box may have multiple y-values per x-value per series.
But in the code (see below), sourceData is populated with x-value as a key. Therefore we can only have one y-value per x-value.
https://github.com/getredash/redash/blob/944adb95ba29bf241fa9a0af9a80734f3afbb3e3/client/app/visualizations/chart/plotly/prepareDefaultData.js#L99
Then, when hover texts are created based on sourceData, all data which share one x-value would have same y-values and other attributes.
Not sure what is the best way to fix this, but just wanted to share my finding.
This is old, but AFAIK it's still a real issue and would be nice to fix. The solution is correct from what I can tell.
Cool, lets try and get it done then. :smile:
@emtwo , one more thanks for the PR! We've updated a lot of things now that we're Community-driven so - if you're still interested in getting this merged - would you mind rebasing off master to re-run the CI, as well as updating merge conflicts?
We're trying to clean up our PR todo list, so if you're not interested, that's fine - we'll close the PR in about a week if we don't hear back. If you're interested in reopening the PR afterwards, we would also very much welcome that.
edit: whoops, just saw wlach and Justin's comments above.
@guidopetri Lets leave this one open for further investigation. :smile:
I believe the functionality in this change should now be located in viz-lib/src/visualizations/chart/plotly/prepareLayout.ts.
@emtwo are you able to try again using the latest checkout?