Skip to content

Commit d5d90d5

Browse files
author
Tamoor Shahid
committed
Changed canvas height sizing to auto instead of fixed value.
1 parent eac9c87 commit d5d90d5

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/components/OavVideoStream.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { Box } from "@mui/material";
2-
import { PvComponent, PvItem, PvDescription, useParsedPvConnection } from "../pv/PvComponent";
2+
import {
3+
PvComponent,
4+
PvItem,
5+
PvDescription,
6+
useParsedPvConnection,
7+
} from "../pv/PvComponent";
38
import { parseNumericPv, pvIntArrayToString } from "../pv/util";
49
import React from "react";
510

6-
export const useContainerDimensions = (ref: React.MutableRefObject<HTMLHeadingElement | null>) => {
11+
export const useContainerDimensions = (
12+
ref: React.MutableRefObject<HTMLHeadingElement | null>
13+
) => {
714
const [dimensions, setDimensions] = React.useState({ width: 0, height: 0 });
815
React.useEffect(() => {
916
const getDimensions = () => ({
@@ -62,7 +69,10 @@ export function OavVideoStream(
6269
label: props.label,
6370
render: (props: PvItem) => {
6471
const value = props.value ? props.value : "undefined";
65-
if (!streamUrl.startsWith("http") && value.toString().startsWith("http")) {
72+
if (
73+
!streamUrl.startsWith("http") &&
74+
value.toString().startsWith("http")
75+
) {
6676
setStreamUrl(value.toString());
6777
}
6878
return (
@@ -130,7 +140,7 @@ function VideoBoxWithOverlay(props: {
130140
/>
131141
<canvas
132142
width={width}
133-
height={height}
143+
height="auto"
134144
ref={canvasRef}
135145
style={{
136146
top: 0,
@@ -148,8 +158,12 @@ function VideoBoxWithOverlay(props: {
148158
// x and y relative to the crosshair
149159
const [relX, relY] = [x - props.crosshairX, y - props.crosshairY];
150160
// fraction of the image in x/y * original dimension in pixels
151-
const scaledX = props.originalDims ? (relX / width) * props.originalDims.width : x;
152-
const scaledY = props.originalDims ? (relY / height) * props.originalDims.height : y;
161+
const scaledX = props.originalDims
162+
? (relX / width) * props.originalDims.width
163+
: x;
164+
const scaledY = props.originalDims
165+
? (relY / height) * props.originalDims.height
166+
: y;
153167
props.onCoordClick(scaledX, scaledY);
154168
}
155169
}

0 commit comments

Comments
 (0)