Skip to content

Commit

Permalink
Merge branch 'main' into new-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Sep 21, 2024
2 parents e776abd + c1da76c commit a814377
Show file tree
Hide file tree
Showing 34 changed files with 1,210 additions and 544 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,25 @@ jobs:
with:
node-version: "20.x"
cache: "npm"
- name: Setup Emscripten
uses: mymindstorm/setup-emsdk@v14
- name: Install Node.js dependencies
run: npm ci
env:
ASCOPE_NO_FFMPEG: true
- name: Check formatting
run: npm run check-format
- name: Compile WebAssembly
run: mkdir bundles; npm run wasm:compile
- name: Compile bundles (FRC 6328)
run: npm run compile
- name: Upload bundles (FRC 6328)
uses: actions/upload-artifact@v4
with:
name: bundles
path: bundles/*.js
path: |
bundles/*.js
bundles/*.wasm
- name: Compile bundles (WPILib)
run: npm run compile
env:
Expand All @@ -44,7 +50,9 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: bundles-wpilib
path: bundles/*.js
path: |
bundles/*.js
bundles/*.wasm
build-win:
name: Build for Windows (${{ matrix.arch }})
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"C_Cpp.clang_format_style": "Google",
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.formatOnType": true,
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ Feedback, feature requests, and bug reports are welcome on the [issues page](htt

## Building

To install all dependencies, run:
To install Node.js dependencies, run:

```bash
npm install
```

[Emscripten](https://emscripten.org) also needs to be installed (instructions [here](https://emscripten.org/docs/getting_started/downloads.html)).

To build for the current platform, run:

```bash
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
"scripts": {
"start": "electron bundles/main.js",
"compile": "rollup -c --configMain && rollup -c --configLargeRenderers && rollup -c --configSmallRenderers && rollup -c --configWorkers",
"build": "npm run compile && npm run docs:build-embed && electron-builder build",
"fast-build": "npm run compile && npm run docs:build-embed && electron-builder build --dir",
"build": "npm run compile && npm run wasm:compile && npm run docs:build-embed && electron-builder build",
"fast-build": "npm run compile && npm run wasm:compile && npm run docs:build-embed && electron-builder build --dir",
"watch": "rollup -c -w",
"format": "prettier --write .",
"check-format": "prettier --check .",
"test-ytdl": "node testYtdl.mjs",
"wasm:compile": "emcc src/hub/dataSources/wpilog/indexer/wpilogIndexer.c -o bundles/hub\\$wpilogIndexer.js -sEXPORTED_FUNCTIONS=_run,_malloc -sALLOW_MEMORY_GROWTH -O3",
"docs:start": "cd docsSite && npm run start && cd ..",
"docs:build": "cd docsSite && npm run build && cd ..",
"docs:build-embed": "cd docsSite && npm run build-embed && cd ..",
Expand Down Expand Up @@ -65,6 +66,7 @@
},
"dependencies": {
"@distube/ytdl-core": "^4.14.4",
"@types/emscripten": "^1.39.13",
"check-disk-space": "^3.4.0",
"download": "^8.0.0",
"electron-fetch": "^1.9.1",
Expand Down
44 changes: 39 additions & 5 deletions src/hub/Sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import LogFieldTree from "../shared/log/LogFieldTree";
import LoggableType from "../shared/log/LoggableType";
import { getOrDefault, searchFields, TYPE_KEY } from "../shared/log/LogUtil";
import { SelectionMode } from "../shared/Selection";
import { arraysEqual, setsEqual } from "../shared/util";
import { arraysEqual, htmlEncode, setsEqual } from "../shared/util";
import { ZEBRA_LOG_KEY } from "./dataSources/LoadZebra";
import CustomSchemas from "./dataSources/schema/CustomSchemas";

Expand Down Expand Up @@ -47,6 +47,7 @@ export default class Sidebar {
private FIELD_DRAG_THRESHOLD_PX = 3;
private VALUE_WIDTH_MARGIN_PX = 12;

private getFilenames: () => string[];
private sidebarHandleActive = false;
private sidebarWidth = this.DEFAULT_SIDEBAR_WIDTH;
private fieldCount = 0;
Expand All @@ -67,8 +68,11 @@ export default class Sidebar {
private tuningModePublishCallbacks: (() => void)[] = [];
private tuningValueCache: { [key: string]: string } = {};
private updateMetadataCallbacks: (() => void)[] = [];
private updateLoadingCallbacks: (() => void)[] = [];

constructor(getFilenames: () => string[]) {
this.getFilenames = getFilenames;

constructor() {
// Set up handle for resizing
let enableIframes = (enabled: boolean) => {
Array.from(document.getElementsByTagName("iframe")).forEach((iframe) => {
Expand Down Expand Up @@ -433,6 +437,7 @@ export default class Sidebar {
// Update type warnings and metadata
this.updateTypeWarningCallbacks.forEach((callback) => callback());
this.updateMetadataCallbacks.forEach((callback) => callback());
this.updateLoadingCallbacks.forEach((callback) => callback());
}
}

Expand Down Expand Up @@ -573,7 +578,20 @@ export default class Sidebar {
let typeLabel = document.createElement("span");
typeLabel.classList.add("field-item-type-label");
label.appendChild(typeLabel);
typeLabel.innerHTML = " – " + structuredType;
typeLabel.innerHTML = " – " + htmlEncode(structuredType);
}
} else {
if (title.startsWith(this.MERGED_KEY) && indent === 0) {
let mergeIndex = Number(title.slice(this.MERGED_KEY.length));
let mergedFilenames = this.getFilenames();
if (mergeIndex < mergedFilenames.length) {
let filename = mergedFilenames[mergeIndex];

let typeLabel = document.createElement("span");
typeLabel.classList.add("field-item-type-label");
label.appendChild(typeLabel);
typeLabel.innerHTML = " &ndash; " + htmlEncode(filename);
}
}
}

Expand Down Expand Up @@ -886,6 +904,18 @@ export default class Sidebar {
};
this.updateMetadataCallbacks.push(updateMetadata);
updateMetadata();

// Loading callback
let updateLoading = () => {
let isLoading = window.getLoadingFields().has(field.fullKey!);
if (isLoading) {
label.classList.add("loading");
} else {
label.classList.remove("loading");
}
};
this.updateLoadingCallbacks.push(updateLoading);
updateLoading();
}

// Add children
Expand Down Expand Up @@ -978,7 +1008,11 @@ export default class Sidebar {

/** Returns the set of field keys that are currently visible. */
getActiveFields(): Set<string> {
this.activeFieldCallbacks.forEach((callback) => callback());
return this.activeFields;
if (this.sidebarWidth > 0) {
this.activeFieldCallbacks.forEach((callback) => callback());
return this.activeFields;
} else {
return new Set();
}
}
}
16 changes: 8 additions & 8 deletions src/hub/SourceList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SourceListTypeMemoryEntry
} from "../shared/SourceListConfig";
import {
grabChassiSpeeds as grabChassisSpeeds,
grabChassisSpeeds,
grabPosesAuto,
grabSwerveStates,
rotation3dTo2d,
Expand Down Expand Up @@ -802,16 +802,17 @@ export default class SourceList {
// Hide button
let hideButton = item.getElementsByClassName("hide")[0] as HTMLButtonElement;
let toggleHidden = () => {
if (isChild) return;
let index = Array.from(this.LIST.children).indexOf(item);
let newVisible = !this.state[index].visible;
this.state[index].visible = newVisible;
this.updateItem(item, this.state[index]);
while (index < this.state.length) {
index++;
if (!this.isChild(index)) break;
this.state[index].visible = newVisible;
this.updateItem(this.LIST.children[index] as HTMLElement, this.state[index]);
if (!isChild) {
while (index < this.state.length) {
index++;
if (!this.isChild(index)) break;
this.state[index].visible = newVisible;
this.updateItem(this.LIST.children[index] as HTMLElement, this.state[index]);
}
}
};
hideButton.addEventListener("click", (event) => {
Expand All @@ -833,7 +834,6 @@ export default class SourceList {

// Child formatting
if (isChild) {
hideButton.hidden = true;
item.classList.add("child");
}

Expand Down
9 changes: 9 additions & 0 deletions src/hub/Tabs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TabsState } from "../shared/HubState";
import LineGraphFilter from "../shared/LineGraphFilter";
import TabType, { getDefaultTabTitle, getTabIcon } from "../shared/TabType";
import { getAutonomousKey, getEnabledKey } from "../shared/log/LogUtil";
import ConsoleRenderer from "../shared/renderers/ConsoleRenderer";
import DocumentationRenderer from "../shared/renderers/DocumentationRenderer";
import JoysticksRenderer from "../shared/renderers/JoysticksRenderer";
Expand Down Expand Up @@ -430,6 +431,14 @@ export default class Tabs {
activeFields.add(field);
});
});
let enabledKey = getEnabledKey(window.log);
if (enabledKey !== undefined) {
activeFields.add(enabledKey);
}
let autonomousKey = getAutonomousKey(window.log);
if (autonomousKey !== undefined) {
activeFields.add(autonomousKey);
}
return activeFields;
}

Expand Down
6 changes: 6 additions & 0 deletions src/hub/Timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export default class Timeline {
this.grabZoomActive = false;
}
});
this.SCROLL_OVERLAY.addEventListener("mouseleave", () => {
if (this.grabZoomActive) {
window.selection.setGrabZoomRange(null);
this.grabZoomActive = false;
}
});
this.SCROLL_OVERLAY.addEventListener("click", (event) => {
if (Math.abs(event.clientX - this.SCROLL_OVERLAY.getBoundingClientRect().x - this.mouseDownX) <= 5) {
let hoveredTime = window.selection.getHoveredTime();
Expand Down
39 changes: 38 additions & 1 deletion src/hub/controllers/LineGraphController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ensureThemeContrast } from "../../shared/Colors";
import LineGraphFilter from "../../shared/LineGraphFilter";
import { SourceListState } from "../../shared/SourceListConfig";
import { getEnabledKey, getLogValueText } from "../../shared/log/LogUtil";
import { AKIT_TIMESTAMP_KEYS, getEnabledKey, getLogValueText } from "../../shared/log/LogUtil";
import { LogValueSetNumber } from "../../shared/log/LogValueSets";
import {
LineGraphRendererCommand,
LineGraphRendererCommand_DiscreteField,
Expand Down Expand Up @@ -281,6 +282,11 @@ export default class LineGraphController implements TabController {

// Add numeric fields
this.numericCommandCache = {};
const akitTimestampField = window.log.getFieldKeys().find((key) => AKIT_TIMESTAMP_KEYS.includes(key));
const akitTimestamps =
akitTimestampField === undefined
? undefined
: window.log.getNumber(akitTimestampField, -Infinity, Infinity)?.timestamps;
let addNumeric = (
source: SourceListState,
dataRange: [number, number],
Expand All @@ -296,6 +302,37 @@ export default class LineGraphController implements TabController {
);
if (data === undefined) return;

// Add AdvantageKit samples
if (akitTimestamps !== undefined) {
switch (fieldItem.type) {
case "stepped":
// Extra samples wouldn't affect rendering
break;
case "smooth":
case "points":
let newData: LogValueSetNumber = { timestamps: [], values: [] };
let sourceIndex = 0;
let akitIndex = akitTimestamps.findIndex((akitTime) => akitTime >= data!.timestamps[0]);
while (
akitIndex < akitTimestamps.length &&
akitTimestamps[akitIndex] <= data!.timestamps[data!.timestamps.length - 1]
) {
while (
sourceIndex < data!.timestamps.length - 1 &&
akitTimestamps[akitIndex] >= data!.timestamps[sourceIndex + 1]
) {
sourceIndex++;
}
newData.timestamps.push(akitTimestamps[akitIndex]);
newData.values.push(data!.values[sourceIndex]);
akitIndex++;
}
console.log(newData.timestamps);
data = newData;
break;
}
}

// Apply filter
switch (filter) {
case LineGraphFilter.Differentiate:
Expand Down
4 changes: 2 additions & 2 deletions src/hub/controllers/SwerveController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SourceListState } from "../../shared/SourceListConfig";
import { Rotation2d, grabChassiSpeeds, grabPosesAuto, grabSwerveStates, rotation3dTo2d } from "../../shared/geometry";
import { Rotation2d, grabChassisSpeeds, grabPosesAuto, grabSwerveStates, rotation3dTo2d } from "../../shared/geometry";
import { Orientation } from "../../shared/renderers/OdometryRenderer";
import { SwerveRendererCommand } from "../../shared/renderers/SwerveRenderer";
import { clampValue, createUUID } from "../../shared/util";
Expand Down Expand Up @@ -132,7 +132,7 @@ export default class SwerveController implements TabController {
color: source.options.color
});
} else if (source.type === "chassisSpeeds") {
let speeds = grabChassiSpeeds(window.log, source.logKey, time, this.UUID);
let speeds = grabChassisSpeeds(window.log, source.logKey, time, this.UUID);
let angle = Math.atan2(speeds.vy, speeds.vx);
let length = Math.hypot(speeds.vx, speeds.vy);
length = clampValue(length / Number(this.MAX_SPEED.value), -1, 1);
Expand Down
Loading

0 comments on commit a814377

Please sign in to comment.