3
3
import xml .etree .ElementTree as et
4
4
5
5
HEADERS = b"""<?xml version=\" 1.0\" standalone=\" no\" ?>
6
+ <?xml-stylesheet href="wheel.css" type="text/css"?>
6
7
<!DOCTYPE svg PUBLIC \" -//W3C//DTD SVG 1.1//EN\"
7
8
\" http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\" >
8
9
"""
9
10
10
- STYLES = """
11
- .success { stroke: #4CAE4C; stroke-width: 1; fill: #5CB85C; }
12
- .default { stroke: #cccccc; stroke-width: 1; fill: #ffffff; }
13
- """
14
-
15
11
PATH_TEMPLATE = """
16
12
M {start_outer_x},{start_outer_y}
17
13
A{outer_radius},{outer_radius} 0 0 1 {end_outer_x},{end_outer_y}
@@ -59,7 +55,7 @@ def add_annular_sectors(wheel, packages, total):
59
55
attrib = {"class" : result ["css_class" ]},
60
56
)
61
57
title = et .SubElement (sector , "title" )
62
- title .text = "{0} {1}" . format ( result [" name" ], result [" icon" ])
58
+ title .text = f" { result [' name' ] } { result [' icon' ] } "
63
59
64
60
65
61
def angles (index , total ):
@@ -78,11 +74,11 @@ def angles(index, total):
78
74
79
75
def add_fraction (wheel , packages , total ):
80
76
text_attributes = {
77
+ "class" : "wheel-text" ,
81
78
"text-anchor" : "middle" ,
82
79
"dominant-baseline" : "central" ,
83
80
"font-size" : str (2 * OFFSET ),
84
81
"font-family" : '"Helvetica Neue",Helvetica,Arial,sans-serif' ,
85
- "fill" : "#333333" ,
86
82
}
87
83
88
84
# Packages with some sort of wheel
@@ -95,10 +91,10 @@ def add_fraction(wheel, packages, total):
95
91
y = str (CENTER - OFFSET ),
96
92
attrib = text_attributes ,
97
93
)
98
- packages_with_wheels .text = "{0}" . format ( wheel_packages )
94
+ packages_with_wheels .text = f" { wheel_packages } "
99
95
100
96
title = et .SubElement (packages_with_wheels , "title" )
101
- percentage = "{:.0%}" . format ( wheel_packages / total )
97
+ percentage = f" { wheel_packages / float ( total ):.0% } "
102
98
title .text = percentage
103
99
104
100
# Dividing line
@@ -109,7 +105,7 @@ def add_fraction(wheel, packages, total):
109
105
y1 = str (CENTER ),
110
106
x2 = str (CENTER + FRACTION_LINE // 2 ),
111
107
y2 = str (CENTER ),
112
- attrib = {"stroke " : "#333333 " , "stroke-width" : "2" },
108
+ attrib = {"class " : "wheel-line " , "stroke-width" : "2" },
113
109
)
114
110
115
111
# Total packages
@@ -120,7 +116,7 @@ def add_fraction(wheel, packages, total):
120
116
y = str (CENTER + OFFSET ),
121
117
attrib = text_attributes ,
122
118
)
123
- total_packages .text = "{0}" . format ( total )
119
+ total_packages .text = f" { total } "
124
120
125
121
title = et .SubElement (total_packages , "title" )
126
122
title .text = percentage
@@ -129,13 +125,10 @@ def add_fraction(wheel, packages, total):
129
125
def generate_svg_wheel (packages , total ):
130
126
wheel = et .Element (
131
127
"svg" ,
132
- viewBox = "0 0 {0 } {0}" . format ( 2 * CENTER ) ,
128
+ viewBox = f "0 0 { 2 * CENTER } { 2 * CENTER } " ,
133
129
version = "1.1" ,
134
130
xmlns = "http://www.w3.org/2000/svg" ,
135
131
)
136
- style = et .SubElement (wheel , "style" , attrib = {"type" : "text/css" })
137
- style .text = STYLES
138
-
139
132
add_annular_sectors (wheel , packages , total )
140
133
141
134
add_fraction (wheel , packages , total )
0 commit comments