-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.py
More file actions
91 lines (75 loc) · 3.02 KB
/
Copy pathfunction.py
File metadata and controls
91 lines (75 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import streamlit as st
import pandas as pd
import altair as alt
import plotly.express as px
import time
def abbreviate_number(num):
try:
num = int(num)
if abs(num) < 1000:
return str(num)
elif abs(num) < 1000000:
return f"{num / 1000:.1f}K"
elif abs(num) < 1000000000:
return f"{num / 1000000:.1f}M"
elif abs(num) < 1000000000000:
return f"{num / 1000000000:.1f}B"
else:
return f"{num / 1000000000000:.1f}T"
except:
return num
def make_donut(input_response, input_text, input_color=None):
if input_color is None:
input_color = 'blue' if input_response >= 0 else 'red'
if input_color == 'blue':
chart_color = ['#29b5e8', '#155F7A']
elif input_color == 'green':
chart_color = ['#27AE60', '#12783D']
elif input_color == 'orange':
chart_color = ['#F39C12', '#875A12']
elif input_color == 'red':
chart_color = ['#E74C3C', '#781F16']
source = pd.DataFrame({
"Topic": ['', input_text],
"% value": [100 - input_response, input_response]
})
source_bg = pd.DataFrame({
"Topic": ['', input_text],
"% value": [100, 0]
})
plot = alt.Chart(source).mark_arc(innerRadius=45, cornerRadius=25).encode(
theta="% value",
color=alt.Color("Topic:N",
scale=alt.Scale(
domain=[input_text, ''],
range=chart_color),
legend=None),
).properties(width=130, height=130)
text = plot.mark_text(align='center', color=chart_color[0], font="Lato", fontSize=10, fontWeight=100, fontStyle="italic").encode(text=alt.value(f'{input_response} %'))
plot_bg = alt.Chart(source_bg).mark_arc(innerRadius=45, cornerRadius=20).encode(
theta="% value",
color=alt.Color("Topic:N",
scale=alt.Scale(
domain=[input_text, ''],
range=chart_color),
legend=None),
).properties(width=130, height=130)
return plot_bg + plot + text
def write_stream_text(text, sped=0.02):
for word in text.split(" "):
yield word + " "
time.sleep(sped)
def make_heatmap(input_df, input_y, input_x, input_color, input_color_theme):
heatmap = alt.Chart(input_df, width=200).mark_rect().encode(
y=alt.Y(f'{input_y}:O', axis=alt.Axis(title="Year", titleFontSize=18, titlePadding=15, titleFontWeight=900, labelAngle=0)),
x=alt.X(f'{input_x}:O', axis=alt.Axis(title="", titleFontSize=18, titlePadding=15, titleFontWeight=900)),
color=alt.Color(f'max({input_color}):Q',
legend=None,
scale=alt.Scale(scheme=input_color_theme)),
stroke=alt.value('black'),
strokeWidth=alt.value(0.25),
).properties(width=300
).configure_axis(
labelFontSize=12,
titleFontSize=12)
return heatmap