Initializing Pathfinding Visualizer Axes to Axes of State Space#791
Initializing Pathfinding Visualizer Axes to Axes of State Space#791raghumanimehta merged 7 commits intomainfrom
Conversation
… state space - Keeps user actions, such as zooming, panning, autoscaling, and preventing snapping back
There was a problem hiding this comment.
Pull request overview
This PR updates the local pathfinding Dash visualizer to initialize (on first render) with axes zoomed to the OMPL state-space bounds instead of the hard-coded default range, and attempts to preserve user pan/zoom ranges across subsequent renders.
Changes:
- Extend
compute_and_add_state_space()/build_figure()to optionally apply either state-space bounds or a stored user range to the plot axes. - Add a
dcc.Storeto persist the last user-selected plot range and wirerelayoutDatainto the callback to capture pan/zoom/autoscale events. - Update the Dash callback outputs/inputs to include the stored axis range.
Comments suppressed due to low confidence (1)
src/local_pathfinding/local_pathfinding/visualizer.py:735
compute_and_add_state_spacenow takeszoom_neededandlast_range, but its docstring/Args section wasn’t updated to describe these parameters or their effect on axis ranges. Please update the docstring so future callers understand when the function uses stored ranges vs state-space bounds.
def compute_and_add_state_space(
boat_xy_km: Tuple[float, float],
goal_xy_km: Tuple[float, float],
fig: go.Figure,
zoom_needed: bool,
last_range: Optional[Dict[str, List[float]]]
):
"""
Build the visualization state-space overlay around the boat and goal. Then, add the built
rectangular overlay spanning the bounds of the state space and returns the state-space.
The overlay is a MultiPolygon consisting of:
- A buffer box around the boat
- A buffer box around the goal
Args:
boat_xy_km: (x, y) boat position in km.
goal_xy_km: (x, y) goal position in km.
fig: Target Plotly figure.
"""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Computing State space overlay and adding it to the plot | ||
| compute_and_add_state_space(boat_xy_km, goal_xy_km, fig) | ||
| zoom_needed = last_goal_xy_km is None | ||
| compute_and_add_state_space(boat_xy_km, goal_xy_km, fig, zoom_needed, last_range) | ||
| apply_layout(fig) |
There was a problem hiding this comment.
New behavior around axis range persistence (using zoom_needed/last_range) isn’t covered by tests. Since src/local_pathfinding/test/test_visualizer.py already unit-tests other visualizer helpers, consider adding tests that assert compute_and_add_state_space sets the layout range to (a) state-space bounds on first render and (b) last_range when provided.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
raghumanimehta
left a comment
There was a problem hiding this comment.
Good work! Please make changes mentioned in the review and as discussed.
|
|
||
| def compute_and_add_state_space( | ||
| boat_xy_km: Tuple[float, float], goal_xy_km: Tuple[float, float], fig: go.Figure | ||
| vs: VisualizerState, |
There was a problem hiding this comment.
The function is doing two sort-of related tasks. compute_and_state_space is doing something that is unexpected given the name of the function. Also, a function should ideally do one thing.
You should handle the zoom logic somewhere else.
| # Computing State space overlay and adding it to the plot | ||
| compute_and_add_state_space(boat_xy_km, goal_xy_km, fig) | ||
| zoom_needed = last_goal_xy_km is None or last_range is None | ||
| compute_and_add_state_space(state, boat_xy_km, goal_xy_km, fig, zoom_needed, last_range) |
There was a problem hiding this comment.
Perhaps the zooming logic can go to apply_layout.
|
|
||
| def get_state_space_axes( | ||
| vs: VisualizerState, | ||
| ) -> Dict[str, List[float]]: |
There was a problem hiding this comment.
We have a class XYwhere the members of the class are x and y. You should use that instead of the dictionary.
a07849e to
4289947
Compare
| boat_wind_radians = math.radians(cs.bound_to_180(boat_heading_deg + 180)) | ||
| self.bw_vector_kmph = cs.polar_to_cartesian(boat_wind_radians, boat_speed_kmph) | ||
|
|
||
| # State space |
There was a problem hiding this comment.
There is no need for this comment here.
| fig: go.Figure, | ||
| ): | ||
| """ | ||
| Build the visualization state-space overlay around the boat and goal. Then, add the built |
There was a problem hiding this comment.
You should make a note that this function changes the vs
Description
This PR addresses the issue where the pathfinding visualizer would initialize on x and y-axes [-100, 100], which was very inconvenient, since we were mostly interested in what was going on in the state space.
Changes Made:
zoom_neededboolean inbuild_figure()so that on first load,compute_and_add_state_spacewould be zoomed into the state space.stored_rangeinput andlast_rangeoutput to update_graph to store the previous axes as a result of a user panning, zooming or autoscaling.The second change was made due to the visualizer either:
Verification