All files / src/web disc-visualiser.js

82.15% Statements 290/353
57.89% Branches 77/133
81.08% Functions 60/74
86.51% Lines 263/304

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552                                      1x     1x 1x 1x 1x   1x     1x     1x   1x     252x 1x   10x                               5x       1x       60x         16x                           10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x   10x 10x 10x 10x 10x 10x 10x   10x   10x 10x 10x 10x 10x 10x 10x 10x 10x   10x     10x 10x 8x 8x   10x         10x 10x 10x 10x 10x 10x 10x 10x 10x       10x 10x 1x 1x 1x 1x 1x 1x   1x   10x           10x                     10x 20x         10x         2x 2x 2x       2x 2x 2x         2x       30x 60x 2x 2x         16x       8x       1x                 1x 1x 1x       8x 8x 8x       3x 3x 3x 3x 3x 3x 3x       13x 13x         16x 15x 16x 15x 15x 6x 4x 15x 15x       67x       22x 22x       16x       1x 1x 1x 1x       2x 2x 2x 2x 2x       3x 3x 3x 3x       8x 8x 8x       8x 8x 8x 16x 16x   8x 8x 8x 8x 8x 8x         756x 252x       11x       9x 9x 9x 9x 9x 9x 9x 9x       12x 12x         9x 9x 9x 765x   765x 765x 756x 765x   9x 9x 9x       758x                             2x 2x   2x 2x 2x 2x       756x 756x 756x                   15x 15x 15x 15x   15x 15x 15x 15x 15x 15x 15x 15x 15x 15x   15x   15x 15x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x     15x 15x 1x 1x 1x 1x 1x         15x 15x 15x 1260x 1260x                                                     22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x         30x       15x 15x 15x 30x 30x 30x   15x 15x 15x 15x 8x   7x     7x 7x 7x   15x 15x 15x       90x       7x 588x 7x           15x 15x 1x 1x 1x 1x 1x             11x      
import { IbmDiscFormat } from "../disc.js";
import { FloatingPanel } from "./floating-panel.js";
import {
    DensityPalette,
    DensityRampHex,
    DiscGeometry,
    ErrorHex,
    MaxDensity,
    MinDensity,
    RegionStyles,
    RegionPalette,
    UnformattedHex,
    clampZoom,
    renderTracks,
    trackPulseDensity,
    trackRegions,
} from "../disc-surface.js";
 
/** 300 rpm. */
const RevolutionMs = 200;
 
/** Not on either palette: the head and the index marker have to sit clear of the surface. */
const HeadColour = "#eb6834";
const IndexColour = "#c3c2b7";
const HoverColour = "#ffffff";
const MarkOutline = "#0d0d0d";
 
const ScanBudgetMs = 16;
 
/** A trackpad reports deltas in the tens, a mouse notch about 100. */
const WheelZoomRate = 0.003;
 
/** Firefox reports wheel deltas in lines, not pixels. */
const PixelsPerWheelLine = 16;
 
const Views = {
    density: {
        palette: DensityPalette,
        analyse: (track) => ({ codes: trackPulseDensity(track) }),
        describe: ({ codes }, word) => (codes[word] === 0 ? "no flux" : `${codes[word]} pulses`),
        legend: () =>
            swatch(UnformattedHex, "unformatted") +
            `<span class="disc-legend-item disc-legend-grow">${MinDensity}` +
            `<span class="disc-legend-ramp" style="background:linear-gradient(to right, ${DensityRampHex.join(", ")})"></span>` +
            `${MaxDensity} pulses per 64&micro;s</span>`,
    },
    format: {
        palette: RegionPalette,
        analyse: (track, warn) => trackRegions(track, warn),
        describe: ({ codes, sectorNumbers, errors }, word) => {
            const what = RegionStyles[codes[word]].name;
            const named = sectorNumbers[word] < 0 ? what : `sector ${sectorNumbers[word]} ${what}`;
            const error = errors.find(({ firstWord, lastWord }) =>
                lastWord <= firstWord ? word >= firstWord || word < lastWord : word >= firstWord && word < lastWord,
            );
            return `${named}${error ? ` · ${error.kind} error` : ""}`;
        },
        legend: () => RegionStyles.map(({ hex, name }) => swatch(hex, name)).join("") + swatch(ErrorHex, "CRC error"),
    },
};
 
