Interactive Figures Visual Polish Implementation Plan
For Claude: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
Goal: Replace placeholder graphics with real NASA moon frames and a Wikimedia Earth map.
Architecture: sync.sh downloads assets (moon frames + Earth map), moon-renderer loads/caches frames and applies latitude rotation, latitude-picker draws Earth map as background.
Tech Stack: Bash/curl for fetching, Canvas 2D for rendering, ES modules.
Reference: See doc/plans/2026-01-11-interactive-figures-visual-polish-design.md for design rationale.
Phase 1: Asset Downloading
Task 1.1: Update sync.sh to download Earth map
Files:
- Modify: editorial/articles/regolith-with-latitude/assets/figures/sync.sh
Step 1: Add Earth map download
Replace the entire sync.sh with:
#!/bin/bash
# sync.sh - Fetch NASA moon frames and Earth map
# Run from the figures/ directory
set -euo pipefail
cd "$(dirname "$0")"
YEAR="${1:-2026}"
DATA_DIR="data"
TEXTURES_DIR="textures"
FALLBACK_DIR="fallback/frames"
echo "=== Syncing assets for Regolith with Latitude ==="
echo ""
# Create directories
mkdir -p "$DATA_DIR" "$TEXTURES_DIR" "$FALLBACK_DIR"
# --- Earth Map ---
EARTH_URL="https://upload.wikimedia.org/wikipedia/commons/thumb/7/74/Mercator-projection.jpg/1280px-Mercator-projection.jpg"
EARTH_FILE="$TEXTURES_DIR/earth-mercator.jpg"
if [ -f "$EARTH_FILE" ]; then
echo "Earth map already exists: $EARTH_FILE"
else
echo "Downloading Earth map..."
curl -L -o "$EARTH_FILE" "$EARTH_URL"
echo "Downloaded: $EARTH_FILE"
fi
echo ""
echo "=== Sync complete ==="
echo "Earth map: $EARTH_FILE"
echo ""
echo "NOTE: Moon frames not yet implemented (Task 1.2)"
Step 2: Run sync.sh to download Earth map
cd editorial/articles/regolith-with-latitude/assets/figures && ./sync.sh
Expected: Downloads earth-mercator.jpg to textures/
Step 3: Verify the file exists
ls -la editorial/articles/regolith-with-latitude/assets/figures/textures/
Expected: earth-mercator.jpg (~100-200KB)
Step 4: Commit
git add editorial/articles/regolith-with-latitude/assets/figures/sync.sh
git add editorial/articles/regolith-with-latitude/assets/figures/textures/earth-mercator.jpg
git commit -m "feat: download Earth map from Wikimedia in sync.sh"
Task 1.2: Add moon frame downloading to sync.sh
Files:
- Modify: editorial/articles/regolith-with-latitude/assets/figures/sync.sh
Step 1: Add moon frame download loop
Add after the Earth map section, before the final echo:
# --- Moon Frames ---
# NASA SVS 5587: Moon Phase and Libration, 2026
# 8760 hourly frames. We fetch one per day (frame at noon = hour 12).
# Every 3rd day = ~122 frames.
NASA_BASE="https://svs.gsfc.nasa.gov/vis/a000000/a005500/a005587/frames/730x730_1x1_30p/plain"
echo "Downloading moon frames (every 3rd day)..."
frame_count=0
for day in $(seq 1 3 365); do
# Frame number = (day - 1) * 24 + 12 (noon on that day)
# Frames are 1-indexed, so day 1 noon = frame 12
frame=$(( (day - 1) * 24 + 12 ))
frame_padded=$(printf "%04d" $frame)
output_file="$FALLBACK_DIR/$(printf "%03d" $day).jpg"
if [ -f "$output_file" ]; then
echo " Day $day: already exists"
else
url="$NASA_BASE/moon.$frame_padded.jpg"
echo " Day $day: downloading frame $frame_padded..."
curl -s -L -o "$output_file" "$url" || echo " Warning: failed to download $url"
fi
frame_count=$((frame_count + 1))
done
echo "Downloaded $frame_count moon frames"
Step 2: Generate frame index
Add after the moon frame loop:
# --- Generate frame index ---
echo "Generating frame index..."
echo "{" > "$DATA_DIR/frame-index.json"
echo ' "year": '$YEAR',' >> "$DATA_DIR/frame-index.json"
echo ' "frames": {' >> "$DATA_DIR/frame-index.json"
first=true
for file in "$FALLBACK_DIR"/*.jpg; do
if [ -f "$file" ]; then
basename=$(basename "$file" .jpg)
day=$(echo "$basename" | sed 's/^0*//')
[ -z "$day" ] && day=0
if [ "$first" = true ]; then
first=false
else
echo "," >> "$DATA_DIR/frame-index.json"
fi
printf ' "%d": "%s"' "$day" "$(basename "$file")" >> "$DATA_DIR/frame-index.json"
fi
done
echo "" >> "$DATA_DIR/frame-index.json"
echo " }" >> "$DATA_DIR/frame-index.json"
echo "}" >> "$DATA_DIR/frame-index.json"
echo "Generated: $DATA_DIR/frame-index.json"
Step 3: Update final summary
Replace the final echo block:
echo ""
echo "=== Sync complete ==="
echo "Earth map: $EARTH_FILE"
echo "Moon frames: $frame_count frames in $FALLBACK_DIR/"
echo "Frame index: $DATA_DIR/frame-index.json"
Step 4: Run sync.sh
cd editorial/articles/regolith-with-latitude/assets/figures && ./sync.sh
Expected: Downloads ~122 moon frames (takes 1-2 minutes), generates frame-index.json
Step 5: Verify downloads
ls editorial/articles/regolith-with-latitude/assets/figures/fallback/frames/ | head -10
cat editorial/articles/regolith-with-latitude/assets/figures/data/frame-index.json | head -20
Expected: Files like 001.jpg, 004.jpg, 007.jpg… and valid JSON index
Step 6: Commit sync.sh (but not the frames - they’re large)
git add editorial/articles/regolith-with-latitude/assets/figures/sync.sh
git add editorial/articles/regolith-with-latitude/assets/figures/data/frame-index.json
git commit -m "feat: add moon frame downloading to sync.sh"
Task 1.3: Add .gitignore for large assets
Files:
- Create: editorial/articles/regolith-with-latitude/assets/figures/.gitignore
Step 1: Create .gitignore
# Large binary assets - run `make sync` to download
fallback/frames/*.jpg
# Keep the Earth map (small enough to commit)
!textures/earth-mercator.jpg
Step 2: Commit
git add editorial/articles/regolith-with-latitude/assets/figures/.gitignore
git commit -m "chore: gitignore moon frames (download via sync.sh)"
Phase 2: Moon Renderer Updates
Task 2.1: Add frame loading to moon-renderer
Files:
- Modify: editorial/articles/regolith-with-latitude/assets/figures/moon-renderer.js
Step 1: Add frame index loading and image cache
Replace the entire moon-renderer.js with:
// moon-renderer.js - Shared moon display component
// Returns a capability object for controlling the moon visualization.
// Frame cache shared across all moon instances
const frameCache = new Map();
let frameIndex = null;
let frameIndexPromise = null;
/**
* Load the frame index JSON.
*/
async function loadFrameIndex(assets) {
if (frameIndex) return frameIndex;
if (frameIndexPromise) return frameIndexPromise;
frameIndexPromise = fetch(assets.data('frame-index.json'))
.then(r => r.json())
.then(data => {
frameIndex = data;
return data;
})
.catch(err => {
console.warn('Failed to load frame index:', err);
return null;
});
return frameIndexPromise;
}
/**
* Find the closest available frame for a given day of year.
*/
function findClosestFrame(dayOfYear, index) {
if (!index || !index.frames) return null;
const days = Object.keys(index.frames).map(Number).sort((a, b) => a - b);
if (days.length === 0) return null;
// Find closest day
let closest = days[0];
let minDiff = Math.abs(dayOfYear - closest);
for (const day of days) {
const diff = Math.abs(dayOfYear - day);
if (diff < minDiff) {
minDiff = diff;
closest = day;
}
}
return index.frames[closest];
}
/**
* Convert date string to day of year (1-365).
*/
function dateToDayOfYear(dateStr) {
const date = new Date(dateStr);
const start = new Date(date.getFullYear(), 0, 0);
const diff = date - start;
const oneDay = 1000 * 60 * 60 * 24;
return Math.floor(diff / oneDay);
}
/**
* Load a frame image, using cache.
*/
async function loadFrame(filename, assets) {
if (frameCache.has(filename)) {
return frameCache.get(filename);
}
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => {
frameCache.set(filename, img);
resolve(img);
};
img.onerror = () => {
console.warn('Failed to load frame:', filename);
resolve(null);
};
img.src = assets.fallback(`frames/${filename}`);
});
}
/**
* Create a moon renderer in the given container.
* Handles progressive enhancement: placeholder → NASA frame.
*
* @param {HTMLElement} container - DOM element to render into
* @param {Object} options
* @param {Object} options.assets - Asset path resolver
* @returns {Object} Moon capability object
*/
export function createMoon(container, { assets }) {
// Internal state
let currentParams = {
size: 100,
brightness: 1,
latitude: 0,
date: new Date().toISOString().split('T')[0],
};
let canvas = null;
let ctx = null;
let currentFrame = null;
let loadingFrame = null;
// Create canvas
function ensureCanvas() {
if (!canvas) {
canvas = document.createElement('canvas');
canvas.setAttribute('role', 'img');
canvas.setAttribute('aria-label', 'Moon visualization');
container.appendChild(canvas);
ctx = canvas.getContext('2d');
}
return canvas;
}
// Render placeholder
function renderPlaceholder() {
ensureCanvas();
const size = currentParams.size;
canvas.width = size;
canvas.height = size;
// Dark background
ctx.fillStyle = '#1a1a2e';
ctx.fillRect(0, 0, size, size);
// Gray circle placeholder
ctx.beginPath();
ctx.arc(size / 2, size / 2, size / 2 - 4, 0, Math.PI * 2);
ctx.fillStyle = '#c9c9c9';
ctx.fill();
// Loading indicator
ctx.fillStyle = '#333';
ctx.font = `${Math.max(10, size / 10)}px sans-serif`;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText('...', size / 2, size / 2);
}
// Render with frame
function renderWithFrame(frame) {
ensureCanvas();
const size = currentParams.size;
const latitude = currentParams.latitude;
canvas.width = size;
canvas.height = size;
// Dark background
ctx.fillStyle = '#1a1a2e';
ctx.fillRect(0, 0, size, size);
// Draw frame with rotation based on latitude
ctx.save();
ctx.translate(size / 2, size / 2);
ctx.rotate(latitude * Math.PI / 180);
// Draw the frame centered, scaled to fit
const frameSize = size - 8; // Small margin
ctx.drawImage(frame, -frameSize / 2, -frameSize / 2, frameSize, frameSize);
ctx.restore();
}
// Main render function
async function render() {
const dayOfYear = dateToDayOfYear(currentParams.date);
// Try to load frame index
const index = await loadFrameIndex(assets);
if (!index) {
renderPlaceholder();
return;
}
// Find closest frame
const filename = findClosestFrame(dayOfYear, index);
if (!filename) {
renderPlaceholder();
return;
}
// If we already have this frame, render it
if (currentFrame && loadingFrame === filename) {
renderWithFrame(currentFrame);
return;
}
// Show placeholder while loading
renderPlaceholder();
// Load the frame
loadingFrame = filename;
const frame = await loadFrame(filename, assets);
// Check if we're still wanting this frame
if (loadingFrame === filename && frame) {
currentFrame = frame;
renderWithFrame(frame);
}
}
// Initial render
renderPlaceholder();
// Return capability object
return {
/**
* Update moon appearance.
* @param {Object} params
* @param {number} params.size - Pixel diameter
* @param {number} params.brightness - 0-1 intensity
* @param {number} params.latitude - Viewer latitude (-90 to 90)
* @param {string} params.date - ISO date string
*/
render(params) {
currentParams = { ...currentParams, ...params };
render();
},
/**
* Get current parameters.
*/
getState() {
return { ...currentParams };
},
/**
* Clean up resources.
*/
destroy() {
if (canvas && canvas.parentNode) {
canvas.parentNode.removeChild(canvas);
}
canvas = null;
ctx = null;
},
};
}
Step 2: Verify syntax
node -c editorial/articles/regolith-with-latitude/assets/figures/moon-renderer.js && echo "Syntax OK"
Expected: “Syntax OK”
Step 3: Commit
git add editorial/articles/regolith-with-latitude/assets/figures/moon-renderer.js
git commit -m "feat: load NASA moon frames in moon-renderer"
Task 2.2: Test moon-renderer in browser
Step 1: Start local server
cd editorial/articles/regolith-with-latitude/assets/figures && python3 -m http.server 8000
Step 2: Open test.html
Navigate to: http://localhost:8000/test.html
Step 3: Verify
- [ ] Three-moons figure shows actual moon images (not gray circles)
- [ ] Latitude-picker moon preview shows moon image
- [ ] Moon-timeline shows moon image
- [ ] Dragging latitude rotates the moon images
- [ ] No JavaScript errors in console
Step 4: Stop server
Press Ctrl+C
Phase 3: Latitude Picker Updates
Task 3.1: Add Earth map background to latitude-picker
Files:
- Modify: editorial/articles/regolith-with-latitude/assets/figures/latitude-picker.js
Step 1: Add Earth image loading
Find the export function setup and add after the moon creation:
// Load Earth map
let earthImg = null;
const earthImage = new Image();
earthImage.onload = () => {
earthImg = earthImage;
render();
};
earthImage.src = assets.textures('earth-mercator.jpg');
Step 2: Update the render function
Replace the render function’s Earth drawing section. Find:
// Draw placeholder Earth (blue rectangle for now)
ctx.fillStyle = '#1a5276';
ctx.fillRect(0, 0, width, height);
Replace with:
// Draw Earth map (or blue fallback)
if (earthImg) {
ctx.drawImage(earthImg, 0, 0, width, height);
} else {
ctx.fillStyle = '#1a5276';
ctx.fillRect(0, 0, width, height);
}
Step 3: Verify syntax
node -c editorial/articles/regolith-with-latitude/assets/figures/latitude-picker.js && echo "Syntax OK"
Expected: “Syntax OK”
Step 4: Commit
git add editorial/articles/regolith-with-latitude/assets/figures/latitude-picker.js
git commit -m "feat: add Earth map background to latitude-picker"
Task 3.2: Test latitude-picker in browser
Step 1: Start local server
cd editorial/articles/regolith-with-latitude/assets/figures && python3 -m http.server 8000
Step 2: Open test.html
Navigate to: http://localhost:8000/test.html
Step 3: Verify
- [ ] Latitude-picker shows Earth map (continents visible)
- [ ] Red latitude line draws over the map
- [ ] Dragging still works
- [ ] Keyboard controls still work (arrow keys)
- [ ] No JavaScript errors in console
Step 4: Stop server
Press Ctrl+C
Phase 4: Final Integration
Task 4.1: Test in Django site
Step 1: Run Django dev server
make serve
Step 2: Navigate to the article
Open the Regolith with Latitude article in browser.
Step 3: Verify
- [ ] All three figures display with real imagery
- [ ] Latitude picker shows Earth map
- [ ] Moon frames load and rotate with latitude
- [ ] Timeline scrubbing changes moon phase
- [ ] No console errors
Step 4: Stop server
Press Ctrl+C
Task 4.2: Final commit and summary
Step 1: Check for any uncommitted changes
git status
Step 2: Commit any remaining changes
git add -A
git commit -m "feat: complete visual polish for interactive figures"
Step 3: Summary
Visual polish complete: - sync.sh downloads Earth map and ~122 NASA moon frames - moon-renderer displays frames with latitude-based rotation - latitude-picker shows Mercator Earth map - All figures now display real imagery instead of placeholders
Summary
Phases completed: 1. Asset downloading (Earth map + moon frames + frame index) 2. Moon renderer updates (frame loading, caching, rotation) 3. Latitude picker updates (Earth map background) 4. Final integration testing
Files modified:
- sync.sh - Downloads assets from Wikimedia and NASA
- moon-renderer.js - Loads/caches NASA frames, applies rotation
- latitude-picker.js - Draws Earth map background
- .gitignore - Excludes large moon frames
Assets added:
- textures/earth-mercator.jpg (~150KB, committed)
- fallback/frames/*.jpg (~20MB total, gitignored)
- data/frame-index.json (generated, committed)