Skip to content

Commit

Permalink
fix: round stepSize to one decimal place (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinShetty authored Feb 10, 2025
1 parent b9efa2d commit 7595348
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mapf-visualizer",
"private": true,
"version": "1.0.1",
"version": "1.0.2",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
16 changes: 9 additions & 7 deletions src/AnimationControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ function AnimationControl({
setShowGoals,
showGoalVectors,
setShowGoalVectors,
}: AnimationControlProps) {
}: AnimationControlProps) {
const roundAndSetStepSize = (value: number) => {
onStepSizeChange(Number(value.toFixed(1)));
}

const handleSliderChange = (event: Event, value: number | number[]) => {
event.preventDefault();
if (typeof value === 'number') {
onStepSizeChange(value);
}
if (typeof value === 'number') roundAndSetStepSize(value);
};

useEffect(() => {
Expand All @@ -122,9 +124,9 @@ function AnimationControl({
} else if (event.key === SHOW_AGENT_ID_KEY) {
onShowAgentIdChange(!showAgentId);
} else if (event.key === STEP_SIZE_UP_KEY && stepSize + STEP_SIZE_INCREMENT <= STEP_SIZE_MAX) {
onStepSizeChange(stepSize + STEP_SIZE_INCREMENT);
roundAndSetStepSize(stepSize + STEP_SIZE_INCREMENT);
} else if (event.key === STEP_SIZE_DOWN_KEY && stepSize - STEP_SIZE_INCREMENT >= STEP_SIZE_MIN) {
onStepSizeChange(stepSize - STEP_SIZE_INCREMENT);
roundAndSetStepSize(stepSize - STEP_SIZE_INCREMENT);
} else if (event.key === TRACE_PATHS_KEY) {
onTracePathsChange(!tracePaths);
} else if (event.key === SCREENSHOT_KEY) {
Expand Down Expand Up @@ -170,7 +172,7 @@ function AnimationControl({
/>
</Tooltip>
<Tooltip title="Reset step size">
<Button onClick={() => onStepSizeChange(1)}>
<Button onClick={() => roundAndSetStepSize(1)}>
<RestartAltIcon />
</Button>
</Tooltip>
Expand Down

0 comments on commit 7595348

Please sign in to comment.