-
Notifications
You must be signed in to change notification settings - Fork 5
fix color mode for smiles
#824
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
Conversation
WalkthroughThis pull request implements dark mode support for molecule image rendering across the stack. The React hook detects the color scheme and passes a dark mode flag through the API request interface to the backend, which refactors molecule drawing from RDKit's Draw.MolToImage to MolDraw2DCairo for improved dark theme rendering capabilities. Changes
Sequence DiagramsequenceDiagram
participant React as React Component
participant Hook as useMoleculeImage Hook
participant ColorScheme as useColorScheme
participant API as API Client
participant Backend as Backend Service
participant MolDraw as MolDraw2DCairo
React->>Hook: Request molecule image
Hook->>ColorScheme: Detect color scheme
ColorScheme-->>Hook: isDarkMode
Note over Hook: Update queryKey with isDarkMode<br/>for cache differentiation
Hook->>API: Call with dark flag
API->>Backend: POST /convert_molecule_to_image<br/>{data, dark: boolean}
Backend->>MolDraw: Create drawer with options
Note over MolDraw: If dark mode:<br/>adjust symbol & atom colors<br/>transparent background
MolDraw->>MolDraw: Render molecule
MolDraw-->>Backend: PNG bytes
Backend->>Backend: Base64 encode
Backend-->>API: Return encoded image
API-->>Hook: Image response
Hook-->>React: Display themed image
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/zndraw/app/utility_routes.py (1)
119-122: Consider updating palette for additional common atoms in dark mode.Currently only carbon (element 6) is updated to light grey. Other heteroatoms like nitrogen (blue), oxygen (red), and sulfur (yellow) retain their default colors. While these are generally visible on dark backgrounds, you may want to lighten them for better contrast.
🔎 Optional: Extend atom palette for improved dark mode visibility
if dark_mode: # Dark mode: light bonds/atoms for visibility on dark containers opts.setSymbolColour((0.9, 0.9, 0.9)) - opts.updateAtomPalette({6: (0.9, 0.9, 0.9)}) + opts.updateAtomPalette({ + 6: (0.9, 0.9, 0.9), # Carbon - light grey + 7: (0.5, 0.7, 1.0), # Nitrogen - lighter blue + 8: (1.0, 0.5, 0.5), # Oxygen - lighter red + 16: (1.0, 1.0, 0.5), # Sulfur - lighter yellow + })
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
docs/source/_static/screenshots/darkmode/molecule_builder.pngis excluded by!**/*.pngdocs/source/_static/screenshots/lightmode/molecule_builder.pngis excluded by!**/*.png
📒 Files selected for processing (5)
app/src/components/shared/MoleculePreview.tsxapp/src/hooks/useMoleculeImage.tsapp/src/myapi/client.tsmisc/test_screenshots.pysrc/zndraw/app/utility_routes.py
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
**/*.py: If sensible, implement collections.abc interfaces for classes, such as MutableMapping or MutableSequence
Use numpy style docstrings
Docstrings must be concise and to the point
Use type hints wherever possible. Importtyping as tif necessary, but uselist[int|float] | Noneinstead oft.Optional[t.List[int|float]]
Imports should always be at the top of the file
Files:
misc/test_screenshots.pysrc/zndraw/app/utility_routes.py
**/test_*.py
📄 CodeRabbit inference engine (AGENTS.md)
**/test_*.py: Usepytest.mark.parametrizeto avoid code duplication in tests
Tests should be very specific and test only one thing
Avoid complex test setups
Each test must be a function, not a method of a class
Files:
misc/test_screenshots.py
🧬 Code graph analysis (1)
misc/test_screenshots.py (1)
misc/conftest.py (1)
page(72-86)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: pytest (3.11, ubuntu-latest)
- GitHub Check: pytest (3.13, ubuntu-latest)
- GitHub Check: pytest (3.12, ubuntu-latest)
🔇 Additional comments (6)
misc/test_screenshots.py (1)
308-308: LGTM - delay allows dark mode molecule image to load.The 500ms delay after toggling to dark mode gives time for the molecule preview to re-fetch and render the dark-mode version of the image before capturing the screenshot.
app/src/myapi/client.ts (1)
1051-1055: LGTM - clean interface extension.The optional
darkproperty is a backwards-compatible addition that aligns with the backend API changes.src/zndraw/app/utility_routes.py (1)
112-129: LGTM - proper MolDraw2DCairo usage.The implementation correctly uses the MolDraw2DCairo API with transparent background, allowing the container to control the visual background color. The PNG generation and base64 encoding are handled correctly.
app/src/components/shared/MoleculePreview.tsx (1)
109-109: LGTM - theme-aware background for transparent molecule images.Using
background.paperinstead of hardcodedwhiteallows the container to adapt to the current theme, complementing the transparent PNG images from the backend.app/src/hooks/useMoleculeImage.ts (2)
30-34: LGTM - robust dark mode detection with safe defaults.The logic correctly handles explicit modes (
"dark","light") and system preference resolution. Defaulting to light mode for undefined/initial states avoids rendering issues during hydration.
55-55: Good cache key strategy.Including
isDarkModein the query key ensures light and dark mode images are cached separately, preventing stale images when the theme changes.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #824 +/- ##
==========================================
- Coverage 78.41% 78.30% -0.12%
==========================================
Files 153 153
Lines 18461 18466 +5
==========================================
- Hits 14477 14460 -17
- Misses 3984 4006 +22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary by CodeRabbit
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.