Skip to content

Commit 51049ba

Browse files
committed
feat: show avg price
1 parent dba242b commit 51049ba

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

frontend/src/components/Chart.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,22 @@ export default function Chart(props: ChartProps) {
4343
//console.log(props.timeSlots);
4444
const [gsValues, setGsValues] = useState([] as GsPoint[]);
4545
const [fuelType, setFuelType] = useState(FuelType.E5);
46-
const [lineColor, setLineColor] = useState('#8884d8')
46+
const [lineColor, setLineColor] = useState('#8884d8');
47+
const [avgValue, setAvgValue] = useState(0.0);
4748

4849
// eslint-disable-next-line
4950
useEffect(() => {
5051
if (fuelType === FuelType.E5) {
5152
setLineColor('#8884d8')
52-
const avgValue = props.timeSlots.reduce((acc, value) => value.e5 + acc, 0) / (props.timeSlots.length || 1);
53+
setAvgValue(props.timeSlots.reduce((acc, value) => value.e5 + acc, 0) / (props.timeSlots.length || 1));
5354
setGsValues(props.timeSlots.map(myValue => ({ timestamp: myValue.x, price: myValue.e5 - avgValue } as GsPoint)))
5455
} else if (fuelType === FuelType.E10) {
5556
setLineColor('#82ca9d')
56-
const avgValue = props.timeSlots.reduce((acc, value) => value.e10 + acc, 0) / (props.timeSlots.length || 1);
57+
setAvgValue(props.timeSlots.reduce((acc, value) => value.e10 + acc, 0) / (props.timeSlots.length || 1));
5758
setGsValues(props.timeSlots.map(myValue => ({ timestamp: myValue.x, price: myValue.e10 - avgValue } as GsPoint)))
5859
} else {
5960
setLineColor('#82caff')
60-
const avgValue = props.timeSlots.reduce((acc, value) => value.diesel + acc, 0) / (props.timeSlots.length || 1);
61+
setAvgValue(props.timeSlots.reduce((acc, value) => value.diesel + acc, 0) / (props.timeSlots.length || 1));
6162
setGsValues(props.timeSlots.map(myValue => ({ timestamp: myValue.x, price: myValue.diesel - avgValue } as GsPoint)))
6263
}
6364
});
@@ -74,7 +75,7 @@ export default function Chart(props: ChartProps) {
7475
<YAxis />
7576
<Tooltip />
7677
<Legend />
77-
<Line type="monotone" dataKey="price" stroke={lineColor} />
78+
<Line name={'AvgPrice: '+(Math.round(avgValue*1000)/1000)} type="monotone" dataKey="price" stroke={lineColor} />
7879
</LineChart>
7980
</ResponsiveContainer>
8081
<FormControl>

0 commit comments

Comments
 (0)