Skip to content

Synchronizer plugin - selectClosest option#1035

Open
n-gist wants to merge 7 commits into
danvk:masterfrom
n-gist:synchronizer-option-select-closest
Open

Synchronizer plugin - selectClosest option#1035
n-gist wants to merge 7 commits into
danvk:masterfrom
n-gist:synchronizer-option-select-closest

Conversation

@n-gist

@n-gist n-gist commented Apr 9, 2023

Copy link
Copy Markdown
Contributor

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 n-gist left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to use layout_.points instead of graph.getValue() for closest point search. Tested on two synchronized graphs (of 1000 and 100 rows resp) with 1mil iterations, got about 50% performance improvement when unzoomed and more if zoomed in

@n-gist

n-gist commented May 16, 2023

Copy link
Copy Markdown
Contributor Author

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

@mirabilos

mirabilos commented May 16, 2023 via email

Copy link
Copy Markdown
Collaborator

@n-gist

n-gist commented May 16, 2023 via email

Copy link
Copy Markdown
Contributor Author

@n-gist

n-gist commented Jul 3, 2023

Copy link
Copy Markdown
Contributor Author

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

n-gist commented Jan 30, 2024

Copy link
Copy Markdown
Contributor Author

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

n-gist commented Jan 17, 2025

Copy link
Copy Markdown
Contributor Author

I have added a note to comment section at the top, and made code style fixes

Also created an example to test the option https://jsfiddle.net/3d80v5xc/
graph 2 has no points on 3,4,5 x values
graph 3 has no points on 5,6,7
When you hover over these values on graph 1, nothing is selected on other two graphs
Toggle selectionClosest to true, so that it starts to select points closest to desired

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants