Skip to content
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

Added Three Different Cases for Adding a New Instance #1859

Merged
merged 14 commits into from
Jul 26, 2024

Conversation

7174Andy
Copy link
Collaborator

@7174Andy 7174Andy commented Jul 10, 2024

Description

  1. Ctrl + I should create instances slightly away from the copied instance
  2. Ctrl + V should create instances exactly on top of the instances it's copying from
  3. Right click and click "Default" to create instance should make the instance based on the location of the click

Types of changes

  • Bugfix
  • New feature
  • Refactor / Code style update (no logical changes)
  • Build / CI changes
  • Documentation Update
  • Other (explain)

Does this address any currently open issues?

This PR is an expansion of PR #1816.

Outside contributors checklist

  • Review the guidelines for contributing to this repository
  • Read and sign the CLA and add yourself to the authors list
  • Make sure you are making a pull request against the develop branch (not main). Also you should start your branch off develop
  • Add tests that prove your fix is effective or that your feature works
  • Add necessary documentation (if appropriate)

Thank you for contributing to SLEAP!

❤️

Summary by CodeRabbit

  • New Features
    • Introduced the ability to specify a location for node positions, enhancing control over instance initialization and visibility settings.
    • Updated the contextual menu in the video widget to support initializing new instances with a specific location.

Copy link

coderabbitai bot commented Jul 10, 2024

Walkthrough

The modifications enhance the create_new_instance and set_visible_nodes functions by introducing init_method and location parameters. This allows for precise adjustments of node positions based on a specified reference point. The show_contextual_menu method in the VideoWidget class was also updated to utilize these parameters, improving the accuracy and flexibility of placements during user interactions.

Changes

File Change Summary
sleap/gui/commands.py Added init_method and location parameters to create_new_instance and set_visible_nodes functions for improved control over node positioning.
sleap/gui/widgets/video.py Updated show_contextual_menu method to include location in calls to newInstance.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant VideoWidget
    participant ContextMenu
    participant Command

    User ->> VideoWidget: Right-click for context menu
    VideoWidget ->> ContextMenu: Display options
    ContextMenu ->> User: Show "Default" option
    User ->> ContextMenu: Select "Default"
    ContextMenu ->> VideoWidget: Trigger newInstance(init_method="best", location=scene_pos)
    VideoWidget ->> Command: create_new_instance(location=scene_pos)
    Command ->> Command: Adjust node positions based on location
Loading

Poem

In fields of code, nodes find their place,
Guided by points in virtual space.
With location set, they now align,
A dance of logic, pure design.
Context menus lead the way,
To precise positions, come what may. 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

codecov bot commented Jul 10, 2024

Codecov Report

Attention: Patch coverage is 70.58824% with 10 lines in your changes missing coverage. Please review.

Project coverage is 74.34%. Comparing base (7ed1229) to head (6d7943a).
Report is 24 commits behind head on develop.

Files Patch % Lines
sleap/gui/commands.py 72.72% 9 Missing ⚠️
sleap/gui/widgets/video.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1859      +/-   ##
===========================================
+ Coverage    73.30%   74.34%   +1.03%     
===========================================
  Files          134      135       +1     
  Lines        24087    24755     +668     
===========================================
+ Hits         17658    18405     +747     
+ Misses        6429     6350      -79     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@7174Andy 7174Andy marked this pull request as ready for review July 11, 2024 23:41
@7174Andy 7174Andy requested a review from roomrys July 11, 2024 23:41
@7174Andy 7174Andy self-assigned this Jul 11, 2024
Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 324377e and 2569fbe.

Files selected for processing (2)
  • sleap/gui/commands.py (4 hunks)
  • sleap/gui/widgets/video.py (1 hunks)
Additional comments not posted (5)
sleap/gui/widgets/video.py (1)

370-373: LGTM! Ensure the usage of scene_pos and newInstance method in the codebase.

The code changes are approved.

However, verify the usage of scene_pos and newInstance method to ensure correctness and consistency.

Verification successful

The usage of scene_pos and newInstance method is correct and consistent in the codebase.

The code changes are verified and approved:

  • scene_pos is properly used as a parameter to the newInstance method in multiple instances within sleap/gui/widgets/video.py.
  • The newInstance method in sleap/gui/commands.py correctly handles the location parameter.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `scene_pos` and `newInstance` method in the codebase.

# Test: Search for the usage of `scene_pos` in the codebase. Expect: Proper handling of `scene_pos`.
rg --type python -A 5 $'scene_pos'

# Test: Search for the usage of `newInstance` method in the codebase. Expect: Proper handling of `newInstance` with `location` parameter.
rg --type python -A 5 $'newInstance'

