Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: thumbnail #344

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/ImageView/AnalogueModelImageView.styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const ImageWrapper = styled.div`
`;

export const CanvasWrapper = styled.div`
height: 55vh;
width: auto;
display: flex;
flex-direction: column;
height: 65vh;
width: 45vw;
`;
29 changes: 9 additions & 20 deletions src/components/ImageView/ModelImageCanvas/ModelImageCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const ModelImageCanvas = ({

// Canvas settings
const tickInterval = 1000;
const canvasOffset = 100;
const canvasYOffset = 100;
const canvasXOffset = 300;
const imageYOffset = 10;
const imageXOffset = 40;
Expand All @@ -46,8 +46,8 @@ export const ModelImageCanvas = ({
// Scale image down based on the size of the parent
const container = canvas.parentElement;
if (container === null) return;
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const containerWidth = container.clientWidth - canvasXOffset;
const containerHeight = container.clientHeight - canvasYOffset;
const scaleX = containerWidth / img.width;
const scaleY = containerHeight / img.height;
const scale = Math.min(scaleX, scaleY); // Use the smaller scale factor
Expand All @@ -60,8 +60,8 @@ export const ModelImageCanvas = ({
const width = scaledWidth;

// Canvas will be bigger than image
canvas.width = width + canvasXOffset;
canvas.height = height + canvasOffset;
canvas.width = container.clientWidth;
canvas.height = container.clientHeight;

// Calculate scaling factors from coordinate space to canvas pixels
const xScale = width / xRange;
Expand Down Expand Up @@ -104,22 +104,11 @@ export const ModelImageCanvas = ({

// Draw tick line
context.beginPath();
context.moveTo(
tickX + imageXOffset,
canvas.height - canvasOffset + imageYOffset,
);
context.lineTo(
tickX + imageXOffset,
canvas.height - canvasOffset + imageYOffset + 10,
);
context.moveTo(tickX + imageXOffset, height + imageYOffset);
context.lineTo(tickX + imageXOffset, height + imageYOffset + 10);
context.stroke();

context.fillText(
tickLabel,
tickX + imageXOffset - 10,
canvas.height - canvasOffset + 30,
24,
);
context.fillText(tickLabel, tickX + imageXOffset - 10, height + 30);
}

// Draw y ticks
Expand Down Expand Up @@ -186,7 +175,7 @@ export const ModelImageCanvas = ({
}
}
if (showLegend) {
const legendX = canvas.width - 250; // Position the legend on the right
const legendX = scaledWidth + 60; // Position the legend on the right
const legendY = 50; // Starting y position for the legend
const legendBoxSize = 20; // Size of each color box
const legendSpacing = 30; // Spacing between legend items
Expand Down