Skip to content

Commit 075d256

Browse files
committed
support saving mappings to file
1 parent 9a8bfce commit 075d256

File tree

6 files changed

+312
-12
lines changed

6 files changed

+312
-12
lines changed

client/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"react-bootstrap": "^2.10.1",
1515
"react-dom": "^18.2.0",
1616
"react-scripts": "5.0.1",
17+
"recharts": "^2.12.2",
1718
"styled-components": "^6.1.8",
1819
"web-vitals": "^2.1.4"
1920
},

client/src/App.js

+80-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import logo from './logo.svg';
22
import './App.css';
33
import { BasicStream } from './BasicStream'
44
import React, { useCallback, useState, useEffect } from 'react'
5+
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
56
import { Container, Row, Col, Button } from 'react-bootstrap';
67
window.addEventListener('error', e => {
78
if (e.message === 'ResizeObserver loop limit exceeded' || e.message === 'ResizeObserver loop completed with undelivered notifications.') {
@@ -38,16 +39,35 @@ function App() {
3839

3940
const handleAzimuthChange = (amount) => {
4041
var new_azimuth = azimuth + amount;
42+
if (new_azimuth > 360) {
43+
new_azimuth = new_azimuth % 360;
44+
}
45+
if (new_azimuth < 0) {
46+
new_azimuth = 360 + new_azimuth;
47+
}
4148
setAzimuth(new_azimuth);
4249
}
4350

4451
const handleElevationChange = (amount) => {
52+
4553
var new_elevation = elevation + amount;
54+
if (new_elevation > 90) {
55+
new_elevation = 90;
56+
}
57+
if (new_elevation < 0) {
58+
new_elevation = 0;
59+
}
4660
setElevation(new_elevation);
4761
}
4862

4963
const handleZoomChange = (amount) => {
5064
var new_zoom = zoom + amount;
65+
if (new_zoom > 9999) {
66+
new_zoom = 9999;
67+
}
68+
if (new_zoom < 1) {
69+
new_zoom = 1;
70+
}
5171
setZoom(new_zoom);
5272
}
5373

@@ -84,30 +104,83 @@ function App() {
84104
}
85105
console.log(mapping);
86106
}
107+
108+
const saveMapping = () => {
109+
fetch('http://localhost:5000/save-mapping', {
110+
method: 'POST',
111+
headers: {
112+
'Content-Type': 'application/json',
113+
},
114+
body: JSON.stringify(mapping),
115+
})
116+
.then(response => response.json())
117+
.then(data => {
118+
console.log('Success:', data);
119+
})
120+
.catch((error) => {
121+
console.error('Error:', error);
122+
});
123+
}
124+
125+
87126
return (
88127
<div >
89128
<table>
90129
<tr>
91130
<td className="App"> <BasicStream /></td>
92131
<td>
93132
<div>
94-
<button onClick={() => { handleAzimuthChange(-10) }}>Decrease Azimuth</button>
133+
<h3>Azimuth</h3>
134+
<button onClick={() => { handleAzimuthChange(-10) }}>-10</button>
135+
<button onClick={() => { handleAzimuthChange(-5) }}>-5</button>
136+
<button onClick={() => { handleAzimuthChange(-1) }}>-1</button>
95137
{azimuth}
96-
<button onClick={() => { handleAzimuthChange(10) }}>Increase Azimuth</button> </div>
138+
<button onClick={() => { handleAzimuthChange(1) }}>+1</button>
139+
<button onClick={() => { handleAzimuthChange(5) }}>+5</button>
140+
<button onClick={() => { handleAzimuthChange(10) }}>+10</button> </div>
97141

98142
<div>
99-
<button onClick={() => { handleElevationChange(-10) }}>Decrease Elevation</button>
143+
<h3>Elevation</h3>
144+
<button onClick={() => { handleElevationChange(-10) }}>-10</button>
145+
<button onClick={() => { handleElevationChange(-5) }}>-5</button>
146+
<button onClick={() => { handleElevationChange(-1) }}>-1</button>
100147
{elevation}
101-
<button onClick={() => { handleElevationChange(10) }}>Increase Elevation</button></div>
148+
<button onClick={() => { handleElevationChange(1) }}>1</button>
149+
<button onClick={() => { handleElevationChange(5) }}>5</button>
150+
<button onClick={() => { handleElevationChange(10) }}>10</button></div>
102151
<div>
103-
<button onClick={() => { handleZoomChange(-200) }}>Decrease Zoom</button>
152+
<h3>Zoom</h3>
153+
<button onClick={() => { handleZoomChange(-1000) }}>-1000</button>
154+
<button onClick={() => { handleZoomChange(-200) }}>-200</button>
104155
{zoom}
105-
<button onClick={() => { handleZoomChange(200) }}>Increase Zoom</button></div>
156+
<button onClick={() => { handleZoomChange(200) }}>200</button>
157+
<button onClick={() => { handleZoomChange(200) }}>1000</button></div>
158+
<div>
159+
<h3>Mapping</h3>
106160
<button onClick={upsertMapping}>Add Point</button>
161+
<button onClick={saveMapping}>Save Mapping</button>
162+
</div>
107163
</td>
108164
</tr>
109165
</table>
110-
166+
<div >
167+
<ResponsiveContainer width="95%" height={400}>
168+
<LineChart
169+
height={300}
170+
data={mapping}
171+
margin={{
172+
top: 5, right: 30, left: 20, bottom: 5,
173+
}}
174+
>
175+
<CartesianGrid strokeDasharray="3 3" />
176+
<XAxis dataKey="azimuth" domain={[0, 360]} />
177+
<YAxis dataKey="elevation" domain={[0, 90]} /> // Set the Y-axis domain to [0, 90]
178+
<Tooltip />
179+
<Legend />
180+
<Line type="monotone" dataKey="elevation" stroke="#8884d8" activeDot={{ r: 8 }} />
181+
</LineChart>
182+
</ResponsiveContainer>
183+
</div>
111184

112185
</div>
113186
);

0 commit comments

Comments
 (0)