Skip to content

Commit

Permalink
Add color function
Browse files Browse the repository at this point in the history
  • Loading branch information
Elscrux authored and schweikart committed Mar 28, 2024
1 parent 621689a commit 28f7e26
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/components/solvers/Graph/ProblemGraphView.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Property } from "csstype";
import { useEffect } from "react";
import {
Controls,
Expand All @@ -14,6 +15,20 @@ import {
} from "../../../api/data-model/ProblemGraph";
import { SolutionStatus } from "../../../api/data-model/SolutionStatus";
import { fetchSolvers } from "../../../api/ToolboxAPI";
import Color = Property.Color;

function getStatusColor(status: SolutionStatus): Color {
switch (status) {
case SolutionStatus.INVALID:
return "red";
case SolutionStatus.COMPUTING:
return "cornflowerblue";
case SolutionStatus.SOLVED:
return "teal";
case SolutionStatus.PENDING_USER_ACTION:
return "ghostwhite";
}
}

export const ProblemGraphView = (props: { graph: ProblemGraph | null }) => {
const [nodes, setNodes, onNodesChange] = useNodesState<Node[]>([]);
Expand Down Expand Up @@ -86,14 +101,13 @@ export const ProblemGraphView = (props: { graph: ProblemGraph | null }) => {
data: data,
position: position,
type: type,
style: {
background: getStatusColor(problemNode.status),
},
};

// Load decision nodes when user action is required
if (problemNode.status == SolutionStatus.PENDING_USER_ACTION) {
node.style = {
background: "teal",
};

fetchSolvers(problemNode.problemType).then((solvers) => {
node.type = "default";
for (let i = 0; i < solvers.length; i++) {
Expand All @@ -110,7 +124,9 @@ export const ProblemGraphView = (props: { graph: ProblemGraph | null }) => {
},
type: "output",
style: {
background: "teal",
background: getStatusColor(
SolutionStatus.PENDING_USER_ACTION
),
},
});

Expand All @@ -121,9 +137,6 @@ export const ProblemGraphView = (props: { graph: ProblemGraph | null }) => {
target: solverId,
});
}
node.style = {
background: "grey",
};

setNodes(nodes);
setEdges(edges);
Expand Down

0 comments on commit 28f7e26

Please sign in to comment.