dygraphs icon indicating copy to clipboard operation
dygraphs copied to clipboard

Synchronizer plugin - selectClosest option

Open n-gist opened this issue 2 years ago • 6 comments

Adds selectClosest option to synchronizer plugin so it selects values closest to desired. Defaults to false. It can be helpful when graphs have not identical x axes data. (For example, when a graph has only one of each n values of another, or the values are different, but are close visually)

As the added search method closestIdx() is a bit slower (about 3 time slower than getRowForX()), I have added some optimization logic: If the option is turned on, it checks graphs rows lengths first. If they are equal, it assumes that axes have identical values and thus tries to use getRowForX(). Otherwise, or if the value was not found, it uses new closestIdx() search function (uses binary search algorithm).

n-gist avatar Apr 09 '23 05:04 n-gist

Also filtered when the found point is out of graph view. This should be done for crosshair plugin too, I'll open separate pr for it

n-gist avatar May 16 '23 08:05 n-gist

n-gist dixit:

got about 50% performance improvement

Sweet!

Also filtered when the found point is out of graph view. This should be done for crosshair plugin too, I'll open separate pr for it

OK, thanks!

I don’t have the bandwidth to look at it currently (was ill for over two weeks and have to catch up on missed things now) but I’ll look at them eventually.

mirabilos avatar May 16 '23 16:05 mirabilos

I’ll look at them eventually

Sure, take your time. Please check https://github.com/danvk/dygraphs/pull/1037 for possible reopening. Get better!

n-gist avatar May 16 '23 16:05 n-gist

When searching for closest point on synced graphs, x axis values are compared. Fine for default graphs, but for those which are in stepPlot mode, left point should be selected, as it represents actual strict value for corresponding selection on the first graph

For example, selecting 4 on one graph, and having values on another such as [...,2,5,...], 5 is selected as closest by value. Good for default mode as closest for interpolated value, but for stepPlot graph 2 should be selected, since it is 2 for whole 2 -> 5 period

This can be done as a separate option, but it seems logical to make it the default

n-gist avatar Jul 03 '23 23:07 n-gist

Adding small fix for stepPlot mode graphs. If synchronizing graph has exact x axis value, return it, even if it is ending point of a step period

n-gist avatar Jan 30 '24 10:01 n-gist