-
Notifications
You must be signed in to change notification settings - Fork 8
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 arrow_data_to_origin option #217
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -153,7 +153,7 @@ def __init__(self, key, default): | |||||||||||||||||||||||||||||||
"dict with following items are accepted: " | ||||||||||||||||||||||||||||||||
"{title: str, pos: tuple, size: list, title_font: str, " | ||||||||||||||||||||||||||||||||
"title_xoffset: float, title_yoffset: float, title_size: float, " | ||||||||||||||||||||||||||||||||
"title_rotation: float, nlabels: int, label_font:str, " | ||||||||||||||||||||||||||||||||
"title_rotation: float, nlabels: int, label_font: str, " | ||||||||||||||||||||||||||||||||
"label_size: float, label_offset: float, label_rotation: int, " | ||||||||||||||||||||||||||||||||
"label_format: str, draw_box: bool, above_text: str, below_text: str, " | ||||||||||||||||||||||||||||||||
"nan_text: str, categories: list}", | ||||||||||||||||||||||||||||||||
|
@@ -180,6 +180,13 @@ def __init__(self, key, default): | |||||||||||||||||||||||||||||||
"cmap, colors are based on the size of the arrows.", | ||||||||||||||||||||||||||||||||
(str, tuple, list, int), | ||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||
Option( | ||||||||||||||||||||||||||||||||
"vedo", | ||||||||||||||||||||||||||||||||
"arrow_data_to_origin", | ||||||||||||||||||||||||||||||||
"Points arrow data to geometric origin." | ||||||||||||||||||||||||||||||||
"Equivalent to shifting arrows backwards with their own magitudes.", | ||||||||||||||||||||||||||||||||
(bool,), | ||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||
Comment on lines
+183
to
+189
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Fix typo and enhance documentation. The implementation looks good and aligns well with the PR objectives. However, there are a few minor improvements needed:
Here's the suggested improvement: Option(
"vedo",
"arrow_data_to_origin",
- "Points arrow data to geometric origin."
- "Equivalent to shifting arrows backwards with their own magitudes.",
+ "Points arrow data to geometric origin. By default, arrows point away from origin. "
+ "When enabled, arrows are shifted backwards by their own magnitudes. "
+ "Works in conjunction with arrow_data and arrow_data_scale options.",
(bool,),
), 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||
Option( | ||||||||||||||||||||||||||||||||
"vedo", | ||||||||||||||||||||||||||||||||
"axes", | ||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -367,10 +367,11 @@ def make_showable(obj, as_dict=False, **kwargs): | |||||||||||||||||||||
|
||||||||||||||||||||||
# we are here because this data is not a scalar | ||||||||||||||||||||||
# is showable? | ||||||||||||||||||||||
if arrow_data_value.shape[1] not in (2, 3): | ||||||||||||||||||||||
a_data_dim = arrow_data_value.shape[1] | ||||||||||||||||||||||
if a_data_dim not in (2, 3): | ||||||||||||||||||||||
raise ValueError( | ||||||||||||||||||||||
"Only 2D or 3D data can be shown.", | ||||||||||||||||||||||
f"Requested data is {arrow_data_value.shape[1]}", | ||||||||||||||||||||||
f"Requested data is {a_data_dim}D.", | ||||||||||||||||||||||
Comment on lines
+371
to
+374
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Combine Error Messages into a Single String When raising the Apply this diff to combine the error message: if a_data_dim not in (2, 3):
raise ValueError(
- "Only 2D or 3D data can be shown.",
- f"Requested data is {a_data_dim}D.",
+ f"Only 2D or 3D data can be shown. Requested data is {a_data_dim}D."
) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
) | ||||||||||||||||||||||
|
||||||||||||||||||||||
as_edges = from_data( | ||||||||||||||||||||||
|
@@ -379,6 +380,16 @@ def make_showable(obj, as_dict=False, **kwargs): | |||||||||||||||||||||
obj.show_options.get("arrow_data_scale", None), | ||||||||||||||||||||||
data_norm=obj.vertex_data.as_scalar(arrow_data), | ||||||||||||||||||||||
) | ||||||||||||||||||||||
|
||||||||||||||||||||||
if obj.show_options.get("arrow_data_to_origin", False): | ||||||||||||||||||||||
# point arrow to the origin instead | ||||||||||||||||||||||
arrow_shift = np.diff( | ||||||||||||||||||||||
as_edges.vertices.reshape(-1, 2, a_data_dim), axis=1 | ||||||||||||||||||||||
) | ||||||||||||||||||||||
as_edges.vertices[:] = ( | ||||||||||||||||||||||
as_edges.vertices.reshape(-1, 2, a_data_dim) - arrow_shift | ||||||||||||||||||||||
).reshape(-1, a_data_dim) | ||||||||||||||||||||||
Comment on lines
+386
to
+391
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor Arrow Adjustment Code for Clarity Consider refactoring the code that adjusts the arrow vertices to improve readability and efficiency. Apply this diff to simplify the code: - arrow_shift = np.diff(
- as_edges.vertices.reshape(-1, 2, a_data_dim), axis=1
- )
- as_edges.vertices[:] = (
- as_edges.vertices.reshape(-1, 2, a_data_dim) - arrow_shift
- ).reshape(-1, a_data_dim)
+ arrow_vertices = as_edges.vertices.reshape(-1, 2, a_data_dim)
+ arrow_shift = np.diff(arrow_vertices, axis=1)
+ arrow_vertices -= arrow_shift
+ as_edges.vertices = arrow_vertices.reshape(-1, a_data_dim) This refactoring reduces the number of reshapes and makes the code easier to understand. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
arrows = vedo.Arrows( | ||||||||||||||||||||||
as_edges.vertices[as_edges.edges], | ||||||||||||||||||||||
c=obj.show_options.get("arrow_data_color", "plasma"), | ||||||||||||||||||||||
|
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.
LGTM!
The code segment that assigns random coordinates to the
coords
attribute of thevertex_data
dictionary for each mesh is correct and contributes to the dynamic visualization of the mesh data.To improve the code readability, consider extracting the random coordinate generation logic into a separate function or variable. For example:
This change is not necessary but can make the code more readable and maintainable.