Spaces:
Runtime error
Runtime error
Commit
β’
c9fdcf2
1
Parent(s):
bead680
Update app.py
Browse files
app.py
CHANGED
@@ -104,9 +104,7 @@ def donut_chart2() -> alt.Chart:
|
|
104 |
|
105 |
return chart
|
106 |
|
107 |
-
|
108 |
-
import pandas as pd
|
109 |
-
import os
|
110 |
|
111 |
def donut_chart() -> alt.Chart:
|
112 |
# Load your data
|
@@ -121,41 +119,19 @@ def donut_chart() -> alt.Chart:
|
|
121 |
"colors": ["#4CAF50", "#757575"] # Green for Completed, Grey for Remaining
|
122 |
})
|
123 |
|
124 |
-
# Base chart for donut segments
|
125 |
base = alt.Chart(source).encode(
|
126 |
-
theta=alt.Theta(
|
127 |
-
|
128 |
-
|
|
|
|
|
129 |
)
|
130 |
|
131 |
-
|
132 |
-
arcs = base.mark_arc(innerRadius=100, outerRadius=150, stroke="#fff") # Increased inner radius for a thicker donut
|
133 |
|
134 |
-
|
135 |
-
text_df = pd.DataFrame({
|
136 |
-
'start_angle': [0],
|
137 |
-
'end_angle': [360 * annotated_records / (annotated_records + pending_records)]
|
138 |
-
})
|
139 |
-
text_df = text_df.append({
|
140 |
-
'start_angle': text_df.iloc[0]['end_angle'],
|
141 |
-
'end_angle': 360
|
142 |
-
}, ignore_index=True)
|
143 |
-
text_df['mid_angle'] = (text_df['start_angle'] + text_df['end_angle']) / 2
|
144 |
-
|
145 |
-
# Create labels based on the mid_angle for better placement
|
146 |
-
text = alt.Chart(text_df).mark_text(radius=120, size=20, color='black').encode(
|
147 |
-
text=alt.Text('mid_angle:O', format='.1f'),
|
148 |
-
angle=alt.Angle('mid_angle:Q')
|
149 |
-
)
|
150 |
|
151 |
-
|
152 |
-
chart = arcs + text
|
153 |
-
|
154 |
-
# Configure the view to have a transparent background
|
155 |
-
chart = chart.configure_view(
|
156 |
-
strokeWidth=0, # Remove border around chart
|
157 |
-
fill=None # Ensure background is transparent
|
158 |
-
)
|
159 |
|
160 |
return chart
|
161 |
|
|
|
104 |
|
105 |
return chart
|
106 |
|
107 |
+
|
|
|
|
|
108 |
|
109 |
def donut_chart() -> alt.Chart:
|
110 |
# Load your data
|
|
|
119 |
"colors": ["#4CAF50", "#757575"] # Green for Completed, Grey for Remaining
|
120 |
})
|
121 |
|
|
|
122 |
base = alt.Chart(source).encode(
|
123 |
+
theta=alt.Theta("values:Q", stack=True),
|
124 |
+
radius=alt.Radius(
|
125 |
+
"values", scale=alt.Scale(type="sqrt", zero=True, rangeMin=20)
|
126 |
+
),
|
127 |
+
color=alt.Color("category:N", legend=alt.Legend(title="Category")),
|
128 |
)
|
129 |
|
130 |
+
c1 = base.mark_arc(innerRadius=20, stroke="#fff")
|
|
|
131 |
|
132 |
+
c2 = base.mark_text(radiusOffset=10).encode(text="values:Q")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
+
chart = c1 + c2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
return chart
|
137 |
|