Commit 96d2ee94 authored by vertighel's avatar vertighel
Browse files

fits-viewer.js: disaccoppia "Auto" (refresh) dalla dinamica manuale

"Auto" faceva doppio lavoro: gate sia del refresh continuo sia del
range vmin/vmax pull dal server. Modificare la dinamica lo disattivava
del tutto, interrompendo l'arrivo di nuove immagini.

Aggiunto _primary.autoRange, indipendente da autoUpdate:
- autoUpdate: "Auto" checkbox, controlla solo se arrivano nuovi frame.
- autoRange: se true segue il vmin/vmax auto del server; diventa false
  quando l'utente imposta un range manualmente (input testuale o drag),
  senza piu' toccare la checkbox "Auto".

Il push WebSocket "fits-preview" consegna un PNG gia' renderizzato
server-side col range auto del server, quindi quando autoRange e' false
non lo dipinge piu' direttamente: rilancia un render REST (_renderPng),
che rispetta vmin/vmax correnti, cosi' i nuovi frame continuano ad
arrivare (Auto resta attivo) ma con la dinamica scelta dall'utente.
parent 96e8e6f7
Loading
Loading
Loading
Loading
+27 −12
Original line number Diff line number Diff line
@@ -121,7 +121,8 @@ export class FitsViewer {
            width:      0,  // FITS image width in pixels
            height:     0,  // FITS image height in pixels
            mode:       'png',   // 'png' | 'fits'
            autoUpdate: true,
            autoUpdate: true,    // "Auto" checkbox: keep pulling new frames
            autoRange:  true,    // follow the server's auto vmin/vmax; false once the user sets one manually
            renderer:   null,    // GLRenderer instance (fits mode only)
            dtype:      '',
            letterbox:  { dx: 0, dy: 0, dw: 800, dh: 800 },
@@ -454,7 +455,10 @@ export class FitsViewer {

            // Accept the server's auto-range whenever the user has not manually
            // set a range (vmin === vmax is our sentinel for "not yet set").
            if (state.autoUpdate || state.vmin === state.vmax) {
            // autoRange is independent of autoUpdate: "Auto" only means
            // auto-refresh — a manually chosen dynamic keeps applying to
            // every new frame for as long as it keeps refreshing.
            if (state.autoRange || state.vmin === state.vmax) {
                state.vmin = info.vmin_auto;
                state.vmax = info.vmax_auto;
            }
@@ -674,6 +678,18 @@ export class FitsViewer {

            if (cam_id === this._primaryCam) {
                if (!this._primary.autoUpdate) return;

                if (!this._primary.autoRange) {
                    // The pushed PNG is pre-rendered server-side with the
                    // server's own auto-range, ignoring our vmin/vmax. Once
                    // the user has set a manual range, re-render via REST
                    // instead so the new frame respects it.
                    if (this._primary.mode === 'png') await this._renderPng();
                    await this._refreshPanoramic();
                    this._redrawOverlay();
                    return;
                }

                const seq = this._nextPrimarySeq();
                const img = await this._loadImage(`data:image/png;base64,${png}`);
                if (this._isPrimaryStale(seq)) return;
@@ -1197,11 +1213,10 @@ export class FitsViewer {
    async _endRightDrag() {
        if (!this._rdrag) return;
        this._rdrag = null;
        // Manual range edit: stop the auto-update refresh from overwriting it
        // with the server's auto-range on the next telemetry-triggered refresh.
        this._primary.autoUpdate = false;
        const chkAuto = this.root.querySelector('.ctrl-auto');
        if (chkAuto) chkAuto.checked = false;
        // Manual range edit: stop new frames from overwriting it with the
        // server's auto-range. "Auto" (autoUpdate) is untouched — it only
        // controls whether frames keep refreshing at all.
        this._primary.autoRange = false;
        // PNG mode: re-fetch at the new range.  FITS mode: already rendered by GPU.
        if (this._primary.mode === 'png') await this._renderPng();
        await this._refreshPanoramic();
@@ -1225,16 +1240,16 @@ export class FitsViewer {
        const el = this._el;

        // Primary camera: apply manual range on input change.
        // Editing min/max explicitly disables auto-update so _refreshPrimary()
        // does not immediately overwrite the user's values with server auto-range.
        // Editing min/max explicitly disables auto-range so _refreshPrimary()
        // does not immediately overwrite the user's values with server
        // auto-range. "Auto" (autoUpdate) is left untouched: it only controls
        // whether frames keep refreshing, not which dynamic they use.
        const applyPrimaryRange = () => {
            const vmin = parseFloat(el.inputVmin?.value);
            const vmax = parseFloat(el.inputVmax?.value);
            if (!isNaN(vmin)) this._primary.vmin = vmin;
            if (!isNaN(vmax)) this._primary.vmax = vmax;
            this._primary.autoUpdate = false;
            const chkAuto = this.root.querySelector('.ctrl-auto');
            if (chkAuto) chkAuto.checked = false;
            this._primary.autoRange = false;
            this._refreshPrimary();
        };
        el.inputVmin?.addEventListener('change', applyPrimaryRange);