Skip to content

feat: extend FITS viewer to support PNG and additional FITS extensions#132

Merged
ppp-one merged 1 commit intoppp-one:mainfrom
dgegen:feat/extend-fits-viewer
Mar 28, 2026
Merged

feat: extend FITS viewer to support PNG and additional FITS extensions#132
ppp-one merged 1 commit intoppp-one:mainfrom
dgegen:feat/extend-fits-viewer

Conversation

@dgegen
Copy link
Copy Markdown
Collaborator

@dgegen dgegen commented Mar 25, 2026

Pull Request

Description
Extends the FITS file viewer to support PNG files and additional FITS filename extensions (.fit, .fts). When a PNG is opened, the viewer switches to an image-only layout — hiding FITS-specific controls (stretch, log scale, HDU selector) — and displays the file via a native <img> element. Switching between files cancels any in-flight requests via AbortController session management to prevent stale renders.

Changes Made

  • Add .fit, .fts, .png to allowed extensions in file_explorer.py
  • Add shared/fileTypes.js for extension detection shared between the explorer file list and the viewer
  • Add viewer/fileTypes.js bridging window.__astraFileTypes with a safe fallback; exports isPngFile and isFitsFile
  • Add PNG display mode in viewer/index.js: applyPngLayout() hides FITS controls, shows <img>; applyFitsLayout() restores the canvas/header layout
  • Add load generation counter + AbortController session tracking (beginNewSession, createSessionController) to abort stale requests on file switch
  • Expose openViewerFile() on window so the explorer modal delegates file-type routing to the viewer module instead of calling loadPreview directly
  • Add fits_url parameter to create_router() and inject window.__ASTRA_FITS_FILES_BASE_PATH for correct raw file URL resolution at non-default mount prefixes
  • Move encodePathSegments to basePath.js; add rawFitsUrl() for encoding raw file paths
  • Refactor renderer.js: add cancelPending() / enableRender() and a render token to drop stale FITS renders when switching to PNG

How to Test

  1. Start the file explorer pointed at a directory containing both .fits and .png files
  2. Click a FITS file — verify the normal canvas viewer, header table, HDU selector, and stretch controls appear
  3. Click a PNG file — verify the image displays, and stretch/log/HDU controls are hidden/disabled
  4. Rapidly click between files — verify no stale image from a previous load flashes in
  5. Open a .fit or .fts file — verify it loads correctly as FITS

Checklist

  • Code follows project style guidelines
  • Tests added/updated
  • Documentation updated (if needed)
  • All checks pass

- Add .fit, .fts, and .png to allowed file extensions in the backend
- Add shared fileTypes.js for extension detection used by both explorer
  and viewer; viewer/fileTypes.js bridges it with a safe fallback
- Implement PNG display mode: dedicated layout hides FITS-specific
  controls and shows an <img> element instead of the canvas
- Introduce load generation + AbortController session management to
  cancel in-flight requests when a new file is opened
- Expose openViewerFile() on window so the explorer modal delegates
  file-type routing to the viewer module
- Add fits_url parameter to create_router() and inject
  __ASTRA_FITS_FILES_BASE_PATH so the viewer resolves raw file URLs
  correctly when mounted at a non-default prefix
- Move encodePathSegments to basePath.js so rawFitsUrl reuses it
- Extract setFitsControlsEnabled() to unify toolbar enable/disable
Copilot AI review requested due to automatic review settings March 25, 2026 13:06

This comment was marked as outdated.

@ppp-one ppp-one merged commit 86e7f57 into ppp-one:main Mar 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants