Turn donut chart into a bar chart

#1
Files changed (1) hide show
  1. app.py +30 -3
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
 
@@ -314,11 +341,11 @@ def main() -> None:
314
  outputs=[kpi_chart_annotations],
315
  )
316
 
317
- donut_languages = gr.Plot(label="Plot")
318
  demo.load(
319
- donut_chart_total,
320
  inputs=[],
321
- outputs=[donut_languages],
322
  )
323
 
324
  gr.Markdown(
 
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
 
 
341
  outputs=[kpi_chart_annotations],
342
  )
343
 
344
+ bar_languages = gr.Plot(label="Plot")
345
  demo.load(
346
+ bar_chart_total,
347
  inputs=[],
348
+ outputs=[bar_languages],
349
  )
350
 
351
  gr.Markdown(