Skip to content

Commit 6ae18cc

Browse files
committed
frontend test fixed
1 parent 91c7fa3 commit 6ae18cc

1 file changed

Lines changed: 11 additions & 28 deletions

File tree

frontend/src/components/MapComponent.jsx

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -613,45 +613,28 @@ export default function MapComponent() {
613613
setUnit(newUnit); // Update local state for legend
614614

615615
markersRef.current.forEach(({ marker, tempC }) => {
616-
// 1) compute the new label
617-
const formattedTemp = formatTemperature(tempC, newUnit);
618-
619-
// 2) find the existing <span class="temp-value"> and update it
620-
const el = marker.getElement();
621-
if (el) {
622-
const valueSpan = el.querySelector('.temp-value');
623-
if (valueSpan) valueSpan.textContent = formattedTemp;
624-
}
625-
626-
// 3) leave the background‐color alone so it never “snaps back” after a refresh
627-
// (skip marker.setIcon entirely)
628-
});
616+
// 1) update the legend label
617+
const formattedTemp = formatTemperature(tempC, newUnit);
618+
const el = marker.getElement();
619+
if (el) {
620+
const valueSpan = el.querySelector('.temp-value');
621+
if (valueSpan) valueSpan.textContent = formattedTemp;
622+
}
629623

630-
// Update the graph if it exists
624+
// 2) if this marker has a chart, update its data & options
631625
if (marker.chartInstance && marker.chartData) {
632626
const chart = marker.chartInstance;
633-
634-
// Convert original data to new unit with time structure
635-
const newTimeBasedData = marker.chartData.map((d) => ({
627+
const newTimeBasedData = marker.chartData.map(d => ({
636628
x: new Date(d.timestamp),
637629
y: newUnit === 'F' ? (d.temp * 9) / 5 + 32 : d.temp
638630
}));
639-
640-
// Update dataset with time-based data
641631
chart.data.datasets[0].data = newTimeBasedData;
642-
643-
// Update the y-axis title
644632
chart.options.scales.y.title.text = `Temperature (°${newUnit})`;
645-
646-
// Update y-axis tick callback
647-
chart.options.scales.y.ticks.callback = function(value) {
648-
return `${value}°${newUnit}`;
649-
};
650-
651-
// Apply the updates
633+
chart.options.scales.y.ticks.callback = val => `${val}°${newUnit}`;
652634
chart.update();
653635
}
654636
});
637+
});
655638

656639
// Listen for theme changes
657640
const onThemeChange = () => {

0 commit comments

Comments
 (0)