-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPetriNetTransitionSVG.tsx
More file actions
69 lines (64 loc) · 1.88 KB
/
PetriNetTransitionSVG.tsx
File metadata and controls
69 lines (64 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { useDiagramStore } from "@/store"
import { useShallow } from "zustand/shallow"
import AssessmentIcon from "../../AssessmentIcon"
import { SVGComponentProps } from "@/types/SVG"
import { CustomText } from "../CustomText"
import { StyledRect } from "@/components"
import { DefaultNodeProps } from "@/types"
import { LAYOUT } from "@/constants"
import { getCustomColorsFromData } from "@/utils/layoutUtils"
interface Props extends SVGComponentProps {
data: DefaultNodeProps
}
export const PetriNetTransitionSVG: React.FC<Props> = ({
id,
svgAttributes,
SIDEBAR_PREVIEW_SCALE,
showAssessmentResults = false,
width,
height,
data,
}) => {
const { name } = data
const assessments = useDiagramStore(useShallow((state) => state.assessments))
const nodeScore = assessments[id]?.score
const previewScale = SIDEBAR_PREVIEW_SCALE ?? 1
const scaledWidth = width * previewScale
const scaledHeight = height * previewScale
const labelHeight = LAYOUT.DEFAULT_ATTRIBUTE_HEIGHT
const scaledLabelHeight = labelHeight * previewScale
const svgHeight = height + labelHeight
const scaledSvgHeight = scaledHeight + scaledLabelHeight
const { fillColor, strokeColor, textColor } = getCustomColorsFromData(data)
return (
<svg
width={scaledWidth}
height={scaledSvgHeight}
viewBox={`0 0 ${width} ${svgHeight}`}
overflow="visible"
{...svgAttributes}
>
<StyledRect
x={0}
y={0}
width={width}
height={height}
fill={fillColor}
stroke={strokeColor}
/>
<CustomText
x={width / 2}
y={height + labelHeight / 2}
textAnchor="middle"
fontWeight="600"
dominantBaseline="middle"
fill={textColor}
>
{name}
</CustomText>
{showAssessmentResults && (
<AssessmentIcon x={width - 15} y={-15} score={nodeScore} />
)}
</svg>
)
}