vgosavi2 commited on
Commit
3397ec7
·
verified ·
1 Parent(s): af0623e

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +24 -25
src/streamlit_app.py CHANGED
@@ -87,37 +87,36 @@ chart1 = (
87
  .properties(width=400, height=400, title="Top 10 Crime Types")
88
  )
89
  st.altair_chart(chart1, use_container_width=True)
90
- ###########################################################################
91
- # 1. Base pie chart
92
  base = (
93
  alt.Chart(top_crimes)
94
- .mark_arc(innerRadius=50)
95
- .encode(
96
- theta=alt.Theta("Count:Q"),
97
- color=alt.Color("Crime Type:N", legend=alt.Legend(title="Crime Type")),
98
- tooltip=[
99
- alt.Tooltip("Crime Type:N", title="Crime Type"),
100
- alt.Tooltip("Count:Q", title="Count"),
101
- alt.Tooltip("Percentage:Q", format=".1%")
102
- ]
103
- )
104
  )
105
 
106
- # 2. Add labels at mid-radius
107
  labels = (
108
  alt.Chart(top_crimes)
109
- .mark_text(radius=90, size=12, color="white")
110
- .encode(
111
- theta=alt.Theta("Count:Q"),
112
- text=alt.Text("Percentage:Q", format=".1%")
113
- )
114
  )
115
 
116
- # 3. Combine and set a fixed, small size
117
- pie = (base + labels).properties(width=300, height=300, title="Top 10 Crime Types")
 
 
 
118
 
119
- # 4. Center in the page using columns
120
- col1, col2, col3 = st.columns([1, 2, 1])
121
- with col2:
122
- st.altair_chart(pie, use_container_width=False)
123
-
 
87
  .properties(width=400, height=400, title="Top 10 Crime Types")
88
  )
89
  st.altair_chart(chart1, use_container_width=True)
90
+
91
+ # Base pie chart (innerRadius=50 gives us the donut)
92
  base = (
93
  alt.Chart(top_crimes)
94
+ .mark_arc(innerRadius=50)
95
+ .encode(
96
+ theta=alt.Theta("Count:Q"),
97
+ color=alt.Color("Crime Type:N", legend=alt.Legend(title="Crime Type")),
98
+ tooltip=[
99
+ alt.Tooltip("Crime Type:N"),
100
+ alt.Tooltip("Count:Q"),
101
+ alt.Tooltip("Percentage:Q", format=".1%")
102
+ ]
103
+ )
104
  )
105
 
106
+ # Add labels *outside* each slice by using a larger radius
107
  labels = (
108
  alt.Chart(top_crimes)
109
+ .mark_text(radius=120, size=11, fontWeight="bold")
110
+ .encode(
111
+ theta=alt.Theta("Count:Q"),
112
+ text=alt.Text("Crime Type:N")
113
+ )
114
  )
115
 
116
+ # Combine and set size/title
117
+ chart2 = (
118
+ (base + labels)
119
+ .properties(width=600, height=600, title="Top 10 Crime Types")
120
+ )
121
 
122
+ st.altair_chart(chart2, use_container_width=False)