{"spec_id":"map-connection-lines","library":"makie","language":"julia","code":"# anyplot.ai\n# map-connection-lines: Connection Lines Map (Origin-Destination)\n# Library: makie 0.24.16 | Julia 1.13.4\n# Quality: 85/100 | Updated: 2026-11-27\n\nusing CairoMakie\nusing Colors\nusing Random\n\nRandom.seed!(42)\n\n# Theme tokens\nconst THEME       = get(ENV, \"ANYPLOT_THEME\", \"light\")\nconst PAGE_BG     = THEME == \"light\" ? colorant\"#FAF8F1\" : colorant\"#1A1A17\"\nconst INK         = THEME == \"light\" ? colorant\"#1A1A17\" : colorant\"#F0EFE8\"\nconst INK_SOFT    = THEME == \"light\" ? colorant\"#4A4A44\" : colorant\"#B8B7B0\"\nconst INK_MUTED   = THEME == \"light\" ? colorant\"#6B6A63\" : colorant\"#A8A79F\"\n\n# Land and coastline colors (theme-adaptive)\nconst LAND_FILL   = THEME == \"light\" ?\n    RGBAf(0.87f0, 0.85f0, 0.80f0, 1.0f0) :\n    RGBAf(0.24f0, 0.24f0, 0.22f0, 1.0f0)\nconst COAST_COLOR = THEME == \"light\" ?\n    RGBAf(0.58f0, 0.56f0, 0.52f0, 1.0f0) :\n    RGBAf(0.40f0, 0.40f0, 0.37f0, 1.0f0)\n\nconst GRAT_ALPHA  = THEME == \"light\" ? 0.08f0 : 0.13f0\nconst GRAT_COLOR  = THEME == \"light\" ?\n    RGBAf(26f0/255f0, 26f0/255f0, 23f0/255f0, GRAT_ALPHA) :\n    RGBAf(240f0/255f0, 239f0/255f0, 232f0/255f0, GRAT_ALPHA)\n\n# Imprint sequential ramp, marks stops (colored lines on the page), per theme\nconst IMPRINT_SEQ_MARKS = THEME == \"light\" ?\n    cgrad([colorant\"#009E73\", colorant\"#024582\", colorant\"#351E45\"], [0.0, 0.687, 1.0]) :\n    cgrad([colorant\"#6F7E20\", colorant\"#009E73\", colorant\"#CDD9FF\"], [0.0, 0.21, 1.0])\n\n# Airport data: (name, lat, lon)\nconst airport_names = [\n    \"London\", \"New York\", \"Dubai\", \"Singapore\",\n    \"Tokyo\", \"Sydney\", \"Paris\", \"Los Angeles\",\n    \"Hong Kong\", \"Frankfurt\",\n]\nconst airport_lats = Float64[\n     51.5,  40.7,  25.2,   1.4,\n     35.7, -33.9,  48.9,  34.1,\n     22.3,  50.0,\n]\nconst airport_lons = Float64[\n     -0.1, -74.0,  55.4, 103.8,\n    139.7, 151.2,   2.4, -118.2,\n    114.2,   8.6,\n]\n\n# Connections: (origin_idx, dest_idx, annual_passengers_millions, both directions)\nconst connections = [\n    (1, 2, 3.4), (1, 3, 2.0), (1, 9, 1.0), (1, 4, 1.4),\n    (2, 8, 3.0), (2, 7, 1.9), (3, 9, 0.9), (3, 4, 1.1),\n    (9, 4, 2.0), (4, 5, 1.2), (4, 6, 1.5), (5, 9, 2.4),\n    (5, 8, 1.0), (7, 3, 1.2), (10, 2, 1.6),\n]\n\nconst volumes = Float64[c[3] for c in connections]\nconst vmin = minimum(volumes)\nconst vmax = maximum(volumes)\n\n# Hand-digitised land outlines as (lon, lat) vertices: continents, major islands and\n# the inland seas that cut into them, so the shorelines follow the real coasts.\n# poly! auto-closes each polygon (last point connects back to first).\nconst _LAND_RAW = [\n    # North America\n    [(-168,65.5),(-165,68.5),(-156,71.3),(-141,69.7),(-128,70),(-115,68),(-95,68),(-95,72),\n     (-88,68),(-82,69),(-82,66),(-90,64),(-94,61),(-93,58.5),(-85,55.5),(-82,52.5),(-79,51.5),\n     (-79,55),(-77,60),(-72,62),(-65,60.5),(-61.5,56),(-56,52),(-64,50),(-60,47),(-64,45),\n     (-66,44.5),(-70,43.5),(-70,41.7),(-74,40.5),(-76,37),(-75.5,35.2),(-81,31.5),(-80,27),\n     (-80.5,25.2),(-82,26.5),(-82.8,29.5),(-85,29.7),(-89,30.2),(-91,29.3),(-94,29.5),\n     (-97.2,27.5),(-97.5,22),(-95,18.5),(-91,18.7),(-90.5,21),(-87,21.5),(-88,16),(-84,15.5),\n     (-83.5,11),(-81.5,8.8),(-79,9.4),(-77.3,8.6),(-80,7.3),(-83,8.3),(-86,11),(-90,13.5),\n     (-94.5,16),(-97,15.8),(-105.5,20),(-105.5,23),(-109,26),(-112.5,30),(-114.8,31.7),\n     (-114.5,30),(-112,26.5),(-109.5,23),(-112,24.7),(-114.5,28),(-115.5,30),(-117,32.5),\n     (-120.5,34.5),(-122.5,37.5),(-124,40.5),(-124.5,43),(-124,46.5),(-123,48.5),(-127,51),\n     (-130.5,54.5),(-134,57),(-138,59),(-146,60.7),(-152,59.3),(-154,57),(-158,56),\n     (-163,54.8),(-157.5,58.5),(-162,59.5),(-165,61),(-165,64),(-161.5,64.5)],\n    # South America\n    [(-77.3,8.6),(-75.5,10.8),(-71.5,12),(-68,10.6),(-62,10.7),(-60,8.5),(-57,6),(-52,5),\n     (-50,1.5),(-50,0),(-44,-2.5),(-39,-3.5),(-35,-5.5),(-35,-9),(-39,-13.5),(-39,-18),\n     (-41,-22),(-44,-23),(-48,-26),(-48.7,-28.5),(-52,-32),(-54,-34.5),(-57,-35),(-58,-38),\n     (-62,-39),(-65,-41),(-63.5,-42.5),(-65.5,-45),(-67.5,-46.5),(-66,-48),(-69,-51),\n     (-68.5,-52.5),(-65,-55),(-72,-54),(-75,-50),(-74,-45),(-73.5,-40),(-71.5,-32),\n     (-71.5,-28),(-70,-18),(-76,-14),(-79,-8),(-81,-5),(-80,-2),(-80,1),(-78,2.5),(-77.5,6)],\n    # Eurasia (Iberia, Italy, Greece, Anatolia, Arabia, India and Southeast Asia included)\n    [(-9,37),(-9,43),(-2,43.5),(-1,46),(-4.5,48.5),(2,51),(5,53),(8,54),(8.5,57),(10.5,57.5),\n     (10,54.5),(14,54),(19,54.5),(21,57),(24,57.5),(24,59.5),(30,60),(23,60),(21.5,63),\n     (25,65.5),(22,65.8),(17.5,62),(19,60),(16.5,57),(13,55.5),(11,59),(8,58),(5,59),(5,62),\n     (14,67),(20,70),(28,71),(40,67),(44,68),(60,69),(70,73),(80,73),(100,77),(113,74),\n     (130,71),(150,71),(170,70),(180,68),(180,65),(178,64.5),(170,60),(163,60),(163,56),\n     (156,51),(156,57),(160,61),(155,59),(143,59),(135,55),(141,53),(140,48),(135,43),\n     (130,42),(129,36),(126,35),(126,38),(125,40),(122,40),(118,39),(122,37),(119,35),\n     (122,31),(121,28),(117,23.5),(110,21),(108,21.5),(106,19),(109,12),(105,9),(103,10.5),\n     (100,13),(99,9),(101,6.5),(103.5,1.5),(100.5,3.5),(98,8),(98.5,16),(94,18),(92,22),\n     (90,22),(87,21),(80,15.5),(80,10),(77.5,8),(76,11),(73,17),(72.8,21),(70,21),(67,24.5),\n     (62,25),(57,25.5),(56.5,27),(54,26.7),(51,28),(48.5,30),(48,29.5),(50,26.5),(51.5,24.5),\n     (54,24.2),(56,26),(56.5,24.5),(59.5,22.5),(58.5,20),(55,17),(52,16),(45,12.8),(43,13),\n     (42.5,16),(39,21.5),(35,28),(34.5,29.5),(34.2,31.2),(35,33),(36,36),(32,36.5),(29,36.5),\n     (27,37),(26.5,40),(24,40.5),(23,40),(23,38),(22,37),(21,38),(19.5,40.5),(19,42),(15,45),\n     (12.5,45.5),(13.5,43.5),(16,41.5),(18.5,40),(16,38),(15.7,40),(12,42),(10,44),(7,43.5),\n     (3,43.2),(3,42),(0,39.5),(-1,37.5),(-5,36)],\n    # Africa\n    [(-17,21),(-13,27.5),(-9.5,30),(-6,35.8),(-2,35),(3,36.8),(10,37.3),(11,35),(10,34),\n     (15,32.3),(20,30.3),(20,32),(25,31.7),(32,31.2),(34,30.5),(35,24),(37.5,18),(39,15.5),\n     (43,12.5),(51,11.8),(51,10.5),(48,5),(41,-2),(39,-5),(40,-10.5),(40.5,-15),(35,-20),\n     (35.5,-24),(32.5,-26),(32,-29),(28,-33),(20,-34.8),(18.3,-34),(15,-27),(11.8,-17),\n     (13.5,-12),(12,-5),(9,-1),(9.5,4),(5,6),(-2,5),(-8,4.5),(-13,8),(-17,13.5),(-16.5,20)],\n    # Australia\n    [(113.5,-22),(114,-26),(115,-34),(118,-35),(123,-34),(129,-31.5),(132,-32),(135.5,-34.8),\n     (138,-35),(140,-38),(146,-39),(150,-37.5),(153,-31),(153.5,-26),(149,-21),(146,-18.5),\n     (145.5,-15),(143.5,-14),(142.5,-10.7),(141.5,-13),(141,-17),(139,-17.5),(136,-15),\n     (137,-12),(132,-11.3),(130,-12.5),(129,-15),(126,-14),(122.5,-17.5),(121,-19.5),(117,-20.7)],\n    # Japan: Honshu, Hokkaido, Kyushu\n    [(130.9,34),(132.5,35.5),(136,36),(137,37.3),(140,39.5),(140,41.5),(141.5,41),(142,39),\n     (141,37),(140.8,35.7),(139.8,35),(137,34.6),(135.2,33.5),(134.5,34.5),(132.5,34),(131,33.9)],\n    [(140,41.7),(141,45.4),(145.5,43.3),(143,42),(141,42.5)],\n    [(129.7,33),(131,33.8),(131.9,33),(131,31.2),(130.2,31.3)],\n    # Greenland\n    [(-73,78),(-60,82),(-30,83.5),(-20,82),(-18,76),(-22,70),(-32,68),(-40,65),(-43,60),\n     (-48,61),(-52,65),(-54,69),(-58,75)],\n    # Great Britain, Ireland, Iceland, Cuba\n    [(-5.5,50),(1.5,51),(1.7,52.8),(-0.5,54),(-2,56),(-2,57.6),(-3.5,58.6),(-5.5,58.5),\n     (-6,56.5),(-5,55),(-3,54.8),(-3,53.5),(-4.5,53.3),(-5,51.8)],\n    [(-10,52),(-6,52),(-6,54.3),(-8,55.2),(-10,54)],\n    [(-24,65.5),(-22,66.4),(-14.5,66),(-13.5,64.5),(-18,63.4),(-22.5,63.8)],\n    [(-85,22),(-82,23.2),(-74,20),(-77.5,19.8),(-81,22)],\n    # Madagascar, Sri Lanka, Philippines (Luzon), Indonesia, New Guinea, New Zealand\n    [(43.5,-24),(47,-25),(50,-15.5),(49.5,-12),(47,-15),(44,-17)],\n    [(80,9.7),(81.8,7.5),(80.5,6),(79.8,7.5)],\n    [(120,18.5),(122,18.3),(122,14),(124,13),(121,13.7),(120,16)],\n    [(95.5,5.5),(98,4),(104,-1),(106,-3),(105.5,-5.8),(102,-4),(98.5,1),(95.5,3.5)],\n    [(105.5,-6.5),(111,-6.5),(114.5,-7.8),(106,-7.5)],\n    [(109,1.5),(111,1.8),(114,4.5),(117,7),(119,5),(117.5,1),(116.5,-3),(114,-4),(110.5,-3),(109.5,-1)],\n    [(131,-1),(135,-3.3),(141,-2.6),(147,-6),(150,-10.5),(143,-9),(138,-8.3),(134,-4)],\n    [(173,-35),(175.5,-37),(178,-37.7),(176,-41.5),(174.5,-39.5),(174,-37.5)],\n    [(172.5,-40.5),(174,-41.5),(171,-44.5),(169,-46.6),(166.5,-46),(170.5,-43)],\n    # Chukotka beyond the antimeridian\n    [(-180,68),(-170,66),(-180,65)],\n]\n# Inland seas drawn over the land in the page color\nconst _SEAS_RAW = [\n    [(28,42),(28,44.5),(30,46),(33,46),(35,45),(38,47),(40,45),(41.5,42),(36,41.5),(32,41.8)],  # Black Sea\n    [(47,45),(50,46),(53,45),(53,41),(54,37),(50,37),(49,40),(47,43)],                           # Caspian Sea\n]\nconst LAND = [[Point2f(p[1], p[2]) for p in c] for c in _LAND_RAW]\nconst SEAS = [[Point2f(p[1], p[2]) for p in c] for c in _SEAS_RAW]\n\n# Figure: landscape 1600×900 → 3200×1800 at px_per_unit=2\nconst title_str = \"Global Air Routes · map-connection-lines · julia · makie · anyplot.ai\"\nconst title_sz  = round(Int, 20 * min(1.0, 67 / length(title_str)))\n\nfig = Figure(\n    size            = (1600, 900),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\nax = Axis(\n    fig[1, 1];\n    title               = title_str,\n    titlesize           = title_sz,\n    titlecolor          = INK,\n    xlabel              = \"Longitude\",\n    ylabel              = \"Latitude\",\n    xlabelsize          = 14,\n    ylabelsize          = 14,\n    xlabelcolor         = INK,\n    ylabelcolor         = INK,\n    xticklabelsize      = 14,\n    yticklabelsize      = 14,\n    xticklabelcolor     = INK_SOFT,\n    yticklabelcolor     = INK_SOFT,\n    xtickcolor          = INK_SOFT,\n    ytickcolor          = INK_SOFT,\n    backgroundcolor     = PAGE_BG,\n    topspinevisible     = false,\n    rightspinevisible   = false,\n    leftspinecolor      = INK_SOFT,\n    bottomspinecolor    = INK_SOFT,\n    xgridvisible        = false,\n    ygridvisible        = false,\n    limits              = (-180, 180, -50, 75),\n    xticks              = -180:60:180,\n    yticks              = [-30, 0, 30, 60],\n)\n\n# Base map: land fills and coastlines (drawn first, behind all other elements)\nfor (shapes, fill) in ((LAND, LAND_FILL), (SEAS, PAGE_BG))\n    for pts in shapes\n        poly!(ax, pts; color = fill, strokewidth = 0)\n        lines!(ax, vcat(pts, pts[1:1]); color = COAST_COLOR, linewidth = 0.6)\n    end\nend\n\n# Graticule: reference grid lines for geographic context\nfor lon in -180:30:180\n    lines!(ax, [Float64(lon), Float64(lon)], [-50.0, 75.0];\n        color = GRAT_COLOR, linewidth = 0.5)\nend\nfor lat in -30:30:60\n    lines!(ax, [-180.0, 180.0], [Float64(lat), Float64(lat)];\n        color = GRAT_COLOR, linewidth = 0.5)\nend\n\n# Connection arcs: great-circle paths via SLERP, colored by passenger volume\nfor (oi, di, volume) in connections\n    φ1 = deg2rad(airport_lats[oi]);  λ1 = deg2rad(airport_lons[oi])\n    φ2 = deg2rad(airport_lats[di]);  λ2 = deg2rad(airport_lons[di])\n    d_ang = acos(clamp(sin(φ1) * sin(φ2) + cos(φ1) * cos(φ2) * cos(λ2 - λ1), -1.0, 1.0))\n\n    arc_lons = Float64[]\n    arc_lats = Float64[]\n    n_pts = 80\n    for i in 0:n_pts\n        t = i / n_pts\n        A = sin((1 - t) * d_ang) / sin(d_ang)\n        B = sin(t * d_ang) / sin(d_ang)\n        x = A * cos(φ1) * cos(λ1) + B * cos(φ2) * cos(λ2)\n        y = A * cos(φ1) * sin(λ1) + B * cos(φ2) * sin(λ2)\n        z = A * sin(φ1) + B * sin(φ2)\n        lon_pt = rad2deg(atan(y, x))\n        lat_pt = rad2deg(atan(z, sqrt(x^2 + y^2)))\n        if !isempty(arc_lons) && abs(lon_pt - arc_lons[end]) > 180\n            push!(arc_lons, NaN)\n            push!(arc_lats, NaN)\n        end\n        push!(arc_lons, lon_pt)\n        push!(arc_lats, lat_pt)\n    end\n\n    nv = Float32((volume - vmin) / (vmax - vmin))\n    base_c = get(IMPRINT_SEQ_MARKS, nv)\n    arc_color = RGBAf(red(base_c), green(base_c), blue(base_c), 0.60f0)  # spec: 0.3-0.6\n    lines!(ax, arc_lons, arc_lats;\n        color     = arc_color,\n        linewidth = 2.0 + 3.0 * nv,\n    )\nend\n\n# Airport endpoint markers\nscatter!(ax, airport_lons, airport_lats;\n    color       = colorant\"#009E73\",\n    markersize  = 10,\n    strokewidth = 1.5,\n    strokecolor = INK,\n)\n\n# Airport labels with manual offsets to minimise overlap in dense clusters\nconst label_offsets = [\n    (-6.5,  4.0),   # London\n    (-7.0, -5.5),   # New York\n    ( 4.0,  3.5),   # Dubai\n    ( 5.0, -5.5),   # Singapore\n    ( 5.0,  3.5),   # Tokyo\n    ( 5.0, -5.5),   # Sydney\n    (-6.0, -4.5),   # Paris\n    (-7.0, -5.5),   # Los Angeles\n    ( 5.0,  3.5),   # Hong Kong\n    ( 6.5, -4.0),   # Frankfurt\n]\n\nfor (i, name) in enumerate(airport_names)\n    dx, dy = label_offsets[i]\n    text!(ax, airport_lons[i] + dx, airport_lats[i] + dy;\n        text     = name,\n        fontsize = 13,\n        color    = INK_SOFT,\n        align    = (:center, :center),\n    )\nend\n\n# Colorbar: maps passenger volume (M/year) to the sequential palette\nColorbar(fig[1, 2];\n    colormap       = IMPRINT_SEQ_MARKS,\n    limits         = (vmin, vmax),\n    label          = \"Passengers (M / year)\",\n    labelsize      = 14,\n    labelcolor     = INK,\n    ticklabelsize  = 12,\n    ticklabelcolor = INK_SOFT,\n    tickcolor      = INK_SOFT,\n    width          = 18,\n    tellheight     = false,\n)\n\ncolsize!(fig.layout, 2, Fixed(90))\n\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}