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

65.38% Statements 51/78
61.72% Branches 50/81
66.66% Functions 2/3
80.43% Lines 37/46

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                          10816x 10816x   10816x 16308x 10816x 10816x   10816x   10816x   10816x 10816x   12996x 12996x   10816x             10816x   10816x   10816x 1628x                                 15394x   10816x 298x       298x                                   15394x   10816x   1103x                                                           13300x   10816x                                                 12673x   10816x     512x 298x 1116x   28990x     3057x 10816x 11184x   13845x 19987x          
import { ObjectTypeEnum } from "@/api/apiStore.gen";
import { useObjectsPortsMap } from "@/hooks/flowsheetObjects";
import { GenericObjectGraphicProps } from "@/hooks/graphicTypes";
import { isStreamType } from "../../../../../lib/isStream";
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.is_flipped);
  const rotation = gObj.rotation ?? 0;
 
  const commonStroke = strokeColor(props);
  const commonFill = fillColor(props);
 
  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}
        />
 
        {isStreamType(props.simulationObject.objectType) &&
          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();
    Iif (!objPorts || objPorts.length === 0) return feed();
    Iif (objPorts.length === 2) return intermediate();
    Iif (objPorts[0].direction === "inlet") return feed();
    return product();
  };
 
  return (
    <div
      aria-label={`Graphic - ${props.simulationObject.componentName ?? ""}`}
      style={{ position: "relative", width: size, height: size }}
    >
      {renderIcon()}
    </div>
  );
};
 
export default MaterialStreamGraphic;