Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(weave): optimize finding next tick up or down #3231

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

brianlund-wandb
Copy link
Contributor

@brianlund-wandb brianlund-wandb commented Dec 13, 2024

Description

Fixes getNearestTick() in SliderInput.tsx by including the existing value of the slider to to determine whether to look above or below the previous value.
Optimized function for better performance over large lists.
Included a new test file for basic unit tests of the function.

Testing

Added new unit tests to verify basic functionality.
Created a project with varying steps to ensure slider increments appropriately.

@brianlund-wandb brianlund-wandb requested a review from a team as a code owner December 13, 2024 06:17
@circle-job-mirror
Copy link

diff < minDiff &&
((increasing && tick >= val) || (!increasing && tick <= val))
) {
closest = tick;

Choose a reason for hiding this comment

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

could we have something to break out early if tick is equal to val?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, lets not go searching through half the list if the slider increments to a valid step, heh. Good call.

const end = Date.now();
const duration = end - start;
expect(actual).toBe(500002);
expect(duration).toBeLessThanOrEqual(1);

Choose a reason for hiding this comment

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

these tests are awesome! could you add one for testing the bounds as well? like one where the val is less than the smallest tick and also one where the val is larger than the largest tick?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I like it, sure. That logic lives in the update() function that calls getClosestTick() when it has a list of ticks. I might suck that logic into this function instead, and leave update() as a, "get the right value and synchronize the inputs fields."

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