Skip to content

Commit 903f538

Browse files
Fixed: 3D viewer shouldn't be blank when the board's dimensions are 0 (#221)
* Show grid for empty board * fixed * Improved variable naming * Improved variable naming
1 parent 33c815e commit 903f538

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/CadViewer.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@ export const CadViewer = forwardRef<
4646
const board = su(circuitJson as any).pcb_board.list()[0]
4747
if (!board) return [5, 5, 5] as const
4848
const { width, height } = board
49-
const largestDim = Math.max(width, height)
49+
50+
if (!width && !height) {
51+
return [5, 5, 5] as const
52+
}
53+
54+
const minCameraDistance = 5
55+
const adjustedBoardWidth = Math.max(width, minCameraDistance)
56+
const adjustedBoardHeight = Math.max(height, minCameraDistance)
57+
const largestDim = Math.max(adjustedBoardWidth, adjustedBoardHeight)
5058
return [largestDim / 2, largestDim / 2, largestDim] as const
5159
} catch (e) {
5260
console.error(e)

stories/EmptyBoard.stories.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { CadViewer } from "src/CadViewer"
2+
3+
export const EmptyBoard = () => {
4+
return (
5+
<CadViewer>
6+
<board width="0" height="0"></board>
7+
</CadViewer>
8+
)
9+
}
10+
11+
export default {
12+
title: "EmptyBoard",
13+
component: EmptyBoard,
14+
}

0 commit comments

Comments
 (0)