All files / src/pages/flowsheet-page/flowsheet/Canvas/Nodes MaterialStreamGraphic.tsx

94.44% Statements 34/36
76% Branches 19/25
83.33% Functions 5/6
93.93% Lines 31/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169                            49x 9561x   9561x 9561x 9561x 9561x   9561x   9561x   9561x 9561x   9561x 9561x   9561x   9561x                 9561x   9561x 4799x 4799x                                   9561x 841x           841x                                   9561x 3921x                                                                 9561x                                                     9561x 9561x   9561x 8400x 7559x 3921x     9561x                
import { ObjectTypeEnum } from "@/api/apiStore.gen";
import { useObjectsPortsMap } from "@/hooks/flowsheetObjects";
import { GenericObjectGraphicProps } from "@/hooks/graphicTypes";
import { isStream } from "../../../../../lib/isStream";
import useHoverDebounce from "../DebounceHoverObject";
import {
  Circle,
  FeedIcon,
  fillColor,
  InnerCircle,
  strokeColor,
  ZapIcon,
} from "./HelperFunctions";
 
const MaterialStreamGraphic = (props: GenericObjectGraphicProps) => {
  const gObj = props.graphicObject;
 
  const objPortsMap = useObjectsPortsMap();
  const objPorts = objPortsMap.get(props.simulationObject.id);
  const nodeWidth = gObj.width ?? 40;
  const nodeHeight = gObj.height ?? 40;
 
  const size = Math.min(nodeWidth, nodeHeight);
  const isEnergy =
    props.simulationObject.objectType === ObjectTypeEnum.EnergyStream;
 
  const flipped = !!(gObj.flipped ?? (gObj as any).is_flipped);
  const rotation = gObj.rotation ?? 0;
 
  const commonStroke = strokeColor(props);
  const commonFill = fillColor(props);
 
  useHoverDebounce(!!props.isHovered, props.simulationObject);
 
  const ICONS = {
    feed: "../../assets/UpdatedIcons/connected.svg",
    powerFeed: "../../assets/UpdatedIcons/powerconnected.svg",
    intermediate: "../../assets/UpdatedIcons/feed.svg",
    intermediatePower: "../../assets/UpdatedIcons/feedpowerl.svg",
    intermediatePowerFlipped: "../../assets/UpdatedIcons/feedleftpowerl.svg",
    decisionHalf: "../../assets/UpdatedIcons/halfDecisionNode.svg",
  } as const;
 
  const iconSize = size / 1.5;
 
  const feed = () => {
    const src = isEnergy ? ICONS.powerFeed : ICONS.feed;
    return (
      <>
        <Circle
          size={size}
          fill={commonFill}
          stroke={commonStroke}
          strokeWidth={2}
        />
        <FeedIcon
          src={src}
          size={iconSize}
          rotation={rotation}
          flipped={flipped}
        />
      </>
    );
  };
 
  const intermediate = () => {
    const src = isEnergy
      ? flipped
        ? ICONS.intermediatePowerFlipped
        : ICONS.intermediatePower
      : ICONS.intermediate;
 
    return (
      <>
        <Circle
          size={size}
          fill={commonFill}
          stroke={commonStroke}
          strokeWidth={2}
        />
        <FeedIcon
          src={src}
          size={iconSize}
          rotation={rotation}
          flipped={flipped}
        />
      </>
    );
  };
 
  const product = () => {
    return (
      <>
        <Circle
          size={size}
          fill={commonFill}
          stroke={commonStroke}
          strokeWidth={2}
        />
 
        {isStream(props.simulationObject) &&
          props.simulationObject.objectType !== ObjectTypeEnum.EnergyStream && (
            <InnerCircle size={size} inset={5} fill="#000000" />
          )}
 
        {props.simulationObject.objectType === ObjectTypeEnum.EnergyStream && (
          <div
            style={{
              position: "absolute",
              inset: 0,
              display: "grid",
              placeItems: "center",
              pointerEvents: "none",
              userSelect: "none",
            }}
            aria-hidden="true"
          >
            <ZapIcon sizePercent={80} fill="#FFB300" />
          </div>
        )}
      </>
    );
  };
 
  const decisionNode = () => {
    return (
      <>
        <Circle
          size={size}
          fill={commonFill}
          stroke={commonStroke}
          strokeWidth={2}
        />
        <img
          src={ICONS.decisionHalf}
          alt=""
          draggable={false}
          style={{
            position: "absolute",
            left: 0,
            top: 5,
            width: size,
            height: size,
            pointerEvents: "none",
            userSelect: "none",
          }}
        />
      </>
    );
  };
 
  const renderIcon = () => {
    Iif (props.simulationObject.objectType === "decisionNode")
      return decisionNode();
    if (!objPorts || objPorts.length === 0) return feed();
    if (objPorts.length === 2) return intermediate();
    if (objPorts[0].direction === "inlet") return feed();
    return product();
  };
 
  return (
    <div style={{ position: "relative", width: size, height: size }}>
      {renderIcon()}
    </div>
  );
};
 
export default MaterialStreamGraphic;