Skip to content
Permalink
Browse files

Styling

  • Loading branch information
fredericojordan committed Aug 5, 2019
1 parent 210147a commit 8b5987c92c90e899df1985233f348782f7070f77
Showing with 24 additions and 23 deletions.
  1. +22 −21 progress.py
  2. +2 −2 templates/progress.svg
@@ -3,11 +3,13 @@
from flask import Flask, make_response, redirect, render_template, request

app = Flask(__name__)
app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY", "secret_l801#+#a&^1mz)_p&qyq51j51@20_74c-xi%&i)b*u_dt^2=2key")
app.config["SECRET_KEY"] = os.environ.get(
"SECRET_KEY", "secret_l801#+#a&^1mz)_p&qyq51j51@20_74c-xi%&i)b*u_dt^2=2key"
)


def get_progress_color(progress, scale):
ratio = progress/scale
ratio = progress / scale

if ratio < 0.3:
return "#d9534f"
@@ -20,33 +22,32 @@ def get_progress_color(progress, scale):
def get_template_fields(progress):
title = request.args.get("title")

template_fields = {
"title": title,
"title_width": 10 + 6*len(title) if title else 0,
"title_color": request.args.get("color", "428bca"),
"scale": 100,
"progress": progress,
"progress_width": 60 if title else 90,
"suffix": request.args.get("suffix", "%"),
}

scale = 100
try:
template_fields["progress_width"] = int(request.args.get("width"))
except:
scale = int(request.args.get("scale"))
except ValueError:
pass

progress_width = 60 if title else 90
try:
template_fields["scale"] = int(request.args.get("scale"))
except:
progress_width = int(request.args.get("width"))
except ValueError:
pass

template_fields["color"] = get_progress_color(progress, template_fields["scale"])

return template_fields
return {
"title": title,
"title_width": 10 + 6 * len(title) if title else 0,
"title_color": request.args.get("color", "428bca"),
"scale": scale,
"progress": progress,
"progress_width": progress_width,
"progress_color": get_progress_color(progress, scale),
"suffix": request.args.get("suffix", "%"),
}


@app.route("/<int:progress>/")
def getProgressSVG(progress):
def get_progress_svg(progress):
template_fields = get_template_fields(progress)

template = render_template("progress.svg", **template_fields)
@@ -56,7 +57,7 @@ def getProgressSVG(progress):
return response


@app.route('/')
@app.route("/")
def redirect_to_github():
return redirect("https://github.com/fredericojordan/progress-bar", code=302)

@@ -7,9 +7,9 @@

<rect rx="4" x="0" width="{{ title_width + progress_width }}" height="20" fill="#{{ title_color }}"/>
<rect rx="4" x="{{ title_width }}" width="{{ progress_width }}" height="20" fill="#555" />
<rect rx="4" x="{{ title_width }}" width="{{ [progress/scale, 1] | min * progress_width | int }}" height="20" fill="{{ color }}" />
<rect rx="4" x="{{ title_width }}" width="{{ [progress/scale, 1] | min * progress_width | int }}" height="20" fill="{{ progress_color }}" />
{% if title %}
<path fill="{{ color }}" d="M{{ title_width }} 0h4v20h-4z" />
<path fill="{{ progress_color }}" d="M{{ title_width }} 0h4v20h-4z" />
{% endif %}
<rect rx="4" width="{{ title_width + progress_width }}" height="20" fill="url(#a)" />

0 comments on commit 8b5987c

Please sign in to comment.
You can’t perform that action at this time.