Skip to content

Commit ee5c8f4

Browse files
added themes
1 parent 7558727 commit ee5c8f4

19 files changed

+97
-34
lines changed

digest.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,44 @@
55
from utils.load_components import default_theme
66
from lib.style import fetchCustomCSS
77
from lib.user import User
8+
from lib.themes import Theme
89

910
app = Flask(__name__)
1011

1112

1213
# grabs user data from a leetcode api and returns the svg template with the data filled in.
13-
def populateSVG(svg: str, username: str, styling: str):
14+
def populateSVG(svg: str, username: str, styling: str, theme: dict):
1415
data = User(username)
1516
return svg.format(
1617
username=data.username,
1718
rank=data.ranking,
1819
easy=data.easySolved,
1920
medium=data.mediumSolved,
2021
hard=data.hardSolved,
21-
chart=svgDonutChart(275,30, 'lightgreen', 50, 20, data.solvedDeg, 100),
22+
chart=svgDonutChart(275,30, theme.green, theme.light, 50, 20, data.solvedDeg, 100),
2223
totalCompleted=f'{data.totalSolved} / {data.totalQuestions}',
2324
stylesheet=styling,
25+
theme = theme
2426
)
2527

2628
# returns the generated svg with a given user name
2729
@app.route('/svg/<username>')
2830
def svg(username):
2931
custom_stylesheet = request.args.get('stylesheet')
32+
custom_theme = request.args.get('theme')
3033

34+
if custom_theme == None:
35+
# default theme is nord
36+
custom_theme = 'nord'
37+
3138
if custom_stylesheet == None:
3239
custom_stylesheet = default_theme
3340
else:
3441
custom_stylesheet = fetchCustomCSS(custom_stylesheet)
42+
43+
theme = Theme(custom_theme)
3544

36-
svg_text = populateSVG(svg_template, escape(username), custom_stylesheet)
45+
svg_text = populateSVG(svg_template, escape(username), custom_stylesheet, theme)
3746
return Response(svg_text, mimetype='image/svg+xml')
3847

3948
# app to customise svg

lib/chart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def getCoordsFromDeg(angle, radius, svgSize):
88
return [coordX, coordY]
99

1010

