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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ We currently have `flat` (default), `square` and `plastic` styles:
| ![Progress](https://progress-bar.xyz/100/?style=flat) | [https://progress-bar.xyz/100/?style=flat](https://progress-bar.xyz/100/?style=flat) |
| ![Progress](https://progress-bar.xyz/100/?style=square) | [https://progress-bar.xyz/100/?style=square](https://progress-bar.xyz/100/?style=square) |
| ![Progress](https://progress-bar.xyz/100/?style=plastic) | [https://progress-bar.xyz/100/?style=plastic](https://progress-bar.xyz/100/?style=plastic) |
| ![Progress](https://progress-bar.xyz/100/?style=for-the-badge) | [https://progress-bar.xyz/100/?style=for-the-badge](https://progress-bar.xyz/100/?style=for-the-badge) |

---

Expand Down
48 changes: 42 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ def get_style_fields(style):
"show_text": True,
"show_shadow": True,
"border_radius": 4,
"letter_spacing": 0,
"font_size": 11,
"height": 20,
"progress_weight": "normal",
"title_weight": "normal",
"title_anchor": "left",
"gradient": True,
},
"flat": {
},
Expand All @@ -80,7 +87,17 @@ def get_style_fields(style):
"gloss": True, # Adding a gloss effect for plastic
},
"for-the-badge": {
#
"border_radius": 0,
"title_width": 10,
"title_color": "555",
"progress_weight": "bold",
"progress_color": "97ca00",
"show_shadow": False,
"letter_spacing": 2,
"font_size": 10,
"height": 28,
"title_anchor": "middle",
"gradient": False,
},
}
return style_templates.get(style) if style in style_templates else {}
Expand Down Expand Up @@ -125,7 +142,6 @@ def get_template_fields(progress):

req_params = {
"title": title,
"title_width": 10 + 6 * len(title) if title else 0,
"title_color": request.args.get("color"),
"scale": scale,
"progress": progress,
Expand All @@ -142,13 +158,33 @@ def get_template_fields(progress):
}

default = get_style_fields("default")
style = get_style_fields(request.args.get("style"))
style = {**default, **get_style_fields(request.args.get("style"))}
clean_req_params = {k: v for k, v in req_params.items() if v is not None}

if "progress_color" not in clean_req_params:
clean_req_params["progress_color"] = style.get("progress_color") or default.get("progress_color", get_progress_color(progress, scale))
# fields that need to be calculated based on other fields

if "title" in clean_req_params and clean_req_params["title"] != "":
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))
)
else:
clean_req_params["title_width"] = 0

return {**default, **style, **clean_req_params}
if "progress_color" not in clean_req_params:
clean_req_params["progress_color"] = style.get("progress_color") or default.get(
"progress_color", get_progress_color(progress, scale)
)

if style.get("title_anchor") == "left":
clean_req_params["title_pos_x"] = 5
clean_req_params["title_pos_y"] = 14
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

return {**style, **clean_req_params}

@app.route("/<int:progress>/")
def get_progress_svg(progress):
Expand Down
28 changes: 15 additions & 13 deletions templates/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.