const ignoreWarning = () => {};
 
/** These lines are rewritten every frame, so skip the ones that have not changed. */
function setText(element, text) {
    if (element.textContent !== text) element.textContent = text;
}
 
/** One atomic legend entry, so a swatch never gets orphaned from its label by a line break. */
function swatch(colour, label) {
    return `<span class="disc-legend-item"><span class="disc-legend-swatch" style="background:${colour}"></span>${label}</span>`;
}
 
/**
 * The disc surface panel: one side of one drive's disc drawn as the physical platter, coloured
 * either by raw pulse density or by what the decoder makes of each word, with the head drawn
 * where it sits.
 */
export class DiscVisualiser {
    /**
     * @param {object} options
     * @param {object} options.fdc
     */
    constructor({ fdc }) {
        this._fdc = fdc;
        this.panel = document.getElementById("disc-panel");
        this.surfaceCanvas = document.getElementById("disc-surface");
        this.overlayCanvas = document.getElementById("disc-overlay");
        this.statusElem = document.getElementById("disc-status");
        this.nameElem = document.getElementById("disc-name");
        this.hoverWhereElem = document.getElementById("disc-hover-where");
        this.hoverWhatElem = document.getElementById("disc-hover-what");
        this.legendElem = document.getElementById("disc-legend");
        this.sideControls = document.getElementById("disc-side-controls");
        this.openBtn = document.getElementById("disc-visualiser-open");
 
        this._view = "density";
        this._driveIndex = 0;
        this._isSideUpper = false;
        this._disc = null;
        this._geometry = null;
        this._imageData = null;
        this._pixels = null;
        /** @type {(Uint8Array|null)[]} */
        this._codes = [];
        /** @type {(object|null)[]} */
        this._info = [];
        this._staleTracks = new Set();
        this._needsFullRepaint = true;
        this._scanCursor = 0;
        this._scanHandle = null;
        this._hover = null;
        this._pan = null;
        this._surfaceStale = false;
        this._frameHandle = null;
 
        this._onTrackWrite = (isSideUpper, trackNum) => {
            if (isSideUpper === this._isSideUpper) this._staleTracks.add(trackNum);
        };
        this._onResize = () => this._resize();
        this.openBtn.addEventListener("click", (e) => {
            e.preventDefault();
            this.toggle();
        });
        this.floating = new FloatingPanel({
            panel: this.panel,
            header: this.panel.querySelector(".disc-header"),
            closeButton: document.getElementById("disc-close"),
        });
        this.floating.addEventListener("open", () => this._start());
        this.floating.addEventListener("close", () => this._stop());
        this._bindChoice("[data-drive]", (button) => this._select(Number(button.dataset.drive), this._isSideUpper));
        this._bindChoice("[data-side]", (button) => this._select(this._driveIndex, button.dataset.side === "1"));
        this._bindChoice("[data-view]", (button) => this._setView(button.dataset.view));
        this.overlayCanvas.addEventListener("mousemove", (e) => (this._hover = this._canvasPoint(e)));
        this.overlayCanvas.addEventListener("mouseleave", () => (this._hover = null));
        this._bindZoomAndPan();
        this._buildLegend();
    }
 
