diff --git a/src/components/app.scss b/src/components/app.scss index e241817..700c7f8 100644 --- a/src/components/app.scss +++ b/src/components/app.scss @@ -107,6 +107,12 @@ } } + label { + display: block; + white-space: nowrap; + font-weight: bold; + } + .generate { display: flex; flex-direction: column; @@ -118,12 +124,6 @@ flex-direction: column; gap: 5px; - label { - display: block; - white-space: nowrap; - font-weight: bold; - } - select { padding: 2px; width: 100%; diff --git a/src/components/app.tsx b/src/components/app.tsx index 872d60c..2ece63a 100644 --- a/src/components/app.tsx +++ b/src/components/app.tsx @@ -116,7 +116,7 @@ export const App = () => { } }, [sequenceGroups]); - const graphEmpty = useCallback(() => graph.nodes.length === 0, [graph]); + const graphEmpty = useMemo(() => graph.nodes.length === 0, [graph]); const generateNewSequence = useCallback(async () => { currentSequence.current = []; @@ -274,7 +274,7 @@ export const App = () => { }, [generateNewSequence, animateCurrentSequenceIndex, startAnimationInterval]); const uiForGenerate = () => { - const disabled = graphEmpty(); + const disabled = graphEmpty; const playLabel = generationMode === "playing" ? "Pause" : (generationMode === "paused" ? "Resume" : "Play"); const PlayOrPauseIcon = generationMode === "playing" ? PauseIcon : PlayIcon; const onPlayClick = generationMode === "playing" @@ -346,6 +346,7 @@ export const App = () => { const disabled = sequenceGroups.length === 0; return (
+
{sequenceGroups.map((group, i) => { @@ -382,6 +383,19 @@ export const App = () => { notifyStateIsDirty(); }; + const handleReset = () => { + if (confirm("Are you sure you want to reset?\n\nAny changes you have made will be lost.")) { + setGraph({nodes: [], edges: []}); + } + }; + + const handleReturnToMainMenu = () => { + if (confirm("Are you sure you want to reset?\n\nAny changes you have made will be lost.")) { + setGraph({nodes: [], edges: []}); + setViewMode(undefined); + } + }; + if (loadState === "loading") { return
Loading ...
; } @@ -410,23 +424,18 @@ export const App = () => { ); } - if (graphEmpty() && viewMode === "dataset") { + const maybeRenderRightBar = () => { + if (viewMode === "dataset" && graphEmpty) { + return; + } + return ( -
-
-

Markov Chains

-

- This plugin generates sequences of text using a Markov chain. The plugin uses a Markov chain built from a - dataset in CODAP. The dataset must have a column of states. The plugin will build a Markov chain from the - states, and then allow generation of a sequence of text using the Markov chain. -

-

- To use the plugin, first drag an attribute into the plugin. -

-
+
+ {uiForGenerate()} + {sequenceOutput()}
); - } + }; return (
@@ -445,6 +454,8 @@ export const App = () => { setGraph={setGraph} setHighlightNode={setHighlightNode} setSelectedNodeId={setSelectedNodeId} + onReset={handleReset} + onReturnToMainMenu={handleReturnToMainMenu} /> : { highlightAllNextNodes={highlightAllNextNodes} selectedNodeId={selectedNodeId} animating={animating} + graphEmpty={graphEmpty} setSelectedNodeId={setSelectedNodeId} + onReset={handleReset} + onReturnToMainMenu={handleReturnToMainMenu} /> }
-
- {uiForGenerate()} - {sequenceOutput()} -
+ {maybeRenderRightBar()}
); diff --git a/src/components/dataset.tsx b/src/components/dataset.tsx index 3b8b11e..3cffe0a 100644 --- a/src/components/dataset.tsx +++ b/src/components/dataset.tsx @@ -13,22 +13,53 @@ interface Props { graph: GraphData; selectedNodeId?: string; animating: boolean; + graphEmpty: boolean; setSelectedNodeId: (id?: string, skipToggle?: boolean) => void; + onReset: () => void; + onReturnToMainMenu: () => void; } -const tools: Tool[] = ["select","fitView","recenter","reset","home"]; - export const Dataset = (props: Props) => { const {highlightNode, highlightLoopOnNode, highlightEdge, highlightAllNextNodes, - graph, setSelectedNodeId, selectedNodeId, animating} = props; + graph, graphEmpty, setSelectedNodeId, selectedNodeId, animating, onReset, onReturnToMainMenu} = props; + const handleToolSelected = (tool: Tool) => { // TBD }; + if (graphEmpty) { + return ( +
+ +
+

Markov Chains

+

+ This plugin generates sequences of text using a Markov chain. The plugin uses a Markov chain built from a + dataset in CODAP. The dataset must have a column of states. The plugin will build a Markov chain from the + states, and then allow generation of a sequence of text using the Markov chain. +

+

+ To use the plugin, first drag an attribute into the plugin. +

+
+
+ ); + } + return (
- + >; setHighlightNode: React.Dispatch> setSelectedNodeId: (id?: string, skipToggle?: boolean) => void; + onReset: () => void; + onReturnToMainMenu: () => void; } export const Drawing = (props: Props) => { const {highlightNode, highlightLoopOnNode, highlightEdge, highlightAllNextNodes, - graph, setGraph, setHighlightNode, setSelectedNodeId: _setSelectedNodeId, selectedNodeId, animating} = props; + graph, setGraph, setHighlightNode, setSelectedNodeId: _setSelectedNodeId, + selectedNodeId, animating, onReset, onReturnToMainMenu} = props; const [drawingMode, setDrawingMode] = useState("select"); const [firstEdgeNode, setFirstEdgeNode] = useState(undefined); const [rubberBand, setRubberBand] = useState(undefined); @@ -124,7 +127,6 @@ export const Drawing = (props: Props) => { }, [setGraph]); const handleClicked = useCallback((e: React.MouseEvent) => { - console.log("HANDLE CLICKED"); if (drawingMode === "addNode") { addNode(translateToGraphPoint(e)); // handleSetSelectMode(); @@ -244,7 +246,12 @@ export const Drawing = (props: Props) => { return (
- + void; + onReset: () => void; + onReturnToMainMenu: () => void; } export const ToolbarButton = ({tool, selectedTool, onClick}: ToolbarButtonProps) => { @@ -74,12 +76,16 @@ export const ToolbarButton = ({tool, selectedTool, onClick}: ToolbarButtonProps) ); }; -export const Toolbar = ({tools, onToolSelected}: ToolbarProps) => { +export const Toolbar = ({tools, onToolSelected, onReset, onReturnToMainMenu}: ToolbarProps) => { const [selectedTool, setSelectedTool] = useState("select"); const handleToolSelected = (tool: Tool) => { if (toggleableTools.includes(tool)) { setSelectedTool(tool); + } else if (tool === "reset") { + onReset(); + } else if (tool === "home") { + onReturnToMainMenu(); } onToolSelected(tool); };