-
Notifications
You must be signed in to change notification settings - Fork 368
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
Add utility to rr.components.Color
to generate colors from any string (and use it in the air traffic data example)
#8458
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from __future__ import annotations | ||
|
||
import colorsys | ||
import math | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from . import Color | ||
|
||
_GOLDEN_RATIO = (math.sqrt(5.0) - 1.0) / 2.0 | ||
|
||
|
||
class ColorExt: | ||
"""Extension for [Color][rerun.components.Color].""" | ||
|
||
@staticmethod | ||
def from_string(s: str) -> Color: | ||
""" | ||
Generate a random yet color based on a string. | ||
abey79 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The color is guaranteed to be identical for the same input string. | ||
""" | ||
|
||
from . import Color | ||
|
||
# adapted from egui::PlotUi | ||
hue = (hash(s) & 0xFFFF) / 2**16 * _GOLDEN_RATIO | ||
return Color([round(comp * 255) for comp in colorsys.hsv_to_rgb(hue, 0.85, 0.5)]) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good lord I didnt realize how much that code needs tagged components 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good example of a component which is intended to be shared across two archetypes, btw. Hopefully we don't make that use case too contrived, aka if that
Color
is tagged with thePoints3D
archetype, it should be implicitly(?) used by theGeoPoints
archetype as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha yeah I didn't even realize that was what's happening, interesting.
Yeah we'll have to figure out how we want to handle those. I do think heuristics to implicitly pick up the same component from unrelated tags if on the same entity makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vaguely related is one realisation we've had when discussing the archetype vs. visualiser relationship the other day: indicator components are additive, while tags are exclusive. With the former, you could have 2 archetypes with 1 components (e.g. hypothetical ScalarSeriesLine + ScalarSeriesPoint archetypes based on a single scalar component + 2 indicators), but with the latter you are forced to make a choice.
We don't think this constraint is going to be much of problem though. More in #8368