    _bindZoomAndPan() {
        const canvas = this.overlayCanvas;
        canvas.addEventListener("wheel", (e) => {
            e.preventDefault();
            Iif (!this._geometry) return;
            const { x, y } = this._canvasPoint(e);
            const at = this._geometry.toDisc(x, y);
            const lines = e.deltaMode === WheelEvent.DOM_DELTA_LINE ? PixelsPerWheelLine : 1;
            const zoom = clampZoom(this._geometry.zoom * Math.exp(-e.deltaY * lines * WheelZoomRate));
            // Keep whatever is under the pointer under the pointer.
            this._setViewport(zoom, at.x - x / zoom, at.y - y / zoom);
        });
        canvas.addEventListener("pointerdown", (e) => {
            if (e.button !== 0) return;
            const { originX, originY } = this._geometry;
            this._pan = { pointerId: e.pointerId, ...this._canvasPoint(e), originX, originY, moved: false };
            canvas.setPointerCapture(e.pointerId);
        });
        canvas.addEventListener("pointermove", (e) => {
            if (this._pan?.pointerId !== e.pointerId) return;
            const { x, y } = this._canvasPoint(e);
            const { zoom } = this._geometry;
            this._pan.moved = true;
            this._setViewport(
                zoom,
                this._pan.originX - (x - this._pan.x) / zoom,
                this._pan.originY - (y - this._pan.y) / zoom,
            );
        });
        for (const ending of ["pointerup", "pointercancel"])
            canvas.addEventListener(ending, (e) => {
                if (this._pan?.pointerId !== e.pointerId) return;
                if (this._pan.moved) this._surfaceStale = true;
                this._pan = null;
            });
        canvas.addEventListener("dblclick", () => this._setViewport(1, 0, 0));
    }
 
    /** @returns {{x: number, y: number}} the event's position in canvas pixels */
    _canvasPoint(e) {
        const rect = this.overlayCanvas.getBoundingClientRect();
        const scale = this.overlayCanvas.width / rect.width;
        return { x: (e.clientX - rect.left) * scale, y: (e.clientY - rect.top) * scale };
    }
 
    _setViewport(zoom, originX, originY) {
        const was = { ...this._geometry };
        this._geometry.setView(zoom, originX, originY);
        Eif (
            was.zoom !== this._geometry.zoom ||
            was.originX !== this._geometry.originX ||
            was.originY !== this._geometry.originY
        )
            this._surfaceStale = true;
    }
 
    _bindChoice(selector, onClick) {
        for (const button of this.panel.querySelectorAll(selector))
            button.addEventListener("click", () => {
                onClick(button);
                this.update();
            });
    }
 
    get isOpen() {
        return this.floating.isOpen;
    }
 
    toggle() {
        this.floating.toggle();
    }
 
    open() {
        this.floating.open();
    }
 
    close() {
        this.floating.close();
    }
 
    /** Opens the panel showing the given drive's lower side. */
    openOn(driveIndex) {
        this._select(driveIndex, false);
        this.open();
        this.update();
    }
 
    _start() {
        window.addEventListener("resize", this._onResize);
        this._resize();
        this._tick();
    }
 
    _stop() {
        Eif (this._frameHandle !== null) cancelAnimationFrame(this._frameHandle);
        this._frameHandle = null;
        this._cancelScan();
        this._detach();
        this._hover = null;
        this._needsFullRepaint = true;
        window.removeEventListener("resize", this._onResize);
    }
 
    _tick() {
        this.update();
        this._frameHandle = requestAnimationFrame(() => this._tick());
    }
 
    /** Cheap enough to call every frame. */
    update() {
        if (!this.isOpen || !this._geometry) return;
        const disc = this._drive?.disc ?? null;
        Iif (this._isSideUpper && !disc?.isDoubleSided) this._select(this._driveIndex, false);
        if (disc !== this._disc) this._attach(disc);
        if (this._needsFullRepaint) this._beginFullRepaint();
        else if (this._surfaceStale) this._repaintSurface();
        else Iif (this._staleTracks.size && !this._scanning) this._repaintStaleTracks();
        this._drawOverlay();
        this._updateStatus();
    }
 
