Skip to content

Commit

Permalink
Fix/example build (#437)
Browse files Browse the repository at this point in the history
* update node version

* fix errors

* remove null agent export and format

* revert change

* make sure to send a copy

* check for null

* Update src/visGeometry/index.ts

Co-authored-by: Peyton Lee <[email protected]>

---------

Co-authored-by: Peyton Lee <[email protected]>
  • Loading branch information
meganrm and ShrimpCryptid authored Jan 15, 2025
1 parent e0c98a7 commit 852e5bd
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 76 deletions.
70 changes: 35 additions & 35 deletions .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
name: github pages

on:
schedule:
- cron: "0 0 * * *"
schedule:
- cron: "0 0 * * *"

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "16.x"
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "20.x"

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run gh-build
- name: Prepare tag
id: prepare_tag
if: startsWith(github.ref, 'refs/tags/')
run: |
TAG_NAME="${GITHUB_REF##refs/tags/}"
echo "::set-output name=tag_name::${TAG_NAME}"
echo "::set-output name=deploy_tag_name::deploy-${TAG_NAME}"
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
tag_name: ${{ steps.prepare_tag.outputs.deploy_tag_name }}
tag_message: 'Deployment to gh-pages to test new viewer ${{ steps.prepare_tag.outputs.tag_name }}'
- name: Cache dependencies

uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run gh-build
- name: Prepare tag
id: prepare_tag
if: startsWith(github.ref, 'refs/tags/')
run: |
TAG_NAME="${GITHUB_REF##refs/tags/}"
echo "::set-output name=tag_name::${TAG_NAME}"
echo "::set-output name=deploy_tag_name::deploy-${TAG_NAME}"
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
tag_name: ${{ steps.prepare_tag.outputs.deploy_tag_name }}
tag_message: "Deployment to gh-pages to test new viewer ${{ steps.prepare_tag.outputs.tag_name }}"
6 changes: 3 additions & 3 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions examples/src/Components/AgentMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface AgentMetadataProps {
}

const AgentMetadata = ({ agentData }: AgentMetadataProps): JSX.Element => {
if (agentData.instanceId === -1) {
if (!agentData || agentData.instanceId === -1) {
return <div className="ui-container">No agent selected</div>;
}
return (
Expand All @@ -15,7 +15,8 @@ const AgentMetadata = ({ agentData }: AgentMetadataProps): JSX.Element => {
<div> uniqueID: {agentData.instanceId}</div>
<div> agentType: {agentData.type}</div>
<div>
position: x = {agentData.x}, y = {agentData.y}, z = {agentData.z}
position: x = {agentData.x}, y = {agentData.y}, z ={" "}
{agentData.z}
</div>
<div>
rotation: x = {agentData.xrot}, y = {agentData.yrot}, z ={" "}
Expand Down
5 changes: 2 additions & 3 deletions examples/src/Viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { isEqual, findIndex, reduce } from "lodash";
import { isEqual, findIndex, reduce, map } from "lodash";
import { v4 as uuidv4 } from "uuid";
import { InputParams } from "tweakpane";

Expand All @@ -12,7 +12,6 @@ import SimulariumViewer, {
ErrorLevel,
NetConnectionParams,
TrajectoryFileInfo,
nullAgent,
TrajectoryType,
} from "@aics/simularium-viewer";
import type {
Expand Down Expand Up @@ -119,7 +118,7 @@ const initialState: ViewerState = {
trajectoryTitle: "",
initialPlay: true,
firstFrameTime: 0,
followObjectData: nullAgent(),
followObjectData: null,
};

class Viewer extends React.Component<InputParams, ViewerState> {
Expand Down
11 changes: 8 additions & 3 deletions examples/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const webpack = require('webpack');
const webpack = require("webpack");

module.exports = {
entry: "./src/index.tsx",
Expand All @@ -28,11 +28,13 @@ module.exports = {
],
}),
new webpack.DefinePlugin({
SIMULARIUM_USE_LOCAL_BACKEND: Boolean(process.env.npm_config_localserver),
SIMULARIUM_USE_LOCAL_BACKEND: Boolean(
process.env.npm_config_localserver
),
}),
],
devServer: {
devMiddleware:{
devMiddleware: {
publicPath: "/public/",
},
open: ["public/"],
Expand All @@ -48,6 +50,9 @@ module.exports = {
loader: "babel-loader",
},
],
resolve: {
fullySpecified: false,
},
},
{
test: /\.css/,
Expand Down
16 changes: 0 additions & 16 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,6 @@ export const enum TrajectoryType {

export const DEFAULT_FRAME_RATE = 60; // frames per second

export const nullAgent = (): AgentData => {
return {
visType: -1,
instanceId: -1,
type: -1,
x: 0,
y: 0,
z: 0,
xrot: 0,
yrot: 0,
zrot: 0,
cr: 0,
subpoints: [],
};
};

// the size of the header before the agent data in the binary file
export const AGENT_HEADER_SIZE = 3; // frameNumber, time, agentCount

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export {
ClientMessageEnum,
} from "./simularium/index.js";
export { compareTimes, loadSimulariumFile } from "./util.js";
export { DEFAULT_CAMERA_SPEC, nullAgent, TrajectoryType } from "./constants.js";
export { DEFAULT_CAMERA_SPEC, TrajectoryType } from "./constants.js";

export default Viewport;
4 changes: 2 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
AgentData,
CachedFrame,
} from "./simularium/types.js";
import { nullAgent } from "./constants.js";
import { FrontEndError } from "./simularium/index.js";
import VisGeometry from "./visGeometry/index.js";

export const compareTimes = (
time1: number,
Expand Down Expand Up @@ -102,7 +102,7 @@ export const getAgentDataFromBuffer = (
"Invalid offset: Not enough data in the buffer for agent data."
);
}
const agentData: AgentData = nullAgent();
const agentData: AgentData = VisGeometry.getNullAgent();
for (let i = 0; i < AGENT_OBJECT_KEYS.length; i++) {
agentData[AGENT_OBJECT_KEYS[i]] = view[offset + i];
}
Expand Down
18 changes: 9 additions & 9 deletions src/viewport/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faSyncAlt } from "@fortawesome/free-solid-svg-icons";
import { forOwn, isEqual } from "lodash";

import SimulariumController from "../controller/index.js"
import SimulariumController from "../controller/index.js";
import {
TrajectoryFileInfo,
SelectionInterface,
SelectionStateInfo,
UIDisplayData,
} from "../simularium/index.js"
import { AgentData, TrajectoryFileInfoAny } from "../simularium/types.js"
import { updateTrajectoryFileInfoFormat } from "../simularium/versionHandlers.js"
import { FrontEndError, ErrorLevel } from "../simularium/FrontEndError.js"
import { RenderStyle, VisGeometry, NO_AGENT } from "../visGeometry/index.js"
import { ColorAssignment } from "../visGeometry/types.js"
import FrameRecorder from "../simularium/FrameRecorder.js"
import { DEFAULT_FRAME_RATE } from "../constants.js"
} from "../simularium/index.js";
import { AgentData, TrajectoryFileInfoAny } from "../simularium/types.js";
import { updateTrajectoryFileInfoFormat } from "../simularium/versionHandlers.js";
import { FrontEndError, ErrorLevel } from "../simularium/FrontEndError.js";
import { RenderStyle, VisGeometry, NO_AGENT } from "../visGeometry/index.js";
import { ColorAssignment } from "../visGeometry/types.js";
import FrameRecorder from "../simularium/FrameRecorder.js";
import { DEFAULT_FRAME_RATE } from "../constants.js";

export type PropColor = string | number | [number, number, number];

Expand Down
24 changes: 22 additions & 2 deletions src/visGeometry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import { FrontEndError, ErrorLevel } from "../simularium/FrontEndError.js";
import {
DEFAULT_CAMERA_Z_POSITION,
DEFAULT_CAMERA_SPEC,
nullAgent,
AGENT_HEADER_SIZE,
} from "../constants.js";
import {
Expand Down Expand Up @@ -95,6 +94,20 @@ const MIN_ZOOM = 0.16;
const CANVAS_INITIAL_WIDTH = 100;
const CANVAS_INITIAL_HEIGHT = 100;

const NULL_AGENT = {
visType: -1,
instanceId: NO_AGENT,
type: -1,
x: 0,
y: 0,
z: 0,
xrot: 0,
yrot: 0,
zrot: 0,
cr: 0,
subpoints: [],
};

export enum RenderStyle {
WEBGL1_FALLBACK,
WEBGL2_PREFERRED,
Expand All @@ -115,6 +128,9 @@ const coordsToVector = ({ x, y, z }: Coordinates3d) => new Vector3(x, y, z);
type Bounds = readonly [number, number, number, number, number, number];

class VisGeometry {
static getNullAgent(): AgentData {
return { ...NULL_AGENT };
}
public onError: (error: FrontEndError) => void;
public renderStyle: RenderStyle;
public backgroundColor: Color;
Expand Down Expand Up @@ -667,9 +683,13 @@ class VisGeometry {
}

public getObjectData(id: number): AgentData {
if (id === NO_AGENT) {
// initial state
return VisGeometry.getNullAgent();
}
const data = this.visAgentInstances.get(id);
if (!data) {
return nullAgent();
return VisGeometry.getNullAgent();
}
return data.agentData;
}
Expand Down

0 comments on commit 852e5bd

Please sign in to comment.