lunadebruyne commited on
Commit
49443a1
·
1 Parent(s): 7251537

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -5
app.py CHANGED
@@ -178,12 +178,29 @@ def dist_colors(output_file, input_checks):
178
  range_ = ['#999999', '#b22222', '#663399', '#ffcc00', '#db7093', '#6495ed']
179
  n = max(data['Frequency'])
180
 
181
- plot = alt.Chart(data, title="Emotion distribution over time").mark_line().encode(
182
- x="Date",
 
 
 
 
183
  y=alt.Y("Frequency", scale=alt.Scale(domain=[0, (n + 9) // 10 * 10])),
184
- color=alt.Color("Emotion category", scale=alt.Scale(domain=domain, range=range_)),
185
- tooltip=['Date', 'Frequency', 'Emotion category']).properties(
186
- width=350).interactive()
 
 
 
 
 
 
 
 
 
 
 
 
 
187
 
188
  if "peaks" in input_checks:
189
  return gr.update(value=plot, visible=True), gr.update(visible=True), gr.update(visible=False) # next_button_peaks becomes available
 
178
  range_ = ['#999999', '#b22222', '#663399', '#ffcc00', '#db7093', '#6495ed']
179
  n = max(data['Frequency'])
180
 
181
+ highlight = alt.selection(
182
+ type='single', on='mouseover', fields=["Emotion category"], nearest=True)
183
+
184
+
185
+ base = alt.Chart(data).encode(
186
+ x ="Date",
187
  y=alt.Y("Frequency", scale=alt.Scale(domain=[0, (n + 9) // 10 * 10])),
188
+ color=alt.Color("Emotion category", scale=alt.Scale(domain=domain, range=range_)))
189
+
190
+
191
+ points = base.mark_circle().encode(
192
+ opacity=alt.value(0),
193
+ tooltip=[
194
+ alt.Tooltip('Emotion category', title='Emotion category'),
195
+ alt.Tooltip('Date', title='Date'),
196
+ alt.Tooltip('Frequency', title='Frequency')
197
+ ]).add_selection(highlight)
198
+
199
+
200
+ lines = base.mark_line().encode(
201
+ size=alt.condition(~highlight, alt.value(1), alt.value(3)))
202
+
203
+ plot = (points + lines).properties(width=600, height=350).interactive()
204
 
205
  if "peaks" in input_checks:
206
  return gr.update(value=plot, visible=True), gr.update(visible=True), gr.update(visible=False) # next_button_peaks becomes available