Skip to content

Commit 3b64000

Browse files
committed
misc cleanup/fixes; re-enable rangeslider setting viewinterval
1 parent c709b99 commit 3b64000

File tree

6 files changed

+43
-23
lines changed

6 files changed

+43
-23
lines changed

frontend/app/components/Navbar.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ export default function Navbar() {
121121

122122
function DataSourcePicker() {
123123
function onPickerChanged(value: string) {
124-
console.log(value);
125124
if (value === "recording") {
126125
//TODO Make an actual function to stop the live view
127126
switchToRecording("");

frontend/app/components/TimelineBar.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function SyncButton() {
5050
return () => {
5151
unsub1();
5252
unsub2();
53-
}
53+
};
5454
}, []);
5555
const setTimelineSynced = () => {
5656
setEnabled(true);
@@ -73,7 +73,10 @@ function MainSlider() {
7373
const [disabled, setDisabled] = useState<boolean>(false);
7474
const [minMax, setMinMax] = useState<RangeSliderValue>([0, 10]);
7575
const [value, setValue] = useState<RangeSliderValue>([0, 10]);
76-
const debouncedSetValue = useDebounceCallbackGreedy((value) => setValue(value), 10);
76+
const debouncedSetValue = useDebounceCallbackGreedy((value) => {
77+
setValue(value);
78+
// console.log(performance.now(), value);
79+
}, 10);
7780
const ref = useRef<HTMLDivElement>(null);
7881
// id is only used to differentiate between who set viewInterval (avoid infinite recursion)
7982
const id = "timelineBar";
@@ -94,7 +97,7 @@ function MainSlider() {
9497
setMinMax([left, right]);
9598
});
9699
const unsub2 = subscribeDataSource((dataSource: DataSourceType) => {
97-
// setDisabled(dataSource == DataSourceType.NONE);
100+
setDisabled(dataSource == DataSourceType.NONE);
98101
});
99102
const unsub3 = subscribeViewInterval((range, setterID) => {
100103
// console.log(range, setterID, minMax);
@@ -126,13 +129,13 @@ function MainSlider() {
126129
// viewIntervalRef.current[1],
127130
// );
128131
}
132+
129133
setValue(range);
130-
// setViewInterval(range, id);
134+
setViewInterval(range, id);
131135

132-
const val = dataArraysRef.current[timeColumnName]![range[0]];
133-
console.log("idx:", range[0], val, dataArraysRef.current[":Time"]);
134-
console.log("timeline setting range:", range);
135-
136+
// const val = dataArraysRef.current[timeColumnName]![range[0]];
137+
// console.log("idx:", range[0], val, dataArraysRef.current[":Time"]);
138+
// console.log("timeline setting range:", range);
136139
};
137140

138141
const sliderStyles = useMemo(
@@ -149,7 +152,6 @@ function MainSlider() {
149152

150153
// console.log("idx:", idx, val, dataArraysRef.current[":Time"]);
151154
return val !== undefined ? val.toFixed(2) : "???";
152-
153155
};
154156

155157
return (

frontend/app/components/visualizations/CarWireframe.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function Car({ rotation }: { rotation: rotation }) {
3333

3434
useEffect(() => {
3535
group.current?.setRotationFromEuler(
36-
new THREE.Euler(rotation.x, rotation.y + Math.PI, rotation.z, "XYZ"),
36+
new THREE.Euler(rotation.x, rotation.y, rotation.z, "XYZ"),
3737
);
3838
}, [rotation]);
3939

@@ -69,9 +69,12 @@ export default function CarWireframe() {
6969
useEffect(() => {
7070
return subscribeCursorRow((cursorRow) => {
7171
setValues({
72-
x: cursorRow?.VDM_X_AXIS_ACCELERATION ?? 0,
73-
y: cursorRow?.VDM_Y_AXIS_ACCELERATION ?? 0,
74-
z: cursorRow?.VDM_Z_AXIS_ACCELERATION ?? 0,
72+
// x: cursorRow?.VDM_X_AXIS_ACCELERATION ?? 0,
73+
// y: cursorRow?.VDM_Y_AXIS_ACCELERATION ?? 0,
74+
// z: cursorRow?.VDM_Z_AXIS_ACCELERATION ?? 0,
75+
x: 0,
76+
y: (cursorRow?.VDM_GPS_TRUE_COURSE ?? 0) / -180 * Math.PI + Math.PI,
77+
z: 0,
7578
});
7679
});
7780
}, []);

frontend/app/components/visualizations/lightning-charts/StackedLineChart.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import StackedLineChartInternal from "./StackedLineChartInternal";
33
import { Gear, Plus } from "@phosphor-icons/react";
44
import { VisualizationProps } from "../../FlexLayoutComponent";
55
import { ColumnName, columnNames, timeColumnName } from "@/app/data-processing/datatypes";
6+
import { useState } from "react";
67

78
type YAxisInfo = {
89
columnNames: ColumnName[];
@@ -62,9 +63,12 @@ export function StackedLineChart({
6263
},
6364
]);
6465

66+
const [search, setSearch] = useState("");
67+
6568
// this is just a basic, not-thought-through example of how to modify the
6669
// state to add new columns
6770
const tryAddColumn = (key: string) => {
71+
setSearch(key);
6872
if ((columnNames as string[]).includes(key)) {
6973
setYAxesInfo([
7074
{
@@ -109,7 +113,7 @@ export function StackedLineChart({
109113
label="Add Columns"
110114
placeholder="Seg0_VOLT_0"
111115
data={columnNames}
112-
value=""
116+
value={search}
113117
onChange={tryAddColumn}
114118
/>
115119
</Menu.Dropdown>

frontend/app/components/visualizations/lightning-charts/StackedLineChartInternal.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export default function StackedLineChartInternal({
175175
// restoreDefault: { doubleClick: true },
176176
// };
177177
// chart.setUserInteractions(defaultUserInteractions);
178+
// chart.setAnimationsEnabled(false); // do we like animations?
178179

179180
chart.getDefaultAxisX().addEventListener("intervalchange", ({ start, end }) => {
180181
// start/end are "axis coordinates" but chart.solveNearest() expects
@@ -203,9 +204,11 @@ export default function StackedLineChartInternal({
203204
// TODO: maybe only set the main viewInterval if we have pointer
204205
// focus and the viewWidth itself changed?
205206
// also, maybe chart.seriesBackground.addEventListener("") ?
206-
const [oldStart, oldEnd] = viewIntervalRef.current;
207-
if (!isTimelineSyncedRef.current || start - end == oldStart - oldEnd) {
208-
}
207+
// const [oldStart, oldEnd] = viewIntervalRef.current;
208+
// if (!isTimelineSyncedRef.current || start - end == oldStart - oldEnd) {
209+
// }
210+
211+
// console.log("LCJS setting:", dataIndexes);
209212
setViewInterval(dataIndexes, `lcjs-${id}`);
210213
}
211214
});
@@ -327,7 +330,7 @@ export default function StackedLineChartInternal({
327330

328331
useEffect(() => {
329332
legendRef.current?.setVisible(showLegend ?? false);
330-
}, [showLegend])
333+
}, [showLegend]);
331334

332335
return <div id={id} ref={containerRef} className="w-[100%] h-[100%]"></div>;
333336
}

frontend/app/utils/useGreedyDebounce.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,25 @@ export default function useDebounceCallbackGreedy<T extends (...args: any[]) =>
55
delay: number,
66
) {
77
const timeoutRef = useRef<number>(null);
8-
const isCooldownRef = useRef(false);
8+
const isOnCooldownRef = useRef(false);
9+
const lastArgsRef = useRef<Parameters<T>>(null);
910

1011
const debouncedFunc = useCallback(
1112
(...args: Parameters<T>) => {
12-
if (!isCooldownRef.current) {
13+
if (!isOnCooldownRef.current) {
1314
func(...args);
14-
isCooldownRef.current = true;
15+
isOnCooldownRef.current = true;
1516
timeoutRef.current = window.setTimeout(() => {
16-
isCooldownRef.current = false;
17+
isOnCooldownRef.current = false;
18+
19+
if (lastArgsRef.current) {
20+
const args = lastArgsRef.current;
21+
lastArgsRef.current = null;
22+
func(...args);
23+
}
1724
}, delay);
25+
} else {
26+
lastArgsRef.current = args;
1827
}
1928
},
2029
[func, delay],

0 commit comments

Comments
 (0)