Skip to content

Fix: Grid not showing in altair if both draw_structure and draw_agnets are called. #2817

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

Merged
merged 1 commit into from
Jul 25, 2025

Conversation

Sahil-Chhoker
Copy link
Collaborator

@Sahil-Chhoker Sahil-Chhoker commented Jul 22, 2025

Summary

If both draw_structure and draw_agnets are called in altair backend, the grid won't show because the axis are overridden when layering the two charts.

Implementation

Resolved the axis for both x and y to independent to prevent overriding of axis because of charts.

Summary by CodeRabbit

  • Refactor
    • Improved the display of layered spatial charts by setting their axes to be independent, enhancing clarity when viewing multiple chart layers.

@Sahil-Chhoker
Copy link
Collaborator Author

@coderabbitai full review

Copy link

coderabbitai bot commented Jul 22, 2025

✅ Actions performed

Full review triggered.

@Sahil-Chhoker Sahil-Chhoker requested a review from tpike3 July 22, 2025 04:14
Copy link

coderabbitai bot commented Jul 22, 2025

Walkthrough

The update modifies how multiple spatial charts are combined in the SpaceRendererComponent function by applying independent resolution to the x and y axes using Altair's .resolve_axis(x="independent", y="independent") method. No other logic, control flow, or public API changes are introduced.

Changes

File(s) Change Summary
mesa/visualization/solara_viz.py Modified chart layering to set x and y axes as independent when combining multiple charts.

Estimated code review effort

1 (~2 minutes)

Poem

In the meadow of charts, axes roam free,
Each one independent, as far as can be.
No more crowding or tangled display,
The charts now layer in their own special way.
A hop and a skip, the data’s in view—
This bunny’s delighted with something so new! 🐇📊


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47eff74 and 13fc327.

📒 Files selected for processing (1)
  • mesa/visualization/solara_viz.py (1 hunks)
🧠 Learnings (2)
📓 Common learnings
Learnt from: Sahil-Chhoker
PR: projectmesa/mesa#2803
File: mesa/visualization/backends/altair_backend.py:312-553
Timestamp: 2025-06-20T16:44:20.677Z
Learning: In mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer method intact despite its complexity, as they believe breaking it into smaller functions would divert attention from the main logic flow. The method is well-documented and follows a clear sequence of operations for property layer rendering.
mesa/visualization/solara_viz.py (1)

Learnt from: Sahil-Chhoker
PR: #2803
File: mesa/visualization/backends/altair_backend.py:312-553
Timestamp: 2025-06-20T16:44:20.677Z
Learning: In mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer method intact despite its complexity, as they believe breaking it into smaller functions would divert attention from the main logic flow. The method is well-documented and follows a clear sequence of operations for property layer rendering.

🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Sahil-Chhoker
PR: projectmesa/mesa#2803
File: mesa/visualization/backends/altair_backend.py:312-553
Timestamp: 2025-06-20T16:44:20.677Z
Learning: In mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer method intact despite its complexity, as they believe breaking it into smaller functions would divert attention from the main logic flow. The method is well-documented and follows a clear sequence of operations for property layer rendering.
mesa/visualization/solara_viz.py (1)

Learnt from: Sahil-Chhoker
PR: #2803
File: mesa/visualization/backends/altair_backend.py:312-553
Timestamp: 2025-06-20T16:44:20.677Z
Learning: In mesa/visualization/backends/altair_backend.py, the author prefers to keep the draw_propertylayer method intact despite its complexity, as they believe breaking it into smaller functions would divert attention from the main logic flow. The method is well-documented and follows a clear sequence of operations for property layer rendering.

⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: run-benchmarks
🔇 Additional comments (1)
mesa/visualization/solara_viz.py (1)

322-324: Excellent fix for the axis override issue!

This change correctly addresses the grid visibility problem by ensuring independent axis resolution when layering multiple spatial charts. Without this fix, when draw_structure and draw_agents are both called, the resulting layered charts could have their axis settings override each other, causing the grid to disappear. The .resolve_axis(x="independent", y="independent") ensures each chart maintains its own axis configuration.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -2.0% [-3.1%, -0.9%] 🔵 -0.2% [-0.4%, -0.0%]
BoltzmannWealth large 🔵 -1.9% [-3.2%, -1.0%] 🔵 -5.4% [-7.9%, -3.0%]
Schelling small 🔵 -0.9% [-1.1%, -0.7%] 🔵 -0.6% [-0.8%, -0.4%]
Schelling large 🔵 -1.0% [-1.4%, -0.5%] 🔵 -2.3% [-4.4%, -0.6%]
WolfSheep small 🔵 +1.3% [+0.9%, +1.6%] 🔵 +1.0% [+0.7%, +1.2%]
WolfSheep large 🔵 +1.1% [+0.0%, +2.1%] 🔴 +5.7% [+3.2%, +7.8%]
BoidFlockers small 🔵 -2.9% [-3.4%, -2.4%] 🔵 -2.5% [-2.7%, -2.3%]
BoidFlockers large 🔵 -2.9% [-3.4%, -2.4%] 🔵 -1.7% [-2.1%, -1.3%]

Copy link
Member

@tpike3 tpike3 left a comment

Choose a reason for hiding this comment

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

LGTM

@tpike3 tpike3 merged commit 8ebd1d9 into projectmesa:main Jul 25, 2025
13 checks passed
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