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

feat: add for-the-badge style #73

Merged
merged 3 commits into from
Dec 21, 2024
Merged

feat: add for-the-badge style #73

merged 3 commits into from
Dec 21, 2024

Conversation

ztest95
Copy link
Contributor

@ztest95 ztest95 commented Dec 9, 2024

Closes #29

📑 Description

  • added for-the-badge style.
  • added more dynamic styling options for the svg by using variables such as letter_spacing, font_size, height, title_anchor, gradient which are needed to modify the svg for this style. these are only defined, currently, within the for-the-badge style, and are not user customizable

✅ Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

☢️ Does this introduce a breaking change?

  • Yes
  • No

ℹ Additional Information

(on the above image)

  1. new for-the-badge style
  2. image referenced on issue 29
  3. square style

image

i wasn't sure if the for-the-badge style should force capitalized titles

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new style option for the progress bar: for-the-badge.
    • Enhanced styling capabilities with additional properties for progress bar customization.
  • Documentation

    • Updated the README.md to include the new for-the-badge style with an example preview and URL.

Copy link

vercel bot commented Dec 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
progressbar ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 9, 2024 7:27am

Copy link

coderabbitai bot commented Dec 9, 2024

Walkthrough

The changes in this pull request introduce a new style option called for-the-badge for progress bars in the README.md file and enhance the functionality of the get_style_fields and get_template_fields functions in app.py. The README.md now includes an example and URL for the new style, while app.py has been updated to include new properties and refined calculations for these styles, improving layout control and styling capabilities.

Changes

File Change Summary
README.md Added a new style option for-the-badge with an example preview and URL in the "Styles" section.
app.py Enhanced get_style_fields and get_template_fields functions by adding new properties and refining calculations for the for-the-badge style.

Assessment against linked issues

Objective Addressed Explanation
Add For The Badges style to progress bars (Issue #29)

Possibly related issues

Possibly related PRs

Suggested labels

help wanted, good first issue, Review effort [1-5]: 3

Suggested reviewers

  • gstraccini
  • guibranco

🐇 In the meadow, bright and bold,
A new style for progress, a sight to behold.
With badges that shine, oh what a delight,
Our progress now dances, in colors so bright!
Hop along, dear friends, let’s celebrate this cheer,
For the badge style is here, let’s give a great cheer! 🎉


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

@gstraccini gstraccini bot added enhancement New feature or request gitauto GitAuto label to trigger the app in a issue. hacktoberfest Participation in the Hacktoberfest event 📝 documentation Tasks related to writing or updating documentation labels Dec 9, 2024
@gstraccini gstraccini bot requested a review from guibranco December 9, 2024 04:55
@gstraccini gstraccini bot added the 🚦 awaiting triage Items that are awaiting triage or categorization label Dec 9, 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: 1

🧹 Outside diff range and nitpick comments (2)
app.py (2)

90-100: Consider adding documentation for the style's visual characteristics

The for-the-badge style properties are well-configured to match the expected visual appearance. Consider adding a comment block above the style definition to document its distinctive visual characteristics for future maintainers.

        },
