dvilasuero HF staff commited on
Commit
78802f4
β€’
1 Parent(s): c9fdcf2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -62,7 +62,6 @@ def get_user_annotations_dictionary(
62
 
63
  return output
64
 
65
-
66
  def donut_chart2() -> alt.Chart:
67
  # Load your data
68
  source_dataset, results = obtain_source_target_datasets()
@@ -79,16 +78,28 @@ def donut_chart2() -> alt.Chart:
79
  # Base chart for donut segments
80
  base = alt.Chart(source).encode(
81
  theta=alt.Theta(field="values", type="quantitative", stack=True), # The angle encoding
82
- color=alt.Color(field="colors", type="nominal", legend=alt.Legend(title="Category"), scale=None), # Direct color specification
83
  tooltip=['category', 'values'] # Tooltips for interactivity
84
  )
85
 
86
  # Arc marks for donut segments
87
  arcs = base.mark_arc(innerRadius=100, outerRadius=150, stroke="#fff") # Increased inner radius for a thicker donut
88
 
89
- # Text marks for labels, adjusted to be placed within the donut segments
90
- text = base.mark_text(radiusOffset=-70, size=16, color='white').encode(
91
- text=alt.Text(field="values", type="quantitative"), # The text to display
 
 
 
 
 
 
 
 
 
 
 
 
92
  )
93
 
94
  # Combine the arcs and text
@@ -98,14 +109,11 @@ def donut_chart2() -> alt.Chart:
98
  chart = chart.configure_view(
99
  strokeWidth=0, # Remove border around chart
100
  fill=None # Ensure background is transparent
101
- ).configure_axis(
102
- grid=False # Turn off the grid
103
  )
104
 
105
  return chart
106
 
107
 
108
-
109
  def donut_chart() -> alt.Chart:
110
  # Load your data
111
  source_dataset, results = obtain_source_target_datasets()
 
62
 
63
  return output
64
 
 
65
  def donut_chart2() -> alt.Chart:
66
  # Load your data
67
  source_dataset, results = obtain_source_target_datasets()
 
78
  # Base chart for donut segments
79
  base = alt.Chart(source).encode(
80
  theta=alt.Theta(field="values", type="quantitative", stack=True), # The angle encoding
81
+ color=alt.Color(field="colors", type="nominal", legend=None), # Direct color specification
82
  tooltip=['category', 'values'] # Tooltips for interactivity
83
  )
84
 
85
  # Arc marks for donut segments
86
  arcs = base.mark_arc(innerRadius=100, outerRadius=150, stroke="#fff") # Increased inner radius for a thicker donut
87
 
88
+ # Calculate the midpoints of the arc segments for label placement
89
+ text_df = pd.DataFrame({
90
+ 'start_angle': [0],
91
+ 'end_angle': [360 * annotated_records / (annotated_records + pending_records)]
92
+ })
93
+ text_df = text_df.append({
94
+ 'start_angle': text_df.iloc[0]['end_angle'],
95
+ 'end_angle': 360
96
+ }, ignore_index=True)
97
+ text_df['mid_angle'] = (text_df['start_angle'] + text_df['end_angle']) / 2
98
+
99
+ # Create labels based on the mid_angle for better placement
100
+ text = alt.Chart(text_df).mark_text(radius=120, size=20, color='black').encode(
101
+ text=alt.Text('mid_angle:O', format='.1f'),
102
+ angle=alt.Angle('mid_angle:Q')
103
  )
104
 
105
  # Combine the arcs and text
 
109
  chart = chart.configure_view(
110
  strokeWidth=0, # Remove border around chart
111
  fill=None # Ensure background is transparent
 
 
112
  )
113
 
114
  return chart
115
 
116
 
 
117
  def donut_chart() -> alt.Chart:
118
  # Load your data
119
  source_dataset, results = obtain_source_target_datasets()