Skip to content

Commit

Permalink
feature: animation control tooltips (#5)
Browse files Browse the repository at this point in the history
* also add button to recenter view
  • Loading branch information
JustinShetty authored Jan 6, 2025
1 parent f8f84aa commit b050d05
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 48 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This is a work-in-progress and has not yet reached feature parity with [Kei18/ma
- [x] Basic solution animation (with and without rotation)
- [x] Playback control (play, pause, reset, speed adjustment, etc.)
- [x] Timestep display
- [ ] Playback control tooltips
- [x] Playback control tooltips
- [ ] Agent ID display
- [ ] Agent coloring
- [ ] Per-agent path drawing
Expand Down
103 changes: 57 additions & 46 deletions src/AnimationControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import RestartAltIcon from '@mui/icons-material/RestartAlt';
import Slider from '@mui/material/Slider';
import RepeatIcon from '@mui/icons-material/Repeat';
import RepeatOnIcon from '@mui/icons-material/RepeatOn';
import Stack from '@mui/material/Stack';
import CropFreeIcon from '@mui/icons-material/CropFree';
import Tooltip from '@mui/material/Tooltip';

interface AnimationControlProps {
playAnimation: boolean;
Expand All @@ -20,6 +23,7 @@ interface AnimationControlProps {
onSpeedChange: (speed: number) => void;
loopAnimation: boolean,
onLoopAnimationChange: (loopAnimation: boolean) => void;
onFitView: () => void;
}

function AnimationControl({
Expand All @@ -32,6 +36,7 @@ function AnimationControl({
onSpeedChange,
loopAnimation,
onLoopAnimationChange,
onFitView,
}: AnimationControlProps) {
const handleSliderChange = (event: Event, value: number | number[]) => {
event.preventDefault();
Expand All @@ -41,58 +46,64 @@ function AnimationControl({
};

return (
<Box display="flex" flexDirection="column" alignItems="center">
<Stack direction="column" spacing={2}>
<Box display="flex" justifyContent="center">
<ButtonGroup
size="large"
variant="outlined"
>
<Button onClick={onSkipBackward}>
<SkipPreviousIcon />
</Button>
<Button
onClick={() => onPlayAnimationChange(!playAnimation)}
>
{playAnimation ?
<PauseTwoToneIcon /> :
<PlayArrowIcon />}
</Button>
<Button onClick={onSkipForward}>
<SkipNextIcon />
</Button>
<ButtonGroup size="large" variant="outlined">
<Tooltip title="Backward one step">
<Button onClick={onSkipBackward}>
<SkipPreviousIcon />
</Button>
</Tooltip>
<Tooltip title={playAnimation ? "Pause" : "Play"}>
<Button onClick={() => onPlayAnimationChange(!playAnimation)}>
{playAnimation ?
<PauseTwoToneIcon /> :
<PlayArrowIcon />}
</Button>
</Tooltip>
<Tooltip title="Forward one step">
<Button onClick={onSkipForward}>
<SkipNextIcon />
</Button>
</Tooltip>
</ButtonGroup>
</Box>
<Box display="flex" justifyContent="center">
<ButtonGroup
size="large"
variant="outlined"
>
<Button onClick={onRestart}>
<RestartAltIcon />
</Button>
<Button onClick={() => onLoopAnimationChange(!loopAnimation)}>
{loopAnimation ?
<RepeatOnIcon /> :
<RepeatIcon />}
</Button>
</ButtonGroup>
<ButtonGroup size="large" variant="outlined">
<Tooltip title="Restart animation">
<Button onClick={onRestart}>
<RestartAltIcon />
</Button>
</Tooltip>
<Tooltip title={loopAnimation ? "Disable loop" : "Enable loop"}>
<Button onClick={() => onLoopAnimationChange(!loopAnimation)}>
{loopAnimation ?
<RepeatOnIcon /> :
<RepeatIcon />}
</Button>
</Tooltip>
<Tooltip title="Reset view">
<Button onClick={onFitView}>
<CropFreeIcon />
</Button>
</Tooltip>
</ButtonGroup>
</Box>
<Box
sx={{ width: 1/2 }}
display="flex"
justifyContent="center"
>
<Slider
value={speed}
step={0.2}
marks
min={0.2}
max={10}
valueLabelDisplay="auto"
onChange={handleSliderChange}
/>
<Box display='flex' justifyContent='center'>
<Tooltip title="Adjust animation step size (speed)">
<Slider
value={speed}
step={0.2}
marks
min={0.2}
max={10}
valueLabelDisplay="auto"
onChange={handleSliderChange}
sx={{ width: '50%' }}
/>
</Tooltip>
</Box>
</Box>
</Stack>
);
}

Expand Down
14 changes: 13 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import React from 'react';
import { StrictMode, useRef } from 'react';

function App() {
const pixiAppRef = useRef<{ skipBackward?: () => void; skipForward?: () => void; restart?: () => void; }>(null);
const pixiAppRef = useRef<{
skipBackward?: () => void;
skipForward?: () => void;
restart?: () => void;
fit?: () => void;
}>(null);

const [graph, setGraph] = React.useState<Graph | null>(null);
const [solution, setSolution] = React.useState<Solution | null>(null);
Expand All @@ -34,6 +39,12 @@ function App() {
}
}

const handleFitView = () => {
if (pixiAppRef.current?.fit) {
pixiAppRef.current.fit();
}
}

return (
<StrictMode>
<Box sx={{ flexGrow: 1 }}>
Expand Down Expand Up @@ -61,6 +72,7 @@ function App() {
onSpeedChange={(speed: number) => setSpeed(speed)}
loopAnimation={loopAnimation}
onLoopAnimationChange={(loopAnimation: boolean) => setLoopAnimation(loopAnimation)}
onFitView={handleFitView}
/>
</Grid>
</Grid>
Expand Down
3 changes: 3 additions & 0 deletions src/ConfigBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface ConfigBarProps {
onSpeedChange: (speed: number) => void;
loopAnimation: boolean,
onLoopAnimationChange: (loopAnimation: boolean) => void;
onFitView: () => void;
}

function ConfigBar({
Expand All @@ -32,6 +33,7 @@ function ConfigBar({
onSpeedChange,
loopAnimation,
onLoopAnimationChange,
onFitView,
}: ConfigBarProps) {
const repoName = "JustinShetty/mapf-visualizer";
return (
Expand All @@ -50,6 +52,7 @@ function ConfigBar({
onSpeedChange={onSpeedChange}
loopAnimation={loopAnimation}
onLoopAnimationChange={onLoopAnimationChange}
onFitView={onFitView}
/>
<Divider />
<a target="_blank" href={`https://github.com/${repoName}`} style={{ color: 'white' }}>
Expand Down
3 changes: 3 additions & 0 deletions src/PixiApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ const PixiApp = forwardRef(({
restart: () => {
resetTimestep();
},
fit: () => {
fit();
},
}));

// Fit the viewport to the grid
Expand Down

0 comments on commit b050d05

Please sign in to comment.