Skip to content

Fix : MiniMap Not Rendering and Make It Visible #507

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gitsofaryan
Copy link
Contributor

@gitsofaryan gitsofaryan commented Mar 6, 2025

Describe the changes you have made in this PR -

This PR fixes a bug where the miniMap (that small overview map in the corner) wasn’t showing up at all. The map was either not rendering correctly, or just completely invisible.

Changes I Made -

✅ Added checks to make sure the miniMap only tries to show when it's actually supposed to.
✅ Fixed some drawing issues so the miniMap correctly updates and displays the components and wires.
✅ Made sure the miniMap correctly resizes to fit the whole workspace, so it doesn’t get stuck or disappear.
✅ Double-checked that it only shows up in dark mode, and it’s fully hidden in light mode (like it was meant to).

After Changes -

✅ MiniMap now shows up when it should.
✅ It updates as you add/remove components.
✅ It hides in light mode like expected.
✅ No more console errors related to miniMap rendering.

Screenshots of the changes (If any) -

image

Note: Please check Allow edits from maintainers. if you would like us to assist in the PR.

Summary by CodeRabbit

  • Bug Fixes

    • Added safeguards to ensure the display component initializes correctly.
    • Adjusted dimension settings and rendering operations for improved visual consistency.
  • Refactor

    • Streamlined coordinate calculations and updated variable handling for clarity.
    • Optimized styling updates for a more maintainable and consistent display behavior.
    • Enhanced method operations for better performance and readability.
    • Improved checks for element existence before operations.

Copy link
Contributor

coderabbitai bot commented Mar 6, 2025

Walkthrough

The pull request refactors the minimap functionality in the simulator. A new lightMode constant is introduced, and the type annotation for the canvas property is corrected. The setup method now includes a check for the canvas element’s existence and uses window.width and window.height for dimension initialization. Several variables have been updated from var to const/let for improved clarity, and drawing operations in the play method have been streamlined. Minor modifications include using Date.now() in the timestamp update and stricter equality checks in the removeMiniMap function. The export is also relocated to the file’s end.

Changes

File Change Summary
v0/src/simulator/src/minimap.js - Added a lightMode constant set to false
- Corrected the canvas property type from HTMLCanvasObject to HTMLCanvasElement
- Initialized and relocated miniMapArea and lastMiniMapShown variables
- Updated setup to check canvas existence and use window dimensions
- Refactored drawing logic and variable declarations (using const/let)
- Modified timestamp and equality checks; moved export to file end

Sequence Diagram(s)

sequenceDiagram
  participant App as Application
  participant MM as miniMapArea
  participant Cnv as HTMLCanvasElement
  participant Win as Window
  participant Log as Console

  App->>MM: setup()
  MM->>Cnv: Verify canvas element exists
  alt Canvas exists
    MM->>Win: Retrieve window.width & window.height
    MM->>MM: Calculate minX, maxX, minY, maxY via ternary operators
    MM->>MM: Set dimensions using template literals
  else Canvas missing
    MM->>Log: Log warning about missing canvas
  end
Loading

Poem

I’m a rabbit hopping in the code glen,
With bright new updates hidden within,
Canvas checks and sleek const/let rhymes,
Ternary tunes and fillRect chimes,
Hop along—our sim leaps ahead again! 🐰✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

netlify bot commented Mar 6, 2025

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit 6c103e2
🔍 Latest deploy log https://app.netlify.com/sites/circuitverse/deploys/67c9e9a744f15c000896369e
😎 Deploy Preview https://deploy-preview-507--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a9f309 and 71170f5.

📒 Files selected for processing (1)
  • v0/src/simulator/src/minimap.js (2 hunks)
🧰 Additional context used
🪛 GitHub Check: ESLint
v0/src/simulator/src/minimap.js

[failure] 111-111: disallow the use of undeclared variables unless mentioned in /*global */ comments
'updateOrder' is not defined.

🪛 ESLint
v0/src/simulator/src/minimap.js

[error] 111-111: 'updateOrder' is not defined.

(no-undef)

🔇 Additional comments (5)
v0/src/simulator/src/minimap.js (5)

39-53: Good refactoring of boundary calculations

The use of ternary operators for calculating boundaries improves readability. Good work!


71-75: Good practice using template literals

