-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* make sequence diagram horizontal * horizontal sequence diagram to show messages * move into TimeTravelSlider * introduce lerp and resize observer * padding * tweak widths * put input on top of diagram * disable explore button if there's no choose fn * still show hops in sequence diagram when we rewind * break out time travel slider * put explore form inside of time travel slider * rearrange slider * filter out user ticks * try putting ticks into the diagram * fix ticks * fix up patterns ugh I hate the lack of type safety * fix maxTime calculation
- Loading branch information
Showing
11 changed files
with
259 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import React from "react"; | ||
import useResizeObserver from "use-resize-observer"; | ||
import { AbstractInterpreter } from "../../../core/abstractInterpreter"; | ||
import { rec, varr } from "../../../core/types"; | ||
import { SequenceDiagram } from "../../../uiCommon/visualizations/sequence"; | ||
import { TimeTravelAction } from "../types"; | ||
|
||
export function TimeTravelSlider<St, Msg>(props: { | ||
interp: AbstractInterpreter; | ||
curIdx: number; | ||
historyLength: number; | ||
exploreEnabled: boolean; | ||
dispatch: (action: TimeTravelAction<St, Msg>) => void; | ||
}) { | ||
const { ref, width } = useResizeObserver(); | ||
|
||
const atEnd = | ||
props.historyLength === 0 || props.curIdx === props.historyLength - 1; | ||
|
||
return ( | ||
<div ref={ref}> | ||
<div style={{ display: "flex", flexDirection: "row" }}> | ||
{props.curIdx}/{props.historyLength - 1}{" "} | ||
<input | ||
type="range" | ||
min={0} | ||
max={props.historyLength - 1} | ||
value={props.curIdx} | ||
style={{ width: width - 40 }} | ||
onChange={(evt) => | ||
props.dispatch({ | ||
type: "TimeTravelTo", | ||
idx: parseInt(evt.target.value), | ||
}) | ||
} | ||
/> | ||
<button | ||
disabled={atEnd} | ||
onClick={() => props.dispatch({ type: "Branch" })} | ||
> | ||
Branch | ||
</button>{" "} | ||
</div> | ||
<SequenceDiagram | ||
interp={props.interp} | ||
id={"sequence"} | ||
spec={rec("sequence", { | ||
actors: rec("clientServerActor", { id: varr("ID") }), | ||
ticks: rec("clientServerTick", { | ||
time: varr("Time"), | ||
place: varr("Place"), | ||
}), | ||
hops: rec("clientServerHop", { | ||
from: varr("FromTick"), | ||
to: varr("ToTick"), | ||
}), | ||
})} | ||
width={width} | ||
highlightedTerm={null} | ||
setHighlightedTerm={() => {}} | ||
runStatements={() => {}} | ||
/> | ||
{/* controls */} | ||
<ExploreForm | ||
disabled={props.exploreEnabled} | ||
onExplore={(steps) => props.dispatch({ type: "Explore", steps })} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
const DEFAULT_STEP_LIMIT = 100; | ||
|
||
function ExploreForm(props: { | ||
disabled: boolean; | ||
onExplore: (steps: number) => void; | ||
}) { | ||
const [steps, setSteps] = React.useState(DEFAULT_STEP_LIMIT); | ||
|
||
return ( | ||
<form onSubmit={() => props.onExplore(steps)}> | ||
<button type="submit" disabled={props.disabled}> | ||
Explore | ||
</button>{" "} | ||
<input | ||
type="number" | ||
min={0} | ||
max={3_000} | ||
value={steps} | ||
onChange={(evt) => setSteps(parseInt(evt.target.value))} | ||
/>{" "} | ||
steps | ||
</form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.