-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work on polling objects and rearrangement of text
- Loading branch information
1 parent
6366803
commit 89e0980
Showing
43 changed files
with
1,877 additions
and
138 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
state_polls = Dict( | ||
"PA" => [Poll(0.40, 0.46, 1305), Poll(0.45, 0.45, 807), Poll(0.56, 0.46, 520)], | ||
"MI" => [Poll(0.41, 0.45, 1218), Poll(0.45, 0.45, 778), Poll(0.56, 0.46, 1097)], | ||
"GA" => [Poll(0.43, 0.44, 788), Poll(0.48, 0.51, 1133), Poll(0.42, 0.46, 520)], | ||
"NC" => [Poll(0.43, 0.49, 699), Poll(0.42, 0.45, 829), Poll(0.48, 0.51, 1295)], | ||
"AZ" => [Poll(0.43, 0.48, 796), Poll(0.43, 0.47, 1000), Poll(0.45, 0.50, 600)], | ||
"WI" => [Poll(0.46, 0.45, 697), Poll(0.44, 0.46, 1000), Poll(0.45, 0.46, 600)], | ||
"NV" => [Poll(0.44, 0.46, 447), Poll(0.49, 0.51, 1000), Poll(0.48, 0.44, 600)] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using PlotlyJS | ||
|
||
const STATES = ["NV", "WI", "AZ", "GA", "MI", "PA", "NC"] | ||
|
||
const VOTES = [6, 10, 11, 16, 15, 19, 16] | ||
|
||
const TIED = 269 | ||
|
||
const FLAGRED = "rgb(178, 34, 52)" | ||
|
||
const FLAGBLUE = "rgb(60, 59, 110)" | ||
|
||
const PURPLE = "rgb(119, 47, 81)" | ||
|
||
const GREENBAR = "rgb(47, 119, 78)" | ||
|
||
const STATE_COLORS = Dict( | ||
"PA" => FLAGRED, | ||
"NC" => FLAGRED, | ||
"NV" => PURPLE, | ||
"MI" => PURPLE, | ||
"WI" => PURPLE, | ||
"AZ" => PURPLE, | ||
"GA" => PURPLE | ||
) | ||
|
||
votes = Dict( | ||
"NV" => 6, | ||
"MI" => 15, | ||
"WI" => 10, | ||
"NC" => 16, | ||
"AZ" => 11, | ||
"PA" => 19, | ||
"GA" => 16 | ||
) | ||
|
||
data = [votes[state] for state in STATES] | ||
|
||
function electoral_map_with_colors(data, state_colors) | ||
# Create the data for the choropleth map | ||
choropleth_trace = PlotlyJS.choropleth( | ||
locationmode="USA-states", | ||
locations=STATES, | ||
z=data, | ||
colorscale=[[0, "rgba(0,0,0,0)"], [1, "rgba(0,0,0,0)"]], | ||
showscale=false, | ||
marker=attr(line=attr(color="white", width=2)), | ||
hoverinfo="location+text" | ||
) | ||
|
||
# Create the data for the state colors | ||
color_traces = [ | ||
PlotlyJS.choropleth( | ||
locationmode="USA-states", | ||
locations=[state], | ||
z=[1], | ||
colorscale=[[0, color], [1, color]], | ||
showscale=false, | ||
marker=attr(line=attr(color="white", width=2)), | ||
hoverinfo="none" | ||
) | ||
for (state, color) in state_colors | ||
] | ||
|
||
# Create the data for the state labels | ||
label_trace = PlotlyJS.scattergeo( | ||
locationmode="USA-states", | ||
locations=STATES, | ||
text=data, | ||
textfont=attr(size=12, color="white"), | ||
mode="text", | ||
showlegend=false, | ||
hoverinfo="none" | ||
) | ||
|
||
# Create the layout for the map | ||
layout = PlotlyJS.Layout( | ||
title= "Without PA & NC: 58 Swing State Electoral Votes (45 required to win)", | ||
geo=attr( | ||
scope="usa", | ||
projection=attr(type="albers usa"), | ||
showlakes=true, | ||
lakecolor="rgb(255, 255, 255)" | ||
) | ||
) | ||
|
||
# Create the figure with all traces | ||
fig = PlotlyJS.plot(vcat(choropleth_trace, color_traces..., label_trace), layout) | ||
|
||
# Save the plot as an image file | ||
PlotlyJS.savefig(fig, "/Users/ro/projects/SwingWatch/_assets/img/maps/no_pa_nc.png") | ||
end | ||
|
||
electoral_map_with_colors(data, STATE_COLORS) |
Oops, something went wrong.