    get _drive() {
        return this._fdc.drives[this._driveIndex];
    }
 
    get _showingHead() {
        const drive = this._drive;
        return !!drive?.disc && drive.isSideUpper === this._isSideUpper;
    }
 
    get _scanning() {
        return this._geometry !== null && this._scanCursor <= this._geometry.numTracks;
    }
 
    _setView(view) {
        Iif (view === this._view || !Views[view]) return;
        this._view = view;
        this._needsFullRepaint = true;
        this._buildLegend();
    }
 
    _select(driveIndex, isSideUpper) {
        Iif (driveIndex === this._driveIndex && isSideUpper === this._isSideUpper) return;
        this._driveIndex = driveIndex;
        this._isSideUpper = isSideUpper;
        this._detach();
        this._needsFullRepaint = true;
    }
 
    _attach(disc) {
        this._detach();
        this._disc = disc;
        disc?.addTrackWriteListener(this._onTrackWrite);
        this._needsFullRepaint = true;
    }
 
    _detach() {
        this._disc?.removeTrackWriteListener(this._onTrackWrite);
        this._disc = null;
        this._staleTracks.clear();
    }
 
    _resize() {
        const size = Math.round(this.surfaceCanvas.clientWidth * (window.devicePixelRatio || 1));
        Iif (size <= 0 || size === this._geometry?.size) return;
        for (const canvas of [this.surfaceCanvas, this.overlayCanvas]) {
            canvas.width = size;
            canvas.height = size;
        }
        const previous = this._geometry;
        this._geometry = new DiscGeometry(size, IbmDiscFormat.tracksPerDisc);
        Iif (previous) this._geometry.adoptView(previous);
        this._imageData = this.surfaceCanvas.getContext("2d").createImageData(size, size);
        this._pixels = new Uint32Array(this._imageData.data.buffer);
        this._needsFullRepaint = true;
    }
 
    /** @returns {{codes: Uint8Array, sectorNumbers: Int16Array|null, errors: object[]|null}|null} */
    _analyse(trackNum) {
        if (!this._disc) return null;
        return Views[this._view].analyse(this._disc.getTrack(this._isSideUpper, trackNum), ignoreWarning);
    }
 
    _blit() {
        this.surfaceCanvas.getContext("2d").putImageData(this._imageData, 0, 0);
    }
 
    _beginFullRepaint() {
        this._needsFullRepaint = false;
        this._cancelScan();
        const count = this._geometry.numTracks;
        this._codes = new Array(count).fill(null);
        this._info = new Array(count).fill(null);
        this._scanCursor = 0;
        this._pixels.fill(0);
        this._advanceScan();
    }
 
    _cancelScan() {
        Iif (this._scanHandle !== null) cancelAnimationFrame(this._scanHandle);
        this._scanHandle = null;
    }
 
    /** Driven by requestAnimationFrame rather than the emulator's loop, so it completes while paused. */
    _advanceScan() {
        const count = this._geometry.numTracks;
        const deadline = performance.now() + ScanBudgetMs;
        do {
            if (this._scanCursor < count) this._analyseInto(this._scanCursor);
            // A track's edge pixels sample its neighbours, so paint one behind the scan.
            const paintTrack = this._scanCursor - 1;
            if (paintTrack >= 0)
                renderTracks(this._pixels, this._geometry, this._codes, this._palette, paintTrack, paintTrack);
            this._scanCursor++;
        } while (this._scanCursor <= count && performance.now() < deadline);
        this._blit();
        Iif (this._scanning) this._scanHandle = requestAnimationFrame(() => this._advanceScan());
        else this._scanHandle = null;
    }
 
    get _palette() {
        return Views[this._view].palette;
    }
 
    _repaintStaleTracks() {
        const deadline = performance.now() + ScanBudgetMs;
        for (const trackNum of this._staleTracks) {
            this._repaintTrack(trackNum);
            this._staleTracks.delete(trackNum);
            if (performance.now() >= deadline) break;
        }
        this._blit();
    }
 
