Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/connections/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def _process_single(self, json_path: Path) -> str:
output_filename = f"{title}.png"
output_path = self.output_dir / output_filename

# Create and save map
# Create and save map with thumbnail
fm = FlightMap(flights=flights, title=title)
fm.save(filename=str(output_path))
fm.save_with_thumbnail(filename=str(output_path))

return str(output_path)
16 changes: 15 additions & 1 deletion src/connections/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class MapMetadata:
title: str
filename: str
relative_path: str
thumbnail_path: Optional[str] = None


class IndexGenerator:
Expand Down Expand Up @@ -81,13 +82,26 @@ def scan_output_directory(self, directory: str) -> List[MapMetadata]:

metadata_list = []
for png_file in png_files:
# Skip thumbnail files (they end with _thumb)
if png_file.stem.endswith("_thumb"):
continue

# Use filename (without extension) as title
title = png_file.stem
filename = png_file.name
# Relative path for HTML links
relative_path = f"./{filename}"

metadata = MapMetadata(title=title, filename=filename, relative_path=relative_path)
# Check if thumbnail exists
thumbnail_file = png_file.parent / f"{png_file.stem}_thumb{png_file.suffix}"
thumbnail_path = f"./{thumbnail_file.name}" if thumbnail_file.exists() else None

metadata = MapMetadata(
title=title,
filename=filename,
relative_path=relative_path,
thumbnail_path=thumbnail_path,
)
metadata_list.append(metadata)

return metadata_list
64 changes: 55 additions & 9 deletions src/connections/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,32 @@ def __init__(
self._title = title
self._image_format = image_format

def draw(self) -> go.Figure:
"""Generate map from flights and airports"""
def draw(self, thumbnail: bool = False) -> go.Figure:
"""Generate map from flights and airports

Args:
thumbnail: If True, optimize layout for thumbnail display
"""
# Adjust layout for thumbnail vs full-size
if thumbnail:
title_config = None
margin_config = dict(l=0, r=0, t=0, b=0)
else:
title_config = go.layout.Title(
text=self._title,
font=dict(family="Arial", size=50),
xanchor="center",
yanchor="top",
x=0.5,
)
margin_config = dict(l=0, r=0, t=80, b=0)

fig = go.Figure(
layout=dict(
title=go.layout.Title(
text=self._title,
font=dict(family="Arial", size=50),
xanchor="center",
yanchor="top",
x=0.5,
),
title=title_config,
showlegend=False,
autosize=True,
margin=margin_config,
geo=dict(
fitbounds="locations",
showframe=False,
Expand Down Expand Up @@ -81,7 +94,40 @@ def to_image(self, width: int = 1920, height: int = 1080):
format=self._image_format.value, width=width, height=height, scale=10
)

def to_thumbnail(self, width: int = 640, height: int = 360) -> bytes:
"""Generate thumbnail image at lower resolution with optimized layout"""
thumbnail_fig = self.draw(thumbnail=True)
return thumbnail_fig.to_image(
format=self._image_format.value, width=width, height=height, scale=5
)

def save(self, filename: str) -> None:
image = self.to_image()
with open(filename, "wb") as fp:
fp.write(image)

def save_with_thumbnail(self, filename: str) -> str:
"""
Save both full-size image and thumbnail

Args:
filename: Path for the full-size image

Returns:
Path to the generated thumbnail file
"""
# Save full-size image
self.save(filename)

# Generate thumbnail filename
from pathlib import Path

path = Path(filename)
thumbnail_path = path.parent / f"{path.stem}_thumb{path.suffix}"

# Save thumbnail
thumbnail_image = self.to_thumbnail()
with open(thumbnail_path, "wb") as fp:
fp.write(thumbnail_image)

return str(thumbnail_path)
182 changes: 22 additions & 160 deletions src/connections/templates/index.html.j2
Original file line number Diff line number Diff line change
@@ -1,202 +1,64 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flight Connection Maps</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="light dark">
<title>Connections</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 2rem;
}

.container {
max-width: 1400px;
margin: 0 auto;
}

header {
text-align: center;
color: white;
margin-bottom: 3rem;
}

h1 {
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 0.5rem;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle {
font-size: 1.1rem;
opacity: 0.9;
}

.maps-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
gap: 2rem;
margin-bottom: 2rem;
}

.map-card {
background: white;
border-radius: 12px;
overflow: hidden;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.map-card:hover {
transform: translateY(-5px);
box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
.grid {
grid-template-columns: repeat(3, 1fr);
}

.map-thumbnail {
position: relative;
display: block;
width: 100%;
padding-top: 56.25%; /* 16:9 aspect ratio */
overflow: hidden;
background: #f0f0f0;
background: var(--pico-muted-color);
}

.map-thumbnail img {
position: absolute;
top: 0;
left: 0;
display: block;
width: 100%;
height: 100%;
object-fit: cover;
height: auto;
transition: transform 0.3s ease;
}

.map-card:hover .map-thumbnail img {
transform: scale(1.05);
}

.map-info {
padding: 1.5rem;
}

.map-title {
font-size: 1.25rem;
font-weight: 600;
color: #333;
margin-bottom: 0.5rem;
word-wrap: break-word;
}

.map-link {
display: inline-block;
margin-top: 0.75rem;
padding: 0.5rem 1rem;
background: #667eea;
color: white;
text-decoration: none;
border-radius: 6px;
font-size: 0.9rem;
font-weight: 500;
transition: background 0.3s ease;
}

.map-link:hover {
background: #5568d3;
}

.empty-state {
text-align: center;
color: white;
padding: 4rem 2rem;
}

.empty-state h2 {
font-size: 1.5rem;
margin-bottom: 1rem;
}

footer {
text-align: center;
color: white;
margin-top: 3rem;
padding-top: 2rem;
border-top: 1px solid rgba(255, 255, 255, 0.2);
opacity: 0.8;
}

@media (max-width: 768px) {
body {
padding: 1rem;
}

h1 {
font-size: 2rem;
}

.maps-grid {
grid-template-columns: 1fr;
gap: 1.5rem;
}
}

@media (max-width: 480px) {
h1 {
font-size: 1.5rem;
}

.subtitle {
font-size: 1rem;
}

.map-info {
padding: 1rem;
}

.map-title {
font-size: 1.1rem;
}
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>✈️ Flight Connection Maps</h1>
<p class="subtitle">Explore your flight routes around the world</p>
</header>
<header>
<h1>Connections</h1>
</header>

<main class="container">
{% if maps %}
<div class="maps-grid">
<div class="grid">
{% for map in maps %}
<div class="map-card">
<article>
<h2>{{ map.title }}</h2>
<a href="{{ map.relative_path }}" class="map-thumbnail">
<img src="{{ map.relative_path }}" alt="{{ map.title }}" loading="lazy">
<img src="{{ map.thumbnail_path or map.relative_path }}" alt="{{ map.title }}" loading="lazy">
</a>
<div class="map-info">
<h2 class="map-title">{{ map.title }}</h2>
<a href="{{ map.relative_path }}" class="map-link" target="_blank">View Full Size</a>
</div>
</div>
</article>
{% endfor %}
</div>
{% else %}
<div class="empty-state">
<h2>No flight maps found</h2>
<p>Add some flight data to generate your first map!</p>
</div>
{% endif %}

<footer>
<p>Generated with Connections Flight Map Generator</p>
</footer>
</div>

</main>
</body>
</html>
Loading
Loading