From 5b6061c51af0772c986703db855c67f429bba86b Mon Sep 17 00:00:00 2001 From: Doug Martin Date: Thu, 26 Sep 2024 11:08:36 -0400 Subject: [PATCH] feat: Add transition probabilities to dataset mode [PT-188245100] --- src/components/app.scss | 46 +++++++++++++++++++ src/components/dataset.tsx | 17 ++++++- src/components/drawing.scss | 44 ------------------ src/components/drawing.tsx | 1 + src/components/drawing/node-modal.tsx | 28 ++++++++++- .../drawing/probability-selector.tsx | 11 +++-- 6 files changed, 98 insertions(+), 49 deletions(-) diff --git a/src/components/app.scss b/src/components/app.scss index f3946d3..222fb4e 100644 --- a/src/components/app.scss +++ b/src/components/app.scss @@ -245,5 +245,51 @@ } } + .nodeModalBackground { + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 0; + background: #000; + opacity: 0.25; + z-index: 100; + } + .nodeModal { + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 0; + display: flex; + justify-content: center; + align-items: center; + z-index: 101; + user-select: none; + + .nodeModalContent { + min-width: 200px; + + .nodeModalTitle { + background-color: #177991; + color: white; + padding: 5px 10px; + } + + form { + padding: 10px; + background-color: white; + display: flex; + flex-direction: column; + gap: 10px; + + .nodeModalButtons { + display: flex; + gap: 5px; + justify-content: flex-end; + } + } + } + } } diff --git a/src/components/dataset.tsx b/src/components/dataset.tsx index b7b6065..89cfa4a 100644 --- a/src/components/dataset.tsx +++ b/src/components/dataset.tsx @@ -1,7 +1,8 @@ -import React from "react"; +import React, { useState } from "react"; import { Tool, Toolbar } from "./toolbar"; import { Graph } from "./graph"; import { Node, Edge, GraphData } from "../type"; +import { NodeModal } from "./drawing/node-modal"; import "./dataset.scss"; @@ -30,11 +31,17 @@ export const Dataset = (props: Props) => { graph, graphEmpty, setSelectedNodeId, selectedNodeId, animating, fitViewAt, recenterViewAt, onReset, onReturnToMainMenu, onFitView, onRecenterView} = props; + const [selectedNodeForModal, setSelectedNodeForModal] = useState(undefined); const handleToolSelected = (tool: Tool) => { // TBD }; + const handleNodeDoubleClicked = (id: string) => { + setSelectedNodeForModal(graph.nodes.find(n => n.id === id)); + }; + const handleClearSelectedNode = () => setSelectedNodeForModal(undefined); + if (graphEmpty) { return (
@@ -82,6 +89,7 @@ export const Dataset = (props: Props) => { highlightAllNextNodes={highlightAllNextNodes} highlightOutputNodes={highlightOutputNodes} selectedNodeId={selectedNodeId} + onNodeDoubleClick={handleNodeDoubleClicked} animating={animating} allowDragging={true && !animating} autoArrange={true} @@ -89,6 +97,13 @@ export const Dataset = (props: Props) => { fitViewAt={fitViewAt} recenterViewAt={recenterViewAt} /> + undefined} + onCancel={handleClearSelectedNode} + />
); }; diff --git a/src/components/drawing.scss b/src/components/drawing.scss index 3ce7fbf..7d88d29 100644 --- a/src/components/drawing.scss +++ b/src/components/drawing.scss @@ -11,50 +11,6 @@ pointer-events: none; } - .nodeModalBackground { - position: absolute; - top: 0; - right: 0; - bottom: 0; - left: 0; - background: #000; - opacity: 0.25; - z-index: 100; - } - .nodeModal { - position: absolute; - top: 0; - right: 0; - bottom: 0; - left: 0; - display: flex; - justify-content: center; - align-items: center; - z-index: 101; - - .nodeModalContent { - min-width: 200px; - .nodeModalTitle { - background-color: #177991; - color: white; - padding: 5px 10px; - } - - form { - padding: 10px; - background-color: white; - display: flex; - flex-direction: column; - gap: 10px; - - .nodeModalButtons { - display: flex; - gap: 5px; - justify-content: flex-end; - } - } - } - } } \ No newline at end of file diff --git a/src/components/drawing.tsx b/src/components/drawing.tsx index 4dc8f76..23aa1ce 100644 --- a/src/components/drawing.tsx +++ b/src/components/drawing.tsx @@ -335,6 +335,7 @@ export const Drawing = (props: Props) => { /> void, onCancel: () => void } -export const NodeModal = ({ node, graph, onChange, onCancel }: NodeModalProps) => { +export const NodeModal = ({ viewMode, node, graph, onChange, onCancel }: NodeModalProps) => { const [label, setLabel] = useState(node?.label || ""); const [exactPercentages, _setExactPercentages] = useState([]); @@ -68,6 +70,29 @@ export const NodeModal = ({ node, graph, onChange, onCancel }: NodeModalProps) = return null; } + if (viewMode === "dataset") { + return ( + <> +
+
+
+
State: {label}
+
+ +
+ +
+ +
+
+ + ); + } + return ( <>
@@ -77,6 +102,7 @@ export const NodeModal = ({ node, graph, onChange, onCancel }: NodeModalProps) =
diff --git a/src/components/drawing/probability-selector.tsx b/src/components/drawing/probability-selector.tsx index 461a643..3b8cb73 100644 --- a/src/components/drawing/probability-selector.tsx +++ b/src/components/drawing/probability-selector.tsx @@ -1,4 +1,5 @@ import React, { useCallback, useMemo } from "react"; +import { ViewMode } from "../../hooks/use-codap"; import "./probability-selector.scss"; @@ -15,6 +16,7 @@ interface ProbabilitySelectorThumbProps { } interface ProbabilitySelectorProps { + viewMode: ViewMode; exactPercentages: number[] edgeLabels: string[] onChange: (newPercentages: number[]) => void @@ -73,7 +75,7 @@ export const ProbabilitySelectorThumb = (props: ProbabilitySelectorThumbProps) = ); }; -export const ProbabilitySelector = ({exactPercentages, edgeLabels, onChange}: ProbabilitySelectorProps) => { +export const ProbabilitySelector = ({viewMode, exactPercentages, edgeLabels, onChange}: ProbabilitySelectorProps) => { const roundPercentages = useMemo(() => { const result = exactPercentages.slice(0, -1).map(exactPercentage => Math.round(exactPercentage)); @@ -135,13 +137,15 @@ export const ProbabilitySelector = ({exactPercentages, edgeLabels, onChange}: Pr } }, [exactPercentages, onChange]); - if (exactPercentages.length < 2) { + const isDrawingMode = viewMode === "drawing"; + if (isDrawingMode && (exactPercentages.length < 2)) { return null; } return (
Transition Probabilities
+ {isDrawingMode &&
{segments.map(({start, end}, i) => ( @@ -166,9 +170,10 @@ export const ProbabilitySelector = ({exactPercentages, edgeLabels, onChange}: Pr ))}
+ }
{roundPercentages.map((p, i) => ( -
To {edgeLabels[i]}: {p}%
+
To {edgeLabels[i]}: {p}%
))}