+       # The "for-the-badge" style features:
+       # - Bold, centered text with increased letter spacing
+       # - Sharp edges (no border radius)
+       # - Solid colors (no gradient)
+       # - Taller height for better visibility
        "for-the-badge": {

166-180: Improve maintainability of text positioning calculations

While the positioning logic is functional, consider these improvements:

  1. The letter spacing fallback value (1) differs from the default style's value (0)
  2. The magic numbers for positioning (5, 14, 18) should be documented or defined as constants
+   # Constants for text positioning
+   TEXT_PADDING_LEFT = 5
+   TEXT_BASELINE_LEFT = 14
+   TEXT_BASELINE_CENTER = 18

    if style.get("title_anchor") == "left":
-       clean_req_params["title_pos_x"] = 5
-       clean_req_params["title_pos_y"] = 14
+       clean_req_params["title_pos_x"] = TEXT_PADDING_LEFT
+       clean_req_params["title_pos_y"] = TEXT_BASELINE_LEFT
    elif style.get("title_anchor") == "middle":
        clean_req_params["title_pos_x"] = (clean_req_params.get("title_width", 0) / 2)
-       clean_req_params["title_pos_y"] = 18
+       clean_req_params["title_pos_y"] = TEXT_BASELINE_CENTER

Also, ensure the letter spacing fallback matches the default style:

-   clean_req_params["title_width"] = style.get("title_width") + 10 + (6 * len(clean_req_params["title"])) + (len(clean_req_params["title"]) * style.get("letter_spacing", 1))
+   clean_req_params["title_width"] = style.get("title_width") + 10 + (6 * len(clean_req_params["title"])) + (len(clean_req_params["title"]) * style.get("letter_spacing", 0))
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8ea8b7a and c1777ec.

⛔ Files ignored due to path filters (1)
  • templates/progress.svg is excluded by !**/*.svg
📒 Files selected for processing (2)
  • README.md (1 hunks)
  • app.py (3 hunks)
🔇 Additional comments (2)
app.py (2)

65-71: LGTM: Well-structured style properties

The new style properties provide a solid foundation for customizable SVG styling with sensible defaults.


161-161: LGTM: Clean style merging implementation

The dictionary unpacking approach ensures proper override behavior where style-specific values take precedence over defaults.

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

🧹 Outside diff range and nitpick comments (2)
app.py (2)

65-71: LGTM! Consider documenting the new style properties.

The new style properties are well-chosen and provide good control over typography and layout. The default values are reasonable.

Consider adding docstring documentation for these new properties to help users understand their purpose and valid values.


166-173: Consider adding maximum title width constraint.

The title width calculation looks good, but very long titles could cause layout issues. Consider adding a maximum width constraint or text truncation.

 if "title" in clean_req_params and clean_req_params["title"] != "":
+    max_title_width = 200  # Adjust as needed
     title_width = (
         style.get("title_width")
         + 10 + (6 * len(clean_req_params["title"]))
         + (len(clean_req_params["title"]) * style.get("letter_spacing", 1))
     )
+    clean_req_params["title_width"] = min(title_width, max_title_width)
-    clean_req_params["title_width"] = title_width
 else:
     clean_req_params["title_width"] = 0
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 15fd051 and dede73f.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • app.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md
🔇 Additional comments (3)
app.py (3)

161-161: LGTM! Style merging logic is robust.

The style merging approach correctly preserves defaults while allowing style-specific overrides.


90-100: Verify the style rendering with various title lengths.

The style properties look good and align with the "For The Badge" style requirements. However, the fixed title_width of 10 combined with title_anchor: "middle" needs verification with different title lengths.

Let's verify the rendering with different title lengths:

✅ Verification successful

The previous attempt to test the endpoint directly wasn't successful since we're in a sandbox environment. Instead, let's analyze the codebase to understand how the title width is handled, which will help us determine if the fixed width of 10 could be problematic.


Fixed title width is not an issue - dynamic calculation is implemented

The codebase analysis shows that despite the initial title_width: 10 in the style template, there's a dynamic width calculation that properly handles varying title lengths. The actual width is calculated using the formula:

title_width = style.title_width + 10 + (6 * len(title)) + (len(title) * letter_spacing)

This means:

  • Base width: 10 (from template)
  • Padding: +10
  • Character width: 6 units per character
  • Letter spacing: 2 units per character (from template)

The title_anchor: "middle" positioning is then correctly calculated using this dynamic width, so there won't be any rendering issues with different title lengths.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Test the SVG generation with various title lengths
# Note: Using curl to test the endpoint directly

# Test cases with different title lengths
titles=("" "A" "Test" "Very Long Title")
for title in "${titles[@]}"; do
  echo "Testing title: $title"
  curl -s "http://localhost:5000/50?style=for-the-badge&title=$title" | grep -A 1 "<text"
done

Length of output: 722


Script:

#!/bin/bash
# Let's analyze the code to understand how title width is calculated and handled

# First, let's find the SVG generation logic
rg -l "def.*svg" --type py

# Then, let's look for title width calculation
rg "title_width|width.*calc" --type py -A 3 -B 3

# Also check for any dynamic width adjustments
ast-grep --pattern 'width = $_'

Length of output: 1642


180-186: Verify title positioning with edge cases.

The title positioning logic looks good but should be tested with edge cases:

  • Very long titles
  • Titles with special characters
  • RTL text

Let's verify the positioning with edge cases:

@guibranco guibranco removed the 🚦 awaiting triage Items that are awaiting triage or categorization label Dec 12, 2024
@guibranco
Copy link
Owner

Hi @ztest95 👋,

Thank you so much for your pull request! 🙌

I appreciate the time and effort you put into this contribution.
I'll review it shortly, and if everything looks good, I'll approve it as soon as possible.

Thanks again for your valuable contribution! 🚀

@guibranco guibranco enabled auto-merge (squash) December 21, 2024 14:19
@guibranco
Copy link
Owner

@gstraccini review

Copy link
Contributor

gstraccini bot commented Dec 21, 2024

Reviewing this pull request! 👀
Mergeable state: blocked

Commits included:
SHA: c879e0783c1e4dfd6cd05323c1431c07ce5622a0
SHA: c1777ec103f01a52277a2dd97bec23ec289c3841
SHA: dede73f6847e4a47a785c0124e6595eb28c2ba67

@guibranco guibranco disabled auto-merge December 21, 2024 14:26
@guibranco guibranco merged commit e45de6f into guibranco:main Dec 21, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📝 documentation Tasks related to writing or updating documentation enhancement New feature or request gitauto GitAuto label to trigger the app in a issue. hacktoberfest Participation in the Hacktoberfest event
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add various styles to the progress bars: For The Badges
2 participants