The switch to template literals for style assignments is cleaner and more readable.


112-144: Good modernization of loops

The switch from var to let and use of for...of loops improves code quality and reduces potential scoping issues.


160-160: Good use of Date.now()

Using Date.now() instead of new Date().getTime() is more concise and slightly more efficient.


170-170:

❓ Verification inconclusive

Verify timing logic for minimap removal

The condition has been changed from <= to >= which inverts the logic. Ensure this is intentional and correct.


🏁 Script executed:

#!/bin/bash
# Find the original implementation to compare
echo "Searching for previous implementation of removeMiniMap..."
git log -p -- "v0/src/simulator/src/minimap.js" | grep -A 5 -B 5 "lastMiniMapShown.*Date"

Length of output: 124


Action: Confirm the Intended Inversion of the Timing Logic
The condition now reads:

if (lastMiniMapShown + 2000 >= Date.now()) {

which is the inverse of the previous <= operator. No historical diff context was found to indicate an intentional change, so please verify that switching to >= correctly captures the minimap's removal timing behavior. If this adjustment was made on purpose, consider adding a brief explanatory note in the commit message.

@gitsofaryan
Copy link
Contributor Author

gitsofaryan commented Mar 6, 2025

cc : @vedant-jain03 @niladrix719 @aryanndwi123 can you please look my PR. the codeclimate test failing cause of similarity of code with just axis name changes 'x' and 'y'.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

♻️ Duplicate comments (2)
v0/src/simulator/src/minimap.js (2)

34-35: ⚠️ Potential issue

Use proper window dimension properties

window.height and window.width are not standard browser properties. You should use window.innerHeight and window.innerWidth instead.

- this.pageHeight = window.height // Make sure you define `height` correctly in your environment.
- this.pageWidth = window.width // Make sure you define `width` correctly in your environment.
+ this.pageHeight = window.innerHeight
+ this.pageWidth = window.innerWidth

5-5: 🛠️ Refactor suggestion

Use a proper theme import rather than a hardcoded value

The lightMode constant is currently hardcoded to false, but the commented code suggests it should be using an isLightMode() function. This approach won't dynamically respond to theme changes.

- const lightMode = false // isLightMode()
+ import { isLightMode } from './themer/themer' // Adjust import path as needed
+ const lightMode = isLightMode()
🧹 Nitpick comments (4)
v0/src/simulator/src/minimap.js (4)

7-7: Use let instead of var and combine declaration with initialization

Using var is outdated in modern JavaScript. Since this object is initialized later, you should use let for more appropriate scoping.

- var miniMapArea
+ let miniMapArea

20-21: Use proper JSDoc format for global variables

The comment for global updateOrder doesn't follow proper JSDoc format. If you want to declare it as a global dependency, use the @global tag.

- * global updateOrder 
+ * @global {Array} updateOrder - Array determining the order of elements to render

28-32: Redundant canvas initialization

The canvas is already initialized at line 23, making this re-initialization redundant. However, the added null check is good for error handling.

- this.canvas = document.getElementById('miniMapArea')
- if (!this.canvas) {
+ if (!this.canvas) {
    console.warn('miniMapArea canvas element not found')
    return
}

161-161: Use let instead of var for better scoping

Using var is outdated in modern JavaScript. Use let for variables that will be reassigned.

- var lastMiniMapShown = 0
+ let lastMiniMapShown = 0
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a135712 and 6c103e2.

📒 Files selected for processing (1)
  • v0/src/simulator/src/minimap.js (2 hunks)
🔇 Additional comments (9)
v0/src/simulator/src/minimap.js (9)

39-55: Good refactoring using ternary operators

The refactoring of the min/max calculations using ternary operators improves readability while maintaining the same logic. Well done!


73-77: Good error handling for miniMap element dimensions

Adding a null check before setting the element dimensions is a good practice. The use of template literals for style property values is also a modern approach.


87-87: Improved drawing efficiency

Using fillRect() directly instead of separate rect() and fill() calls is more efficient and concise.


97-97: Improved line visibility

Setting the line width to 2 improves the visibility of the minimap elements, which addresses one of the PR objectives.


153-157: Inconsistent canvas references

In the clear method, you're creating a new reference to the canvas element with document.getElementById('miniMapArea') while also using this.canvas. This is redundant and could lead to confusion.

clear() {
    if (lightMode) return
-   const canvas = document.getElementById('miniMapArea')
-   if (canvas) {
+   if (this.canvas) {
        $('#miniMapArea').css('z-index', '-1')
        this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height)
    }
}

164-164: Good use of Date.now()

Using Date.now() instead of new Date().getTime() is more concise and efficient.


167-177: Good early returns and strict equality checks

The use of early returns and strict equality checks improves the code's clarity and reliability. The timeout logic ensures the minimap is only hidden after being visible for at least 2 seconds.


182-182: Good code organization

Moving the export statement to the end of the file improves code organization and readability.


113-113:

✅ Verification successful

Fixed undefined variable issue

Properly referencing window.updateOrder with a fallback to an empty array fixes the undefined variable issue highlighted in previous code scans.


🏁 Script executed:

#!/bin/bash
# Check if updateOrder is properly defined in the global scope
echo "Checking references to updateOrder in the codebase:"
rg -A 2 "updateOrder\s*=|window.updateOrder" --type js

Length of output: 731


Review Approved: Proper Global Variable Initialization in minimap.js

The change to use a fallback value with window.updateOrder in v0/src/simulator/src/minimap.js is verified. The shell script output confirms that window.updateOrder is indeed defined in the corresponding setup files, ensuring that the code no longer encounters an undefined variable.

  • The snippet const lst = window.updateOrder || [] safely defaults to an empty array if window.updateOrder isn’t set.
  • References in both v0/src/simulator/src/setup.js and v1/src/simulator/src/setup.js confirm that the global variable is appropriately defined.

Copy link
Member

@vedant-jain03 vedant-jain03 left a comment

Choose a reason for hiding this comment

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

Thanks @gitsofaryan for the contribution. I have tested the minimap rendering in the preview URL ✅

I have some comments regarding code, PTAL!

@@ -2,79 +2,80 @@ import simulationArea from './simulationArea'
import { colors } from './themer/themer'
import { layoutModeGet } from './layoutMode'

const lightMode = false // isLightMode()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const lightMode = false // isLightMode()
const isLightMode = false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the suggestion, i will update the variable name.

this.pageY = this.pageHeight - globalScope.oy
this.pageX = this.pageWidth - globalScope.ox
// CodeClimate ignore similar lines check
Copy link
Member

Choose a reason for hiding this comment

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

any reason to add this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added this ignore comment to suppress the CodeClimate duplication block warning because the pageX and pageY calculations are essential for positioning in the minimap logic. and it looked similar block of code to code climate.

this.maxY = (simulationArea.maxHeight !== undefined)
? Math.max(simulationArea.maxHeight, this.pageY / globalScope.scale)
: this.pageY / globalScope.scale
// CodeClimate ignore similar lines check
Copy link
Member

Choose a reason for hiding this comment

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

any reason to add this?

this.minX = (simulationArea.minWidth !== undefined)
? Math.min(simulationArea.minWidth, -globalScope.ox / globalScope.scale)
: -globalScope.ox / globalScope.scale
// CodeClimate ignore similar lines check
Copy link
Member

Choose a reason for hiding this comment

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

any reason to add this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

used terneray style to make coed look concise and shorter. if you'd like, i can refactor it to prev if else version.

resolve(ratio) {
if (lightMode) return

this.ctx.fillStyle = '#ddd'
this.ctx.beginPath()
this.ctx.lineWidth = 2 // Thicker lines for better visibility
Copy link
Member

Choose a reason for hiding this comment

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

Do we have same lineWidth in legacy simulator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in the legacy simulator minimap code, their is no explicit mention of line width, it is set with value as it is from canvas. this is new change to make the minimap visible.

@vedant-jain03
Copy link
Member

Also, please create a issue and attach to this PR!

@niladrix719
Copy link
Member

niladrix719 commented Mar 7, 2025

We cannot merge it with v0. Updates need to be made in src/ for now. Let's discuss this tomorrow in the mentors' meeting because many contributors are facing this issue @vedant-jain03

@ThatDeparted2061
Copy link
Member

@vedant-jain03 @niladrix719
Could you consider this idea pertaining to the conflicts
#495 (comment)

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.

4 participants