Support "select closest point" in addition to "select closest x-value"
From [email protected] on August 24, 2012 04:32:08
Hallo dygraph devs
We use dygraph to display relatively dense data plots with multiple series and these never has common x-values. Having the data read out in dygraph is a really nice feature, but it does not work so well under these conditions, because the read out will be constantly switching between the different series and never show all of them. I have illustrated the problem with this fiddle example: http://jsfiddle.net/eM2Mg/272/ It seems that the way it works now is that dygraph locates the x-value closest to the mouse and then displays "all" the y-values for that x. It would be nice if there was an option for the data read out so that it would instead locate a number of nearest x's (one for each series) and then display those x-values and their respective y-values.
instead of only showing the point of the x nearest to the mouse pointer to instead showing one point per series.
Is should be mentioned that the rolling average to some extend solve it, but we would rather not be looking at averaged data.
Just for completeness this is an issue in both google chrome and firefox on linux.
I hope you can help. Regards Kenneth
Original issue: http://code.google.com/p/dygraphs/issues/detail?id=374
From [email protected] on August 24, 2012 01:42:17
This is really an enhancement request, but I forgot set that value, if it is even possible for me to do that.
From danvdk on August 25, 2012 13:32:32
I'm going to interpret this as "select closest point instead of closest x-value". This is a reasonable request. There's already a Dygraph.prototype.findClosestPoint method, so this should not be difficult to add.
Summary: Support "select closest point" in addition to "select closest x-value"
Status: Accepted
Labels: -Type-Defect Type-Enhancement
From [email protected] on August 26, 2012 05:50:53
@danvdk thanks for looking into this. Just to be totally clear, what I am really interested in, is to always show the value of the closest point from each series, even if they series don't have common x-values.
From [email protected] on July 17, 2013 13:49:34
I would need the other option. Not selecting the closest point from each series (while still highlighting all series at the same time), but only showing the point of the series the mouse currently touches.
Example: Hover over the line graph nodes in https://developers.google.com/chart/interactive/docs/gallery/linechart
Just came across this and want to second this request. Glad to see it in the 2.0.0 milestone.
Is there a spec in mind for this? I added a shim into a custom build to get the behavior I need but I wouldn't be opposed to implementing a general solution for this request.
I'd imagined something like:
{ selectMode: 'closest-x' }
vs.
{ selectMode: 'euclidean' }
Alternatively, you could imagine making this a callback and having named functions for presets:
{ selectMode: Dygraph.findClosestByX }
{ selectMode: Dygraph.findClosestByEuclidean }
I'd be fine with either of those APIs. The latter has the advantage of being more general and catching typos in the JS engine, rather than in dygraphs.
Also: I'd be very happy to see a PR for this!
Ok. The second API makes more sense to me and I like the flexibility it adds for users to provide custom selection models without needing to extend the API. I'll give it a shot and open a pull request when I have something.
Sounds great. Thanks for contributing your work back to dygraphs!
I'd like to resurrect this issue and work on it, but given there's been a couple of partial attempts at it I'm not sure where to begin - take one of those as a starting point or just start from scratch. Any suggestions?
The API from the comment in 2015 still makes sense to me:
{ selectMode: 'closest-x' }
{ selectMode: 'euclidean' }
My suggestion is to generalize the code used in highlightSeriesOpts, which already enables euclidean selection.
I've got something that seems to work with all the various combinations of locked series, stacked graphs and highlighted series.
To do:
- Write new tests for the different combination of options (existing tests still pass)
- Refactor the code - at the moment it's working, but the chain of
if-elsestatements can be optimised.
@danvk I don't think it's ready for a pull request, but I'd appreciate it if you found time to have a look and see if it does what you think it should. But if you're too busy and want to wait for a proper PR that's also fine.