    /** For when the view moved rather than the disc. */
    _repaintSurface() {
        this._surfaceStale = false;
        this._pixels.fill(0);
        // Mid-drag the whole surface is redrawn every frame, so trade smoothed edges for the frame rate.
        const supersample = this._pan ? 1 : undefined;
        const last = this._geometry.numTracks - 1;
        renderTracks(this._pixels, this._geometry, this._codes, this._palette, 0, last, supersample);
        this._blit();
    }
 
    _analyseInto(trackNum) {
        const analysis = this._analyse(trackNum);
        this._info[trackNum] = analysis;
        this._codes[trackNum] = analysis?.codes ?? null;
    }
 
    _repaintTrack(trackNum) {
        if (trackNum >= this._geometry.numTracks) return;
        this._analyseInto(trackNum);
        renderTracks(this._pixels, this._geometry, this._codes, this._palette, trackNum, trackNum);
    }
 
    _drawOverlay() {
        const geometry = this._geometry;
        const ctx = this.overlayCanvas.getContext("2d");
        const scale = window.devicePixelRatio || 1;
        ctx.clearRect(0, 0, geometry.size, geometry.size);
 
        const centreX = geometry.screenCentreX;
        const centreY = geometry.screenCentreY;
        ctx.lineWidth = scale;
        ctx.strokeStyle = `${IndexColour}44`;
        ctx.beginPath();
        ctx.arc(centreX, centreY, geometry.outerRadius * geometry.zoom, 0, 2 * Math.PI);
        ctx.moveTo(centreX + geometry.hubRadius * geometry.zoom, centreY);
        ctx.arc(centreX, centreY, geometry.hubRadius * geometry.zoom, 0, 2 * Math.PI);
        ctx.stroke();
        this._strokeRadial(ctx, 0, `${IndexColour}66`, scale);
 
        this._drawErrors(ctx, scale);
 
        const drive = this._drive;
        if (this._showingHead) {
            const track = Math.min(drive.track, geometry.numTracks - 1);
            const fraction = drive.positionFraction;
            ctx.globalAlpha = drive.spinning ? 1 : 0.45;
            ctx.strokeStyle = `${HeadColour}55`;
            ctx.lineWidth = Math.max(geometry.trackPitch * geometry.zoom, 2 * scale);
            ctx.beginPath();
            ctx.arc(centreX, centreY, geometry.screenRadiusOf(track), 0, 2 * Math.PI);
            ctx.stroke();
            this._strokeRadial(ctx, fraction, `${HeadColour}66`, scale);
            const { x, y } = geometry.pointAt(track, fraction);
            ctx.fillStyle = HeadColour;
            ctx.beginPath();
            ctx.arc(x, y, 3.5 * scale, 0, 2 * Math.PI);
            ctx.fill();
            ctx.globalAlpha = 1;
        }
 
        const hover = this._hoverPosition();
        if (hover) {
            ctx.strokeStyle = `${HoverColour}55`;
            ctx.lineWidth = scale;
            ctx.beginPath();
            ctx.arc(centreX, centreY, geometry.screenRadiusOf(hover.track), 0, 2 * Math.PI);
            ctx.stroke();
        }
    }
 
    _drawErrors(ctx, scale) {
        const geometry = this._geometry;
        const width = Math.max(geometry.trackPitch * geometry.zoom, 2.5 * scale);
        for (let trackNum = 0; trackNum < this._info.length; ++trackNum) {
            const info = this._info[trackNum];
            Eif (!info?.errors?.length) continue;
            const radius = geometry.screenRadiusOf(trackNum);
            for (const error of info.errors) {
                const start = error.firstWord / info.codes.length;
                let end = error.lastWord / info.codes.length;
                if (end <= start) end += 1;
                for (const [lineWidth, style] of [
                    [width + 3 * scale, MarkOutline],
                    [width, ErrorHex],
                ]) {
                    ctx.lineWidth = lineWidth;
                    ctx.strokeStyle = style;
                    ctx.beginPath();
                    ctx.arc(
                        geometry.screenCentreX,
                        geometry.screenCentreY,
                        radius,
                        geometry.angleOf(start),
                        geometry.angleOf(end),
                    );
                    ctx.stroke();
                }
            }
        }
    }
 