Length of output: 131


Script:

#!/bin/bash
# Description: Verify the usage of `scene_pos` and `newInstance` method in the codebase.

# Test: Search for the usage of `scene_pos` in the codebase. Expect: Proper handling of `scene_pos`.
rg -A 5 'scene_pos'

# Test: Search for the usage of `newInstance` method in the codebase. Expect: Proper handling of `newInstance` with `location` parameter.
rg -A 5 'newInstance'

Length of output: 6976

sleap/gui/commands.py (4)

2916-2916: Verify the addition of the location parameter.

The addition of the location parameter to the function signature appears correct. Ensure that all calls to create_new_instance in the codebase are updated to handle this new parameter.


2988-2988: Verify the handling of the location parameter.

The handling of the location parameter appears correct. The logic for setting node positions based on the location offset is sound. Ensure that location is properly passed and utilized in all relevant scenarios.


3015-3015: Verify the addition of the location parameter.

The addition of the location parameter to the function signature appears correct. Ensure that all calls to set_visible_nodes in the codebase are updated to handle this new parameter.


3030-3038: Verify the logic for location based node positioning.

The logic for adjusting node positions based on the location offset appears correct. Ensure that the location parameter is properly passed and utilized in all relevant scenarios.

Copy link
Collaborator

@roomrys roomrys left a comment

Choose a reason for hiding this comment

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

Have not gotten a chance to test yet, but some comments. Most important is how the offset will be affected when scaling a few lines below. AND also passing in the init_method to determine whether to offset.

sleap/gui/commands.py Outdated Show resolved Hide resolved
sleap/gui/commands.py Outdated Show resolved Hide resolved
sleap/gui/commands.py Outdated Show resolved Hide resolved
sleap/gui/commands.py Outdated Show resolved Hide resolved
@7174Andy 7174Andy requested a review from roomrys July 16, 2024 16:02
Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2569fbe and 30918d2.

Files selected for processing (1)
  • sleap/gui/commands.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • sleap/gui/commands.py

Copy link
Collaborator

@roomrys roomrys left a comment

Choose a reason for hiding this comment

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

The current implementation will add (a scaled) +10 offset even if we are in the third case

  1. Right click and click "Default" to create instance should make the instance based on the location of the click

or the unmentioned fourth case

  1. Neither cases 1-3

We want to add an unscaled +10 offset on in the first case:

  1. Ctrl + I should create instances slightly away from the copied instance

And also handle the fourth case better (i.e. 0 offset). See suggestions/comments

sleap/gui/commands.py Outdated Show resolved Hide resolved
sleap/gui/commands.py Outdated Show resolved Hide resolved
sleap/gui/commands.py Outdated Show resolved Hide resolved
sleap/gui/commands.py Outdated Show resolved Hide resolved
Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 30918d2 and 31a5183.

Files selected for processing (1)
  • sleap/gui/commands.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • sleap/gui/commands.py

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 31a5183 and 70b7977.

Files selected for processing (1)
  • sleap/gui/commands.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • sleap/gui/commands.py

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 70b7977 and 2018df5.

Files selected for processing (1)
  • sleap/gui/commands.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • sleap/gui/commands.py

@7174Andy 7174Andy requested a review from roomrys July 23, 2024 15:45
Copy link
Collaborator

@roomrys roomrys left a comment

Choose a reason for hiding this comment

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

I pushed a few changes. Do you mind reviewing? The thing I am most uncertain about is setting the OOB nodes to not visible after shifting them in bounds.

Comment on lines +3028 to +3030
reference_node = next(
(node for node in copy_instance if not node.isnan()), None
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Finds first non nan reference node

Comment on lines +3061 to +3076
if x_new_offset < 0:
x_new = 0
visible = False
elif x_new_offset > new_size_width:
x_new = new_size_width
visible = False
else:
x_new = x_new_offset
if y_new_offset < 0:
y_new = 0
visible = False
elif y_new_offset > new_size_height:
y_new = new_size_height
visible = False
else:
y_new = y_new_offset
Copy link
Collaborator

Choose a reason for hiding this comment

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

Moves out of bounds nodes to closest in bounds position. Also marks those nodes that were going to be out of bounds as not visible.

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2018df5 and a4f25f5.

Files selected for processing (1)
  • sleap/gui/commands.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • sleap/gui/commands.py

@roomrys roomrys merged commit 28c34e2 into develop Jul 26, 2024
8 checks passed
@roomrys roomrys deleted the andrew/more-cases-for-copying-instance branch July 26, 2024 03:15
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.

None yet

2 participants