Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/components/plots/AxisLines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, fli

const depthRatio = useMemo(()=>shape.z/shape.x*timeScale,[shape, timeScale]);
const shapeRatio = useMemo(()=>shape.y/shape.x, [shape])
const timeRatio = Math.max(shape.z/shape.x, 2);
const timeRatio = useMemo(()=>Math.max(shape.z/shape.x * 2, 2),[shape]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This line has a couple of potential improvements:

  1. Edge Case Handling: There's a potential for division by zero if shape.x is 0. This could result in timeRatio being Infinity or NaN, which might cause rendering errors. It's safer to handle this edge case explicitly.

  2. Magic Numbers: The number 2 is used for both a scaling factor and a minimum value. This can be confusing. Using named constants would make the code more readable and maintainable.

Here is a suggestion that addresses both points:

Suggested change
const timeRatio = useMemo(()=>Math.max(shape.z/shape.x * 2, 2),[shape]);
const timeRatio = useMemo(() => {
if (!shape.x) {
return 2; // Fallback to the minimum value if shape.x is 0 or falsy
}
const SCALE_FACTOR = 2;
const MIN_RATIO = 2;
return Math.max((shape.z / shape.x) * SCALE_FACTOR, MIN_RATIO);
}, [shape]);


const secondaryColor = useCSSVariable('--text-plot') //replace with needed variable
const colorHex = useMemo(()=>{
Expand All @@ -101,7 +101,7 @@ const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, fli

const zLine = useMemo(()=> {
const geom = new LineSegmentsGeometry().setPositions([0, 0, isPC ? zRange[0]*globalScale*depthRatio-tickLength/2 : (zRange[0]*timeRatio-tickLength)/2, 0, 0, isPC ? zRange[1]*globalScale*depthRatio+tickLength/2 : (zRange[1]*timeRatio+tickLength)/2]);
return new LineSegments2(geom, lineMat)},[zRange, depthRatio, isPC, lineMat, globalScale])
return new LineSegments2(geom, lineMat)},[zRange, depthRatio, isPC, lineMat, globalScale, timeRatio])

const tickLine = useMemo(()=> {
const geom = new LineSegmentsGeometry().setPositions([0, 0, 0, 0, 0, tickLength]);
Expand Down
Loading