Skip to content

Commit 04772d8

Browse files
committed
Add solver characteristics based on theoretical paper concepts
Modify some icon-text margins
1 parent 4269cb9 commit 04772d8

4 files changed

Lines changed: 98 additions & 10 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
export enum SolverCharacteristic {
2+
Solve = "SOLVE",
3+
Reformulation = "REFORMULATION",
4+
Decomposition = "DECOMPOSITION",
5+
}
6+
17
export interface ProblemSolverInfo {
28
id: string;
39
name: string;
410
description: string;
11+
characteristics?: SolverCharacteristic[];
512
}

src/components/solvers/Graph/ProblemNode.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ export function ProblemNode(props: NodeProps<ProblemNodeData>) {
372372
id: solverId,
373373
name: solverName,
374374
description: solverDescription,
375+
characteristics: solver?.characteristics,
375376
}}
376377
button={problemButton()}
377378
/>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { Box, HStack, Tooltip } from "@chakra-ui/react";
2+
import { ComponentType } from "react";
3+
import { FaGears } from "react-icons/fa6";
4+
import { LuReplace } from "react-icons/lu";
5+
import { PiTreeStructure } from "react-icons/pi";
6+
import { TbTargetArrow } from "react-icons/tb";
7+
import { SolverCharacteristic } from "../../../api/toolbox/data-model/ProblemSolverInfo";
8+
9+
export const characteristicPresentation: Record<
10+
SolverCharacteristic,
11+
{
12+
label: string;
13+
color: string;
14+
icon: ComponentType<{ size?: string }>;
15+
tooltip: string;
16+
}
17+
> = {
18+
[SolverCharacteristic.Solve]: {
19+
label: "Solve",
20+
color: "green.500",
21+
icon: TbTargetArrow,
22+
tooltip: "Solve: obtains a solution for the problem.",
23+
},
24+
[SolverCharacteristic.Reformulation]: {
25+
label: "Reformulate",
26+
color: "blue.500",
27+
icon: LuReplace,
28+
tooltip: "Reformulate: maps the problem onto another problem type.",
29+
},
30+
[SolverCharacteristic.Decomposition]: {
31+
label: "Decompose",
32+
color: "purple.500",
33+
icon: PiTreeStructure,
34+
tooltip: "Decompose: splits the problem into several subproblems.",
35+
},
36+
};
37+
38+
export interface SolverCharacteristicIconsProps {
39+
characteristics?: SolverCharacteristic[];
40+
}
41+
42+
export const SolverCharacteristicIcons = (
43+
props: SolverCharacteristicIconsProps,
44+
) => {
45+
const characteristics = props.characteristics ?? [];
46+
if (characteristics.length === 0) {
47+
// fallback to previous icon
48+
return (
49+
<Tooltip hasArrow label="Solver" placement="bottom">
50+
<Box display="inline-flex" marginTop="0.35rem">
51+
<FaGears size="1.5rem" />
52+
</Box>
53+
</Tooltip>
54+
);
55+
}
56+
57+
return (
58+
<HStack spacing="0.2rem" marginTop="0.4rem">
59+
{characteristics.map((characteristic) => {
60+
const presentation = characteristicPresentation[characteristic];
61+
const Icon = presentation.icon;
62+
return (
63+
<Tooltip
64+
key={characteristic}
65+
hasArrow
66+
label={presentation.tooltip}
67+
placement="bottom"
68+
>
69+
<Box as="span" color={presentation.color} display="inline-flex">
70+
<Icon size="1.5rem" />
71+
</Box>
72+
</Tooltip>
73+
);
74+
})}
75+
</HStack>
76+
);
77+
};

src/components/solvers/Graph/SolverNodeContent.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ import {
1111
PopoverTrigger,
1212
Portal,
1313
Text,
14-
Tooltip,
1514
VStack,
1615
} from "@chakra-ui/react";
1716
import { ReactNode } from "react";
1817
import { FaQuestionCircle } from "react-icons/fa";
19-
import { FaGears } from "react-icons/fa6";
2018
import { ProblemSolverInfo } from "../../../api/toolbox/data-model/ProblemSolverInfo";
19+
import { SolverCharacteristicIcons } from "./SolverCharacteristicIcons";
2120

2221
export interface SolverNodeContentProps {
2322
solver: ProblemSolverInfo;
@@ -30,19 +29,17 @@ export interface SolverNodeContentProps {
3029
export const SolverNodeContent = (props: SolverNodeContentProps) => {
3130
return (
3231
<VStack gap="0px">
33-
<HStack align="start" maxW="10rem" justifyContent="space-between" gap="0">
34-
<Tooltip hasArrow label="Solver" placement="bottom">
35-
<div>
36-
<FaGears size="2rem" />
37-
</div>
38-
</Tooltip>
39-
<Text padding=".25rem" fontWeight="semibold">
32+
<HStack align="start" maxW="10rem" justifyContent="space-between">
33+
<SolverCharacteristicIcons
34+
characteristics={props.solver.characteristics}
35+
/>
36+
<Text paddingY=".25rem" fontWeight="semibold">
4037
{props.solver.name}
4138
</Text>
4239

4340
<Popover>
4441
<PopoverTrigger>
45-
<div>
42+
<div style={{ marginTop: "0.5rem" }}>
4643
<FaQuestionCircle size="1rem" />
4744
</div>
4845
</PopoverTrigger>
@@ -64,6 +61,12 @@ export const SolverNodeContent = (props: SolverNodeContentProps) => {
6461
</Popover>
6562
</HStack>
6663

64+
{/*
65+
<SolverCharacteristicBadges
66+
characteristics={props.solver.characteristics}
67+
/>
68+
*/}
69+
6770
<div
6871
style={{
6972
display: "flex",

0 commit comments

Comments
 (0)