Rijgersberg commited on
Commit
931fbf4
β€’
1 Parent(s): d648181

Turn donut chart into a bar chart

Browse files

I think a bar chart shows the progress towards the goal better.

I wasn't able to test the char in the context of the full dashboard, but this should be about right.

Files changed (1) hide show
  1. app.py +28 -1
app.py CHANGED
@@ -269,7 +269,34 @@ def donut_chart_total() -> alt.Chart:
269
 
270
  return chart
271
 
 
 
272
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
 
274
  def main() -> None:
275
 
@@ -316,7 +343,7 @@ def main() -> None:
316
 
317
  donut_languages = gr.Plot(label="Plot")
318
  demo.load(
319
- donut_chart_total,
320
  inputs=[],
321
  outputs=[donut_languages],
322
  )
 
269
 
270
  return chart
271
 
272
+ def bar_chart_total() -> alt.Chart:
273
+ """A bar chart with the progress of the total annotations in each language.
274
 
275
+ Returns:
276
+ An altair chart with the bar chart.
277
+ """
278
+ # Load your data
279
+ annotated_records = [annotation for annotation in annotations.values()]
280
+ languages = [language.capitalize() for language in annotations.keys()]
281
+
282
+ # Prepare data for the bar chart
283
+ source = pd.DataFrame(
284
+ {
285
+ "values": annotated_records,
286
+ "category": languages,
287
+ }
288
+ )
289
+
290
+ base = alt.Chart(source, width=300, height=200).encode(
291
+ x=alt.X('values:Q', title='Translations'),
292
+ y=alt.Y('category:N', title='Language'),
293
+ text='values:Q',
294
+ color=alt.Color('category:N', legend=None)
295
+ )
296
+
297
+ rule = alt.Chart(source).mark_rule(color='red').encode(x=alt.datum(500))
298
+
299
+ return base.mark_bar() + base.mark_text(align='left', dx=2) + rule
300
 
301
  def main() -> None:
302
 
 
343
 
344
  donut_languages = gr.Plot(label="Plot")
345
  demo.load(
346
+ bar_chart_total,
347
  inputs=[],
348
  outputs=[donut_languages],
349
  )