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

Refactor and optimise creation of DataCurve geometries #1393

Merged
merged 3 commits into from
Mar 30, 2023
Merged

Conversation

axelboc
Copy link
Contributor

@axelboc axelboc commented Mar 24, 2023

Follows #1390

I'm refactoring DataCurve like I did with ScatterPoints. Here's what changes concretely in this PR:

  • Buffer attributes are now instantiated once instead of being re-created each time.
  • Buffer attributes are now instantiated with a pre-defined size instead of via dynamically-sized, plain JS arrays. This requires preparing error bars for every data point, regardless of whether an error bar is needed/valid at each point (with the (0, 0, CAMERA_FAR) trick).
  • When errors are available, we now loop through the data only once to create all three geometries (data points, error caps, error bars), instead of three times.
  • I've decided to initialise error geometries and render ErrorBars regardless of whether showErrors is enabled or disabled. The showErrors condition is now part of the visible condition of the Three objects involved in rendering the error bars and caps. I think it's better to have a bit more work in the main loop even when errors are toggled off, than to run a full second loop when the errors are toggled on. Note however that like before, if a dataset doesn't have errors, the error geometries are never created.
  • Error bars are now rendered for error values equal to 0 (of course, when this happens, it looks like a single cap on top of the data point).
  • Error bars are no longer rendered for error values lower than 0 (until now, the top/bottom bars and caps were just swapped, so it was impossible to tell the error value was invalid).

packages/lib/src/vis/line/DataCurve.tsx Show resolved Hide resolved
packages/lib/src/vis/line/DataCurve.tsx Show resolved Hide resolved
packages/lib/src/vis/line/DataCurve.tsx Show resolved Hide resolved
packages/lib/src/vis/line/DataCurve.tsx Show resolved Hide resolved
packages/lib/src/vis/line/hooks.ts Show resolved Hide resolved
packages/lib/src/vis/line/hooks.ts Show resolved Hide resolved
packages/lib/src/vis/line/utils.ts Show resolved Hide resolved
@axelboc
Copy link
Contributor Author

axelboc commented Mar 24, 2023

I'm surprised that the CI passes since error bars are now rendered for error values equal to 0, but I guess we don't take snapshots of line visualizations with points only, so the error bar in the snapshot we do take must merge seemlessly with the curve.

@axelboc axelboc requested a review from loichuder March 28, 2023 11:31
Copy link
Member

@loichuder loichuder left a comment

Choose a reason for hiding this comment

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

Yeah, not convinced either by the hooks.

But let's move forward with this see how it goes with future refactorings.

packages/lib/src/vis/line/DataCurve.tsx Outdated Show resolved Hide resolved
packages/lib/src/vis/line/utils.ts Show resolved Hide resolved
packages/lib/src/vis/line/utils.ts Show resolved Hide resolved
@axelboc
Copy link
Contributor Author

axelboc commented Mar 30, 2023

/approve

@axelboc
Copy link
Contributor Author

axelboc commented Mar 30, 2023

Ah ha! Now we see the very subtle change of showing an error cap for errors equal to 0:

image

@axelboc axelboc merged commit 162b967 into main Mar 30, 2023
@axelboc axelboc deleted the buffer-geo-2 branch March 30, 2023 14:54
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