Skip to content

Commit d03a23a

Browse files
committed
🐜✈️ ↝ [SSP-47 SSC-66 SSG-97 SSG-98 SSG-99]: P4 Annotation Working/fixed :)
1 parent da36e7c commit d03a23a

File tree

3 files changed

+59
-32
lines changed

3 files changed

+59
-32
lines changed

components/Projects/(classifications)/Annotating/DrawingCanvas.tsx

+28-13
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,39 @@ export function AnnotationCanvas({
108108
const canvas = canvasRef.current;
109109
const ctx = canvas?.getContext('2d');
110110
if (!canvas || !ctx || !imageRef.current) return;
111-
111+
112112
ctx.clearRect(0, 0, canvas.width, canvas.height);
113-
ctx.drawImage(
114-
imageRef.current,
115-
0,
116-
0,
117-
CANVAS_WIDTH,
118-
CANVAS_HEIGHT // Scale the image to fit within the fixed canvas size
119-
);
120-
113+
114+
const img = imageRef.current;
115+
const imgAspectRatio = img.width / img.height;
116+
const canvasAspectRatio = CANVAS_WIDTH / CANVAS_HEIGHT;
117+
118+
let drawWidth, drawHeight, offsetX, offsetY;
119+
120+
if (imgAspectRatio > canvasAspectRatio) {
121+
// Image is wider than canvas
122+
drawWidth = CANVAS_WIDTH;
123+
drawHeight = CANVAS_WIDTH / imgAspectRatio;
124+
offsetX = 0;
125+
offsetY = (CANVAS_HEIGHT - drawHeight) / 2;
126+
} else {
127+
// Image is taller than canvas
128+
drawWidth = CANVAS_HEIGHT * imgAspectRatio;
129+
drawHeight = CANVAS_HEIGHT;
130+
offsetX = (CANVAS_WIDTH - drawWidth) / 2;
131+
offsetY = 0;
132+
};
133+
134+
ctx.drawImage(img, offsetX, offsetY, drawWidth, drawHeight);
135+
121136
drawings.forEach((drawing) => {
122137
drawObject(ctx, drawing);
123138
});
124-
139+
125140
if (currentDrawing) {
126141
drawObject(ctx, currentDrawing);
127-
}
128-
};
142+
};
143+
};
129144

130145
useEffect(() => {
131146
if (imageRef.current) {
@@ -151,7 +166,7 @@ export function AnnotationCanvas({
151166
onMouseUp={stopDrawing}
152167
onMouseOut={stopDrawing}
153168
className={cn("cursor-crosshair", isDrawing && "cursor-none")}
154-
style={{ width: CANVAS_WIDTH, height: CANVAS_HEIGHT }}
169+
style={{ width: `${CANVAS_WIDTH}px`, height: `${CANVAS_HEIGHT}px` }}
155170
/>
156171
</div>
157172
);

components/Projects/Satellite/PlanetFour.tsx

+30-18
Original file line numberDiff line numberDiff line change
@@ -159,32 +159,41 @@ export function PlanetFourProject({ anomalyid }: SelectedAnomProps) {
159159
};
160160

161161
const fetchAnomaly = async () => {
162-
if (!anomalyid || !session) return;
163-
164-
setLoading(true);
165-
162+
if (!session) {
163+
console.error("No session found");
164+
setLoading(false);
165+
return;
166+
};
167+
168+
setLoading(true);
169+
166170
try {
167-
const { data: anomalyData, error: anomalyError } = await supabase
171+
const { data: anomalies, error } = await supabase
168172
.from('anomalies')
169173
.select('*')
170-
.eq('id', anomalyid)
171-
.single();
172-
173-
if (anomalyError) throw anomalyError;
174-
175-
setAnomaly(anomalyData);
176-
setImageUrl(`${supabaseUrl}/storage/v1/object/public/telescope/satellite-planetFour/${anomalyData.id}.jpeg`);
177-
} catch (error: any) {
178-
console.error("Error fetching anomaly", error.message);
174+
.eq('anomalySet', 'satellite-planetFour');
175+
176+
if (error) throw error;
177+
178+
if (!anomalies || anomalies.length === 0) {
179+
console.error("No anomalies found for the given type");
180+
setAnomaly(null);
181+
} else {
182+
const anomaly = anomalies[0];
183+
setAnomaly(anomaly);
184+
setImageUrl(`${supabaseUrl}/storage/v1/object/public/telescope/satellite-planetFour/${anomaly.id}.jpeg`);
185+
}
186+
} catch (error) {
187+
console.error("Error fetching anomaly", error);
179188
setAnomaly(null);
180189
} finally {
181-
setLoading(false);
190+
setLoading(false);
182191
};
183-
};
192+
};
184193

185194
useEffect(() => {
186195
fetchAnomaly();
187-
}, [anomalyid, session, supabase, supabaseUrl]);
196+
}, [session, supabase, supabaseUrl]);
188197

189198
if (loading) {
190199
return <div><p>Loading...</p></div>;
@@ -215,6 +224,7 @@ export function PlanetFourProject({ anomalyid }: SelectedAnomProps) {
215224
initialImageUrl={imageUrl}
216225
/>
217226
)}
227+
{imageUrl}
218228
</>
219229
) : (
220230
<div>
@@ -231,7 +241,9 @@ export function P4Wrapper () {
231241

232242
return (
233243
<div className="space-y-8">
234-
<PreferredTerrestrialClassifications onSelectAnomaly={setSelectedAnomaly} />
244+
{!selectedAnomaly && (
245+
<PreferredTerrestrialClassifications onSelectAnomaly={setSelectedAnomaly} />
246+
)}
235247
{selectedAnomaly && (
236248
<PlanetFourProject anomalyid={selectedAnomaly} />
237249
)}

components/Structures/Missions/Astronomers/SatellitePhotos/AI4M/AIForMars.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const AI4M = () => {
4242
completedCount: 0,
4343
internalComponent: () => <AI4MWrapper />,
4444
color: "text-blue-500",
45-
},
45+
},
4646
{
4747
id: 2,
4848
chapter: 1,

0 commit comments

Comments
 (0)