11-
def svgDonutChart(x : int , y : int, color: str, radius: int, border_size: int, angle: int, svgSize: int):
11+
def svgDonutChart(x : int , y : int, color: str,bg_color: str, radius: int, border_size: int, angle: int, svgSize: int):
1212
# due to a bug with svg coordinates, an angle of 360 produces an empty chart.
1313
if angle == 360:
1414
angle -= 0.01
@@ -28,5 +28,5 @@ def svgDonutChart(x : int , y : int, color: str, radius: int, border_size: int,
2828
"""
2929
full_slice = f"M {svgSize} {radius} \n A {radius} {radius} 0 1 0 {outer_coords_full[0]} {outer_coords_full[1]} \n L {inner_coords_full[0]} {inner_coords_full[1]} \n A {radius - border_size} {radius - border_size} 0 1 1 {svgSize - border_size} {radius}"
3030
return svg_chart_template.format(
31-
x=x, y=y, color=color, path_slice=path_string, full_slice=full_slice
31+
x=x, y=y, color=color, bg_color=bg_color, path_slice=path_string, full_slice=full_slice
3232
)

lib/json/colours.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

lib/json/themes.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"nord" : {
3+
"dark" : "#2e3440",
4+
"light" : "#eceff4",
5+
"green" : "#eceff4",
6+
"yellow" : "#eceff4",
7+
"red" : "#eceff4"
8+
},
9+
"dracula" : {
10+
"dark" : "#282a36",
11+
"light" : "#f8f8f2",
12+
"green" : "#50fa7b",
13+
"yellow" : "#f1fa8c",
14+
"red" : "#ff5555"
15+
},
16+
"gruvbox" : {
17+
"dark" : "#282828",
18+
"light" : "#fbf1c7",
19+
"green" : "#98971a",
20+
"yellow" : "#d79921",
21+
"red" : "#cc241d"
22+
},
23+
"one_dark" : {
24+
"dark" : "#282c34",
25+
"light" : "#Abb2bF",
26+
"green" : "#98c379",
27+
"yellow" : "#E5c07b",
28+
"red" : "#e06c75"
29+
},
30+
"monokai" : {
31+
"dark" : "#2e2e2e",
32+
"light" : "#d6d6d6",
33+
"green" : "#b4d273",
34+
"yellow" : "#e5b567",
35+
"red" : "#e56767"
36+
},
37+
"solarized_dark" : {
38+
"dark" : "#073642",
39+
"light" : "#fdf6e3",
40+
"green" : "#859900",
41+
"yellow" : "#b58900",
42+
"red" : "#d30102"
43+
},
44+
"solarized_light" : {
45+
"dark" : "#fdf6e3",
46+
"light" : "#073642",
47+
"green" : "#859900",
48+
"yellow" : "#b58900",
49+
"red" : "#d30102"
50+
},
51+
"tokyo" : {
52+
"dark" : "#24283b",
53+
"light" : "#9aa5ce",
54+
"green" : "#9ece6a",
55+
"yellow" : "#e0af68",
56+
"red" : "#f7768e"
57+
},
58+
"terminal" : {
59+
"dark" : "#0c0c0c",
60+
"light" : "#cccccc",
61+
"green" : "#13a10e",
62+
"yellow" : "#c19c00",
63+
"red" : "#c50f1f"
64+
}
65+
}

lib/themes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
class Theme():
44
def __init__(self, theme: str) -> None:
5-
self.path = './lib/json/colours.json'
5+
self.path = './lib/json/themes.json'
66
self.theme = theme
77
self._loadTheme()
88

99
def _loadTheme(self) -> None:
10-
""" Loads the colour themes from json file and appends to colours object """
10+
""" Loads the colour themes from json file and appends to object """
1111
with open(self.path, 'r') as f:
1212
colours_dic = json.loads(f.read())
1313

static/components/chart.svg

Lines changed: 1 addition & 1 deletion
Loading

static/digest.svg

Lines changed: 7 additions & 7 deletions
Loading

static/img/dracula.png

12.5 KB
Loading

static/img/gruvbox.png

12.2 KB
Loading

static/img/monokai.png

11.9 KB
Loading
File renamed without changes.

static/img/one_dark.png

12.3 KB
Loading

static/img/solarized_dark.png

12.6 KB
Loading

static/img/solarized_light.png

12.4 KB
Loading

static/img/terminal.png

11.7 KB
Loading

static/img/tokyo.png

12.4 KB
Loading

static/js/index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const themes = {
22
"nord" : "nord.png",
33
"dracula" : "dracula.png",
4-
"gruvbox" : "base16.png",
4+
"gruvbox" : "gruvbox.png",
55
"one_dark" : "one_dark.png",
66
"monokai" : "monokai.png",
77
"solarized_dark" : "solarized_dark.png",
@@ -10,19 +10,13 @@ const themes = {
1010
"terminal" : "terminal.png"
1111
}
1212

13-
14-
// on click
15-
// fetch url from flask
16-
1713
const url = document.getElementById("url")
1814
const theme = document.getElementById("theme");
1915
const user = document.getElementById("username");
2016

2117
function updateURL(){
2218
// find url and set style
23-
2419
var unique_url = `![](https://digest.gasinski.dev/svg/${user.value}?theme=${theme.value})`
25-
2620
// set to new text, prevents text s
2721
url.innerHTML = unique_url
2822
url.href = unique_url
@@ -33,3 +27,8 @@ let button = document.getElementById("submit");
3327
button.addEventListener("click", updateURL);
3428

3529
// update image on theme change
30+
theme.addEventListener("change", function() {
31+
// get img and update it to theme
32+
document.getElementById("example_img").setAttribute("src", `/static/img/${themes[theme.value]}`)
33+
34+
})

templates/index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ <h1> Leetcode Digest </h1>
2020
<option value="nord"> nord </option>
2121
<option value="dracula"> dracula </option>
2222
<option value="gruvbox"> gruvbox </option>
23-
<option value="base16"> base16 </option>
2423
<option value="one_dark"> one dark </option>
2524
<option value="monokai"> monokai </option>
2625
<option value="solarized_dark"> solarized dark </option>
@@ -37,8 +36,8 @@ <h1> Leetcode Digest </h1>
3736
<br><br>
3837
<br><br>
3938
<h4> Paste this into your <b>Github <a>README.md</a></b></h4>
40-
<div class="url" id="url" href="https://www.digest.gasinski.dev/svg/" >https://www.digest.gasinski.dev/svg/</div>
41-
<img alt="example of the panel" src="/static/img/example.png"/>
39+
<div class="url" id="url" href="![](https://www.digest.gasinski.dev/svg/)" >https://www.digest.gasinski.dev/svg/</div>
40+
<img id="example_img" alt="example of the panel" src="/static/img/nord.png"/>
4241
<div class="footer"> Made by <a href="https://gasinski.dev"> David Gasinski</a> </div>
4342
</div>
4443

themes.json

Whitespace-only changes.

0 commit comments

Comments
 (0)