Skip to content

Commit

Permalink
code cleanup: dragAndDrop and JSON caching code (#409)
Browse files Browse the repository at this point in the history
* remove unused drag and drop code

* remove unused JSON caching code

* clean up linting errors
  • Loading branch information
interim17 authored Sep 11, 2024
1 parent aa39b39 commit eb10973
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 87 deletions.
17 changes: 1 addition & 16 deletions src/controller/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import jsLogger from "js-logger";
import { isEmpty, noop } from "lodash";
import { VisData, RemoteSimulator } from "../simularium";
import type {
NetConnectionParams,
TrajectoryFileInfo,
VisDataMessage,
} from "../simularium";
import type { NetConnectionParams, TrajectoryFileInfo } from "../simularium";
import { VisGeometry } from "../visGeometry";
import {
FileReturn,
Expand Down Expand Up @@ -489,21 +485,10 @@ export default class SimulariumController {
}
}

public cacheJSON(json: VisDataMessage): void {
this.visData.cacheJSON(json);
}

public clearLocalCache(): void {
this.visData.clearCache();
}

public get dragAndDropFileInfo(): TrajectoryFileInfo | null {
return this.visData.dragAndDropFileInfo;
}
public set dragAndDropFileInfo(fileInfo: TrajectoryFileInfo | null) {
this.visData.dragAndDropFileInfo = fileInfo;
}

public set trajFileInfoCallback(
callback: (msg: TrajectoryFileInfo) => void
) {
Expand Down
71 changes: 0 additions & 71 deletions src/simularium/VisData.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { difference } from "lodash";

import { compareTimes } from "../util";

import * as util from "./ThreadUtil";
import {
AGENT_OBJECT_KEYS,
AgentData,
FrameData,
TrajectoryFileInfo,
EncodedTypeMapping,
VisDataMessage,
} from "./types";
import { FrontEndError, ErrorLevel } from "./FrontEndError";
Expand All @@ -26,9 +22,6 @@ class VisData {
private lockedForFrame: boolean;
private cacheFrame: number;

// eslint-disable-next-line @typescript-eslint/naming-convention
private _dragAndDropFileInfo: TrajectoryFileInfo | null;

public timeStepSize: number;

private static parseOneBinaryFrame(data: ArrayBuffer): ParsedBundle {
Expand Down Expand Up @@ -109,7 +102,6 @@ class VisData {
this.frameDataCache = [];
this.cacheFrame = -1;
this.enableCache = true;
this._dragAndDropFileInfo = null;
this.frameToWaitFor = 0;
this.lockedForFrame = false;
this.timeStepSize = 0;
Expand Down Expand Up @@ -206,7 +198,6 @@ class VisData {
this.frameCache = [];
this.frameDataCache = [];
this.cacheFrame = -1;
this._dragAndDropFileInfo = null;
this.frameToWaitFor = 0;
this.lockedForFrame = false;
}
Expand Down Expand Up @@ -312,68 +303,6 @@ class VisData {

this.parseAgentsFromFrameData(msg);
}

// for use w/ a drag-and-drop trajectory file
// save a file for playback
// will be caught by controller.changeFile(...).catch()
public cacheJSON(visDataMsg: VisDataMessage): void {
if (this.frameCache.length > 0) {
throw new Error(
"cache not cleared before cacheing a new drag-and-drop file"
);
}

const frames = parseVisDataMessage(visDataMsg);
this.addFramesToCache(frames);
}

public set dragAndDropFileInfo(fileInfo: TrajectoryFileInfo | null) {
if (!fileInfo) return;
// NOTE: this may be a temporary check as we're troubleshooting new file formats
const missingIds = this.checkTypeMapping(fileInfo.typeMapping);

if (missingIds.length) {
const include = confirm(
`Your file typeMapping is missing names for the following type ids: ${missingIds}. Do you want to include them in the interactive interface?`
);
if (include) {
missingIds.forEach((id) => {
fileInfo.typeMapping[id] = { name: id.toString() };
});
}
}
this._dragAndDropFileInfo = fileInfo;
}

public get dragAndDropFileInfo(): TrajectoryFileInfo | null {
if (!this._dragAndDropFileInfo) {
return null;
}
return this._dragAndDropFileInfo;
}

// will be caught by controller.changeFile(...).catch()
// TODO: check if this code is still used
public checkTypeMapping(typeMappingFromFile: EncodedTypeMapping): number[] {
if (!typeMappingFromFile) {
throw new Error(
"data needs 'typeMapping' object to display agent controls"
);
}
const idsInFrameData = new Set();
const idsInTypeMapping = Object.keys(typeMappingFromFile).map(Number);

if (this.frameCache.length === 0) {
console.log("no data to check type mapping against");
return [];
}

this.frameCache.forEach((element) => {
element.map((agent) => idsInFrameData.add(agent.type));
});
const idsArr: number[] = [...idsInFrameData].sort() as number[];
return difference(idsArr, idsInTypeMapping).sort();
}
}

export { VisData };
Expand Down

0 comments on commit eb10973

Please sign in to comment.