Skip to content

Comments

Initializing Pathfinding Visualizer Axes to Axes of State Space#791

Merged
raghumanimehta merged 7 commits intomainfrom
user/MilcToast/vis-resized-state-space-775
Feb 16, 2026
Merged

Initializing Pathfinding Visualizer Axes to Axes of State Space#791
raghumanimehta merged 7 commits intomainfrom
user/MilcToast/vis-resized-state-space-775

Conversation

@MilcToast
Copy link
Contributor

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:

  1. Added a zoom_needed boolean in build_figure() so that on first load, compute_and_add_state_space would be zoomed into the state space.
  2. Added stored_range input and last_range output 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:

  • snapping back with the state space on the top right
  • having axes that were hard-coded during the second rendering

Verification

  • Tested out on loading the visualizer to ensure that axes were set to the bounds of the state space
  • Tested out on the visualizer with panning the plot, zooming in/out, autoscaling to ensure that the plot didn't snap back

… state space

-  Keeps user actions, such as zooming, panning, autoscaling, and preventing snapping back
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.Store to persist the last user-selected plot range and wire relayoutData into 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_space now takes zoom_needed and last_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.

Comment on lines 900 to 903
# 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)
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
MilcToast and others added 2 commits February 10, 2026 14:08
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

@raghumanimehta raghumanimehta left a comment

Choose a reason for hiding this comment

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

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps the zooming logic can go to apply_layout.


def get_state_space_axes(
vs: VisualizerState,
) -> Dict[str, List[float]]:
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a class XYwhere the members of the class are x and y. You should use that instead of the dictionary.

@raghumanimehta raghumanimehta force-pushed the user/MilcToast/vis-resized-state-space-775 branch from a07849e to 4289947 Compare February 15, 2026 20:14
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
Copy link
Contributor

Choose a reason for hiding this comment

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

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
Copy link
Contributor

Choose a reason for hiding this comment

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

You should make a note that this function changes the vs

@raghumanimehta raghumanimehta merged commit 76b042a into main Feb 16, 2026
17 of 18 checks passed
@raghumanimehta raghumanimehta deleted the user/MilcToast/vis-resized-state-space-775 branch February 16, 2026 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

path Pathfinding team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PATH: Change the visualizer such that, it is always resized to the state space

2 participants