-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_svg.py
More file actions
28 lines (26 loc) · 1.22 KB
/
test_svg.py
File metadata and controls
28 lines (26 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def generate_shield(label, value, color, style):
label_width = len(label) * 8 + 10
value_width = len(str(value)) * 8 + 10
total_width = label_width + value_width
svg = f"""<svg xmlns="http://www.w3.org/2000/svg" width="{total_width}" height="20">
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<mask id="a">
<rect width="{total_width}" height="20" rx="3" fill="#fff"/>
</mask>
<g mask="url(#a)">
<rect width="{label_width}" height="20" fill="#555"/>
<rect x="{label_width}" width="{value_width}" height="20" fill="#{color}"/>
<rect width="{total_width}" height="20" fill="url(#b)"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<text x="{label_width/2}" y="15" fill="#010101" fill-opacity=".3">{label}</text>
<text x="{label_width/2}" y="14">{label}</text>
<text x="{label_width + value_width/2}" y="15" fill="#010101" fill-opacity=".3">{value}</text>
<text x="{label_width + value_width/2}" y="14">{value}</text>
</g>
</svg>"""
return svg
print(generate_shield("visits", "1000", "e05d44", "flat"))