redash icon indicating copy to clipboard operation
redash copied to clipboard

Closes #3497: Show correct values on hover of scatterplot.

Open emtwo opened this issue 6 years ago • 12 comments

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)

screen shot 2019-03-04 at 5 47 03 pm screen shot 2019-03-04 at 5 47 14 pm

emtwo avatar Mar 04 '19 22:03 emtwo

@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 avatar Mar 05 '19 09:03 kravets-levko

@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.

emtwo avatar Mar 05 '19 13:03 emtwo

@arikfr any input on this?

ranbena avatar Mar 10 '19 07:03 ranbena

@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.

emtwo avatar Mar 12 '19 14:03 emtwo

All, I support this PR too.

deecay avatar May 24 '19 05:05 deecay

@arikfr just wanted to resurface this and see if there are any outstanding issues. Thanks!

emtwo avatar Jun 05 '19 17:06 emtwo

@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.

deecay avatar Dec 14 '19 19:12 deecay

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.

wlach avatar Jul 17 '23 13:07 wlach

Cool, lets try and get it done then. :smile:

justinclift avatar Jul 17 '23 13:07 justinclift

@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 avatar Jul 21 '23 19:07 guidopetri

@guidopetri Lets leave this one open for further investigation. :smile:

justinclift avatar Jul 22 '23 08:07 justinclift

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?

eradman avatar Mar 05 '24 18:03 eradman