    _strokeRadial(ctx, fraction, style, scale) {
        const geometry = this._geometry;
        const angle = geometry.angleOf(fraction);
        const cos = Math.cos(angle);
        const sin = Math.sin(angle);
        const inner = geometry.innerRadius * geometry.zoom;
        const outer = geometry.outerRadius * geometry.zoom;
        ctx.strokeStyle = style;
        ctx.lineWidth = scale;
        ctx.beginPath();
        ctx.moveTo(geometry.screenCentreX + inner * cos, geometry.screenCentreY + inner * sin);
        ctx.lineTo(geometry.screenCentreX + outer * cos, geometry.screenCentreY + outer * sin);
        ctx.stroke();
    }
 
    /** @returns {{track: number, fraction: number}|null} */
    _hoverPosition() {
        return this._hover ? this._geometry.positionAt(this._hover.x, this._hover.y) : null;
    }
 
    _updateStatus() {
        const drive = this._drive;
        const disc = drive?.disc;
        this.sideControls.hidden = !disc?.isDoubleSided;
        this._markActive("[data-drive]", (button) => Number(button.dataset.drive) === this._driveIndex);
        this._markActive("[data-side]", (button) => (button.dataset.side === "1") === this._isSideUpper);
        this._markActive("[data-view]", (button) => button.dataset.view === this._view);
 
        const name = disc?.name ?? "";
        setText(this.nameElem, name);
        if (this.nameElem.title !== name) this.nameElem.title = name;
        if (!disc) {
            setText(this.statusElem, `Drive ${this._driveIndex}: no disc`);
        } else {
            const head = this._showingHead
                ? `head track ${drive.track} · ${(drive.positionFraction * RevolutionMs).toFixed(1)} ms`
                : `head track ${drive.track}, other side`;
            const spin = drive.spinning ? "spinning" : "stopped";
            const zoom = this._geometry.zoom > 1 ? ` · ${this._geometry.zoom.toFixed(1)}x` : "";
            setText(this.statusElem, `${spin} · ${head}${zoom}${this._scanNote()}`);
        }
        const { where, what } = this._describeHover();
        setText(this.hoverWhereElem, where);
        setText(this.hoverWhatElem, what);
    }
 
    _markActive(selector, isActive) {
        for (const button of this.panel.querySelectorAll(selector)) button.classList.toggle("active", isActive(button));
    }
 
    _scanNote() {
        Iif (this._scanning) return " · reading surface…";
        const errors = this._info.reduce((count, info) => count + (info?.errors?.length ?? 0), 0);
        Eif (!errors) return "";
        return ` · ${errors} CRC error${errors === 1 ? "" : "s"}`;
    }
 
    /** @returns {{where: string, what: string}} the pointer's position, and what the surface holds */
    _describeHover() {
        const hover = this._hoverPosition();
        if (!hover) return { where: "Point at the surface to read it", what: "" };
        const info = this._info[hover.track];
        Iif (!info?.codes?.length) return { where: `Track ${hover.track}`, what: "not read yet" };
        const word = Math.min((hover.fraction * info.codes.length) | 0, info.codes.length - 1);
        const ms = (hover.fraction * RevolutionMs).toFixed(1);
        return {
            where: `Track ${hover.track} · word ${word} of ${info.codes.length} · ${ms} ms`,
            what: Views[this._view].describe(info, word),
        };
    }
 
    _buildLegend() {
        this.legendElem.innerHTML = Views[this._view].legend();
    }
}