-
Notifications
You must be signed in to change notification settings - Fork 0
/
mundial.py
103 lines (86 loc) · 5.34 KB
/
mundial.py
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
92
93
94
95
96
97
98
99
100
101
102
103
import altair as alt
from vega_datasets import data
import auxilio
# Paleta de Cor que eu achei que ficou melhor
cor=['#13A891','#F09001','#9653F5','#84F53B','#F52232','#FFE92F']
def bump_chart(source,col):
# Condicional
click = alt.selection_multi(fields=['location'])
# BUMP CHART
g1 = alt.Chart(source).mark_line(point = True).encode(
x = alt.X("date:O", timeUnit="yearmonth",axis=alt.Axis(labelAngle=-90,grid=True,domain=False,title=None,ticks=False,labels=False
,labelFont='Courier',labelFontSize=9)),
y=alt.Y("rank:O",axis = alt.Axis(domain=False,grid = True,ticks=False)),
color=alt.condition(click,alt.Color("location:N",legend=None,scale=alt.Scale(range=cor)),alt.value('lightgray')),
tooltip=[alt.Tooltip(f'{col}:Q'),alt.Tooltip('location:N'),'rank:O'],
opacity = alt.condition(click,alt.value(1),alt.value(0.3)),
).transform_window(
rank="rank()",
sort=[alt.SortField(f"{col}", order="descending")],
groupby=["date"]
).properties(
title=auxilio.titulo(col),
width=600,
height=150,
)
# Grafico de linha...
b1 = alt.Chart(source).mark_line(point = True).encode(
x = alt.X("date:O", timeUnit="yearmonth", title="date",axis=alt.Axis(orient='top',grid=True,domain=False,title=None,ticks=False,),),
y=alt.Y(f"{col}:Q",axis = alt.Axis(domain=False,grid =True,gridOpacity=0.5,ticks=False,orient='right',titleFont='Courier',
title=auxilio.titulo(col))),
color=alt.condition(click,alt.Color("location:N",legend=None,
scale=alt.Scale(range=cor)),alt.value('lightgray')),
opacity = alt.condition(click,alt.value(.9),alt.value(0.3)),
).transform_window(
rank="rank()",
sort=[alt.SortField(f"{col}", order="descending")],
groupby=["date"]
).properties(
width=600,
height=150,
)
# HEATMAP
rm1 =alt.Chart(
source,
).mark_rect().encode(
x=alt.X('date:O',timeUnit="yearmonth",axis=alt.Axis(domain=False,title=None,
ticks=False,orient='top',labelAngle=-90,labelFont='Courier',labelFontSize=9)),
y=alt.Y('location:N',axis = alt.Axis(domain=False,ticks=False,title=None,labelFont='Courier'),
scale=alt.Scale(domain=['Oceania','Africa','Asia','Europe','North America','South America'])),
color=alt.Color(f'{col}:Q', scale=alt.Scale(scheme="browns"),legend=alt.Legend(orient='right',title=None,)),
opacity = alt.condition(click,alt.value(.9),alt.value(0)),
).transform_window(
rank="rank()",
sort=[alt.SortField(col, order="descending")],
groupby=["date"]
).properties(width=600,height=150)
# Tooltip Heatmap
rm2 = rm1.encode(opacity=alt.value(0),tooltip=[alt.Tooltip(f'{col}:Q'),alt.Tooltip('location:N'),'rank:O']).transform_filter(click)
# conjunto tooltip + heatmap
rm3 = rm1.add_selection(click)+rm2
#legenda
legenda = alt.Chart(source).mark_rect(stroke='bisque',
cornerRadius=10,x=20).encode(y=alt.Y('location',axis=alt.Axis(domain = False,ticks=False,
orient='right',labelFont='Courier',
title=None)),
color=alt.condition(click,alt.Color('location:N',
scale=alt.Scale(range=cor)),alt.value('lightgray')
)).properties(width=20,
height=150,
).add_selection(click)
return ((alt.vconcat((g1).add_selection(click)|legenda,(b1+rm3) ,spacing=1))).configure_view(strokeWidth=0)
#return(((g1+g2)|legenda)&(b1+rm3))
def mapa_mundi(df1):
sphere = alt.sphere()
graticule = alt.graticule()
mar = alt.Chart(sphere).mark_geoshape(fill='black')#lightblue
linhas = alt.Chart(graticule).mark_geoshape(stroke='white', strokeWidth=0.2)
terra = alt.topo_feature(data.world_110m.url,
'countries')
fundo = alt.Chart(terra).mark_geoshape(stroke="black", strokeWidth=0.15,fill="white")
mapa = alt.Chart(terra).mark_geoshape(stroke="black", strokeWidth=0.15).transform_lookup(
lookup = 'id',from_=alt.LookupData(data=df1, key='id', fields=['new_cases','location','continent'])
).encode(
color = alt.Color('continent:N',scale=alt.Scale(domain=['Africa','Asia',"Europe","North America",'Oceania','South America'],range=cor),legend=None),)
mapa = (mar+linhas+fundo+mapa).properties(width=435, height=250).project(type='naturalEarth1').configure_view(strokeWidth=0)
return mapa