Skip to content

Commit

Permalink
refactor: rename classes
Browse files Browse the repository at this point in the history
  • Loading branch information
seankmartin committed Sep 3, 2024
1 parent 7fbbf88 commit c6dca6c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
40 changes: 18 additions & 22 deletions src/ui/screenshot_menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import "#src/ui/screenshot_menu.css";
import { ScreenshotMode } from "#src/util/trackable_screenshot_mode.js";
import type { Viewer } from "#src/viewer.js";

const friendlyNameMap = {
const statisticsNamesForUI = {
chunkUsageDescription: "Number of loaded chunks",
gpuMemoryUsageDescription: "Visible chunk GPU memory usage",
downloadSpeedDescription: "Number of downloading chunks",
Expand Down Expand Up @@ -78,13 +78,13 @@ export class ScreenshotDialog extends Overlay {

private setupEventListeners() {
this.registerDisposer(
this.viewer.screenshotActionHandler.sendScreenshotRequested.add(() => {
this.viewer.screenshotHandler.sendScreenshotRequested.add(() => {
this.debouncedUpdateUIElements();
this.dispose();
}),
);
this.registerDisposer(
this.viewer.screenshotActionHandler.sendStatisticsRequested.add(() => {
this.viewer.screenshotHandler.sendStatisticsRequested.add(() => {
this.populateStatistics();
}),
);
Expand All @@ -98,14 +98,6 @@ export class ScreenshotDialog extends Overlay {
return (this.nameInput = nameInput);
}

private updateStatisticsTableDisplayBasedOnMode() {
if (this.screenshotMode === ScreenshotMode.OFF) {
this.statisticsContainer.style.display = "none";
} else {
this.statisticsContainer.style.display = "block";
}
}

private createButton(
text: string,
onClick: () => void,
Expand Down Expand Up @@ -136,7 +128,7 @@ export class ScreenshotDialog extends Overlay {
input.type = "radio";
input.name = "screenshot-scale";
input.value = scale.toString();
input.checked = scale === this.screenshotHandler.screenshotScale;
input.checked = scale === this.viewer.screenshotManager.screenshotScale;
input.classList.add("neuroglancer-screenshot-scale-radio");

label.appendChild(input);
Expand All @@ -145,7 +137,7 @@ export class ScreenshotDialog extends Overlay {
scaleMenu.appendChild(label);

input.addEventListener("change", () => {
this.screenshotHandler.screenshotScale = scale;
this.viewer.screenshotManager.screenshotScale = scale;
});
});
return scaleMenu;
Expand Down Expand Up @@ -173,7 +165,7 @@ export class ScreenshotDialog extends Overlay {
headerRow.appendChild(valueHeader);

// Populate inital table elements with placeholder text
const statsRow = this.screenshotHandler.screenshotStatistics;
const statsRow = this.viewer.screenshotManager.screenshotStatistics;
for (const key in statsRow) {
if (key === "timeElapsedString") {
continue;
Expand All @@ -182,7 +174,7 @@ export class ScreenshotDialog extends Overlay {
const keyCell = row.insertCell();
const valueCell = row.insertCell();
keyCell.textContent =
friendlyNameMap[key as keyof typeof friendlyNameMap];
statisticsNamesForUI[key as keyof typeof statisticsNamesForUI];
valueCell.textContent = "Loading...";
this.statisticsKeyToCellMap.set(key, valueCell);
}
Expand All @@ -194,18 +186,26 @@ export class ScreenshotDialog extends Overlay {
}

private forceScreenshot() {
this.screenshotHandler.forceScreenshot();
this.viewer.screenshotManager.forceScreenshot();
this.debouncedUpdateUIElements();
}

private screenshot() {
const filename = this.nameInput.value;
this.screenshotHandler.takeScreenshot(filename);
this.viewer.screenshotManager.takeScreenshot(filename);
this.debouncedUpdateUIElements();
}

private updateStatisticsTableDisplayBasedOnMode() {
if (this.screenshotMode === ScreenshotMode.OFF) {
this.statisticsContainer.style.display = "none";
} else {
this.statisticsContainer.style.display = "block";
}
}

private populateStatistics() {
const statsRow = this.screenshotHandler.screenshotStatistics;
const statsRow = this.viewer.screenshotManager.screenshotStatistics;

for (const key in statsRow) {
if (key === "timeElapsedString") {
Expand Down Expand Up @@ -242,8 +242,4 @@ export class ScreenshotDialog extends Overlay {
this.scaleSelectContainer.style.display = "none";
}
}

get screenshotHandler() {
return this.viewer.screenshotHandler;
}
}
8 changes: 4 additions & 4 deletions src/util/screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async function extractViewportScreenshot(
return croppedBlob;
}

export class ScreenshotFromViewer extends RefCounted {
export class ScreenshotManager extends RefCounted {
public screenshotId: number = -1;
public screenshotScale: number = 1;
private filename: string = "";
Expand All @@ -179,14 +179,14 @@ export class ScreenshotFromViewer extends RefCounted {
super();
this.viewer = viewer;
this.registerDisposer(
this.viewer.screenshotActionHandler.sendScreenshotRequested.add(
this.viewer.screenshotHandler.sendScreenshotRequested.add(
(actionState) => {
this.saveScreenshot(actionState);
},
),
);
this.registerDisposer(
this.viewer.screenshotActionHandler.sendStatisticsRequested.add(
this.viewer.screenshotHandler.sendStatisticsRequested.add(
(actionState) => {
this.persistStatisticsData(actionState);
this.checkAndHandleStalledScreenshot(actionState);
Expand Down Expand Up @@ -243,7 +243,7 @@ export class ScreenshotFromViewer extends RefCounted {

// Pass a new screenshot ID to the viewer to trigger a new screenshot.
this.screenshotId++;
this.viewer.screenshotActionHandler.requestState.value =
this.viewer.screenshotHandler.requestState.value =
this.screenshotId.toString();

// Force handling the canvas size change
Expand Down
7 changes: 4 additions & 3 deletions src/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ import {
EventActionMap,
KeyboardEventBinder,
} from "#src/util/keyboard_bindings.js";
import { ScreenshotFromViewer } from "#src/util/screenshot.js";
import { ScreenshotManager } from "#src/util/screenshot.js";
import { NullarySignal } from "#src/util/signal.js";
import {
CompoundTrackable,
Expand Down Expand Up @@ -491,8 +491,8 @@ export class Viewer extends RefCounted implements ViewerState {

resetInitiated = new NullarySignal();

screenshotActionHandler = this.registerDisposer(new ScreenshotHandler(this));
screenshotHandler = this.registerDisposer(new ScreenshotFromViewer(this));
screenshotHandler = this.registerDisposer(new ScreenshotHandler(this));
screenshotManager = this.registerDisposer(new ScreenshotManager(this));

get chunkManager() {
return this.dataContext.chunkManager;
Expand Down Expand Up @@ -572,6 +572,7 @@ export class Viewer extends RefCounted implements ViewerState {
this.display.applyWindowedViewportToElement(element, value);
}, this.partialViewport),
);

this.registerDisposer(() => removeFromParent(this.element));

this.dataContext = this.registerDisposer(dataContext);
Expand Down

0 comments on commit c6dca6c

Please sign in to comment.