@@ -7,77 +7,80 @@ import { useDataMethods } from "@/app/data-processing/DataMethodsProvider";
77
88// data is represented in row, column (y, x)
99
10- export function LapCounter ( ) {
11- const { subscribeCursorRow, subscribeReset, dataArraysRef } = useDataMethods ( ) ;
12-
13- const lc = useContext ( LightningChartsContext ) ;
14- const containerRef = useRef ( null ) ;
15- const id = useId ( ) ;
16-
17- const columnNames = [ "Lap #" , "Lap Time (s)" ] ;
18-
19- useEffect ( ( ) => {
20- // checks for invalid ref & context
21- if ( ! containerRef . current || ! lc ) return ;
22-
23- let dataGrid = lc . DataGrid ( { container : containerRef . current , theme : globalTheme } ) ;
24-
25- let lapTimes : number [ ] = [ ] ;
26-
27- function calculateLaps ( ) {
28- let lapArray = dataArraysRef . current [ ":Lap" ] ;
29- let lapTimeArray = dataArraysRef . current [ ":LapTime" ] ;
30-
31- dataGrid . setTitle ( "Lap Times" ) ;
32- dataGrid . setRowContent ( 0 , columnNames ) ;
33-
34- if ( ! lapArray || ! lapTimeArray ) return ;
35-
36- lapTimes = [ ] ;
37-
38- let previous = lapArray [ 0 ] ;
39-
40- for ( let i = 0 ; i < lapArray . length ; i ++ ) {
41- if ( lapArray [ i ] > previous ) {
42- lapTimes . push ( lapTimeArray [ i - 1 ] ) ;
43- previous = lapArray [ i ] ;
44- }
45- }
46- }
47-
48- const unsubReset = subscribeReset ( ( ) => {
49- calculateLaps ( ) ;
50- } ) ;
51-
52- // defines subscribers
53- const unsub = subscribeCursorRow ( ( cursorRow ) => {
54- const lap = cursorRow ? cursorRow [ ":Lap" ] : null ;
55- const lapTime = cursorRow ? cursorRow [ ":LapTime" ] : null ;
56-
57- //TODO Fix this to work better with live
58-
59- if ( dataGrid . getRowMax ( ) < 1 ) {
60- calculateLaps ( ) ;
61- }
62-
63- if ( lap === null || lapTime === null ) return ;
64-
65- for ( let i = dataGrid . getRowMax ( ) ; i > lap + 1 ; i -- ) {
66- dataGrid . removeRow ( i ) ;
67- }
68-
69- for ( let i = 0 ; i < lap + 1 ; i ++ ) {
70- dataGrid . setRowContent ( i + 1 , [ i + 1 , lapTimes [ i ] ] ) ;
71- }
72-
73- dataGrid . setRowContent ( dataGrid . getRowMax ( ) , [ dataGrid . getRowMax ( ) , lapTime ] ) ;
74- } ) ;
75-
76- return ( ) => {
77- unsub ( ) ;
78- unsubReset ( ) ;
79- } ;
80- } , [ dataArraysRef . current ] ) ;
81-
82- return < div id = { id } ref = { containerRef } className = "w-[100%] h-[100%]" > </ div > ;
83- }
10+ // Lap counting won't work until we either calculate lap# based on GPS
11+ // coordinates on the car before logging, or calculate it after the fact.
12+
13+ // export function LapCounter() {
14+ // const { subscribeCursorRow, subscribeReset, dataArraysRef } = useDataMethods();
15+ //
16+ // const lc = useContext(LightningChartsContext);
17+ // const containerRef = useRef(null);
18+ // const id = useId();
19+ //
20+ // const columnNames = ["Lap #", "Lap Time (s)"];
21+ //
22+ // useEffect(() => {
23+ // // checks for invalid ref & context
24+ // if (!containerRef.current || !lc) return;
25+ //
26+ // let dataGrid = lc.DataGrid({ container: containerRef.current, theme: globalTheme });
27+ //
28+ // let lapTimes: number[] = [];
29+ //
30+ // function calculateLaps() {
31+ // let lapArray = dataArraysRef.current[":Lap"];
32+ // let lapTimeArray = dataArraysRef.current[":LapTime"];
33+ //
34+ // dataGrid.setTitle("Lap Times");
35+ // dataGrid.setRowContent(0, columnNames);
36+ //
37+ // if (!lapArray || !lapTimeArray) return;
38+ //
39+ // lapTimes = [];
40+ //
41+ // let previous = lapArray[0];
42+ //
43+ // for (let i = 0; i < lapArray.length; i++) {
44+ // if (lapArray[i] > previous) {
45+ // lapTimes.push(lapTimeArray[i - 1]);
46+ // previous = lapArray[i];
47+ // }
48+ // }
49+ // }
50+ //
51+ // const unsubReset = subscribeReset(() => {
52+ // calculateLaps();
53+ // });
54+ //
55+ // // defines subscribers
56+ // const unsub = subscribeCursorRow((cursorRow) => {
57+ // const lap = cursorRow ? cursorRow[":Lap"] : null;
58+ // const lapTime = cursorRow ? cursorRow[":LapTime"] : null;
59+ //
60+ // //TODO Fix this to work better with live
61+ //
62+ // if (dataGrid.getRowMax() < 1) {
63+ // calculateLaps();
64+ // }
65+ //
66+ // if (lap === null || lapTime === null) return;
67+ //
68+ // for (let i = dataGrid.getRowMax(); i > lap + 1; i--) {
69+ // dataGrid.removeRow(i);
70+ // }
71+ //
72+ // for (let i = 0; i < lap + 1; i++) {
73+ // dataGrid.setRowContent(i + 1, [i + 1, lapTimes[i]]);
74+ // }
75+ //
76+ // dataGrid.setRowContent(dataGrid.getRowMax(), [dataGrid.getRowMax(), lapTime]);
77+ // });
78+ //
79+ // return () => {
80+ // unsub();
81+ // unsubReset();
82+ // };
83+ // }, [dataArraysRef.current]);
84+ //
85+ // return <div id={id} ref={containerRef} className="w-[100%] h-[100%]"></div>;
86+ // }
0 commit comments