Skip to content

Commit

Permalink
Update viz to work with new verison of makie
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiahpslewis committed Dec 17, 2024
1 parent 69a4bd1 commit 264d2e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 40 deletions.
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Memoization = "6fafb56a-5788-4b4e-91ca-c0cea6611c73"
Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
NaturalEarth = "436b0209-26ab-4e65-94a9-6526d86fea76"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Retry = "20febd7b-183b-5ae2-ac4a-720e7ce64774"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
Expand All @@ -38,9 +39,9 @@ oxigraph_server_jll = "ca7c0f55-ad95-5972-a3e2-8e5b4e3bed80"
AlgebraOfGraphics = "0.8"
Arrow = "2"
CSV = "0.10"
CairoMakie = "0.13"
CairoMakie = "0.12"
Chain = "0.6"
Colors = "0.13"
Colors = "0.12, 0.13"
DataFrameMacros = "0.4"
DataFrames = "1"
DelimitedFiles = "1"
Expand All @@ -54,6 +55,7 @@ JuliaFormatter = "1"
Makie = "0.21"
Memoization = "0.2"
Mustache = "1"
NaturalEarth = "0.1.0"
OrderedCollections = "1"
Retry = "0.4"
Setfield = "1"
Expand Down
57 changes: 19 additions & 38 deletions src/exploration/visualizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ using DataFrameMacros
using DataFrames
using Dates
using Downloads
using GeoJSON
using GeoMakie
using GeoMakie
using GeoMakie.GeoJSON
Expand All @@ -16,6 +15,7 @@ using JSON
using Statistics
using URIParser
using OrderedCollections
using NaturalEarth

trr_266_colors = ["#1b8a8f", "#ffb43b", "#6ecae2", "#944664"] # petrol, yellow, blue, red

Expand All @@ -26,27 +26,14 @@ function get_esef_mandate_df()
end

function generate_esef_basemap()
url = "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/"
country = Downloads.download(url * "ne_50m_admin_0_countries.geojson")
country_json = JSON.parse(read(country, String))

tiny_country = Downloads.download(url * "ne_50m_admin_0_tiny_countries.geojson")
tiny_country_json = JSON.parse(read(tiny_country, String))
country_geo = DataFrame(naturalearth("admin_0_countries", 50))
tiny_country_geo = DataFrame(naturalearth("admin_0_countries", 10))

mandate_df = get_esef_mandate_df()

malta = [
c for c in tiny_country_json["features"] if c["properties"]["ADMIN"] == "Malta"
]
europe = [
c for c in country_json["features"] if
(c["properties"]["ADMIN"] mandate_df[!, :Country]) &
(c["properties"]["ADMIN"] != "Malta")
]
country_json["features"] = [malta..., europe...]

country_geo = GeoJSON.read(JSON.json(country_json))
return country_geo
mandate_countries = mandate_df[!, :Country]
malta = @chain tiny_country_geo @subset(:ADMIN == "Malta")
europe = @chain country_geo @subset((:ADMIN mandate_countries) & (:ADMIN != "Malta"))
return vcat(malta, europe)
end

function generate_esef_report_map(; is_poster=false)
Expand All @@ -61,43 +48,37 @@ function generate_esef_report_map(; is_poster=false)
dest = "+proj=laea"
source = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"

fig = Figure(; resolution=(1000, 500))
fig = Figure(; size=(1000, 500), backgroundcolor=background_color)
gd = fig[1, 1] = GridLayout()

ga = GeoAxis(
gd[1, 1];
source=source,
dest=dest,
lonlims=(-28, 35),
latlims=(35, 72),
title="ESEF Reports Availability by Country",
subtitle="(XBRL Repository)",
backgroundcolor=background_color,
)

eu_geojson = generate_esef_basemap()
ga.limits[] = (-28, 35, 35, 72)
eu_geo = generate_esef_basemap()
df, df_error = get_esef_xbrl_filings()
country_rollup = calculate_country_rollup(df)

report_count_vect = map(eu_geojson) do geo
report_count = (@chain country_rollup @subset(:countryLabel == geo.ADMIN) @select(
:report_count
))
nrow(report_count) > 0 ? report_count[1, 1] : 0
end
eu_geo = leftjoin(eu_geo, country_rollup, on=(:ADMIN => :countryLabel))
replace!(eu_geo.report_count, missing => 0)

max_reports = maximum(country_rollup[!, :report_count])
color_scale_ = range(
parse(Colorant, "#ffffff"), parse(Colorant, trr_266_colors[2]), max_reports + 1
)
# NOTE: Work around for `ERROR: MethodError: no method matching MultiPolygon(::Point{2, Float32})`
for (c, report_count) in zip(eu_geojson, report_count_vect)
for row in eachrow(eu_geo)
poly!(
ga,
GeoMakie.geo2basic(c);
row[:geometry];
strokecolor=RGBf(0.90, 0.90, 0.90),
strokewidth=1,
color=color_scale_[report_count + 1],
color=row[:report_count],
colorrange=(0, max_reports),
colormap=color_scale_,
label="test",
)
end
Expand All @@ -111,7 +92,7 @@ function generate_esef_report_map(; is_poster=false)
)

hidedecorations!(ga)
hidespines!(ga)
# hidespines!(ga)
colgap!(gd, 1)
rowgap!(gd, 1)

Expand All @@ -128,7 +109,7 @@ function generate_esef_mandate_map()
dest = "+proj=laea"
source = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"

fig = Figure(; resolution=(1000, 500))
fig = Figure(; size=(1000, 500))
gd = fig[1, 1] = GridLayout()

ga = GeoAxis(
Expand Down

0 comments on commit 264d2e8

Please sign in to comment.