1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. import * as React from 'react';
    
  11. 
    
  12. import styles from './ChartNode.css';
    
  13. 
    
  14. type Props = {
    
  15.   color: string,
    
  16.   height: number,
    
  17.   isDimmed?: boolean,
    
  18.   label: string,
    
  19.   onClick: (event: SyntheticMouseEvent<any>) => mixed,
    
  20.   onDoubleClick?: (event: SyntheticMouseEvent<any>) => mixed,
    
  21.   onMouseEnter: (event: SyntheticMouseEvent<any>) => mixed,
    
  22.   onMouseLeave: (event: SyntheticMouseEvent<any>) => mixed,
    
  23.   placeLabelAboveNode?: boolean,
    
  24.   textStyle?: Object,
    
  25.   width: number,
    
  26.   x: number,
    
  27.   y: number,
    
  28. };
    
  29. 
    
  30. const minWidthToDisplay = 35;
    
  31. 
    
  32. export default function ChartNode({
    
  33.   color,
    
  34.   height,
    
  35.   isDimmed = false,
    
  36.   label,
    
  37.   onClick,
    
  38.   onMouseEnter,
    
  39.   onMouseLeave,
    
  40.   onDoubleClick,
    
  41.   textStyle,
    
  42.   width,
    
  43.   x,
    
  44.   y,
    
  45. }: Props): React.Node {
    
  46.   return (
    
  47.     <g className={styles.Group} transform={`translate(${x},${y})`}>
    
  48.       <rect
    
  49.         width={width}
    
  50.         height={height}
    
  51.         fill={color}
    
  52.         onClick={onClick}
    
  53.         onMouseEnter={onMouseEnter}
    
  54.         onMouseLeave={onMouseLeave}
    
  55.         onDoubleClick={onDoubleClick}
    
  56.         className={styles.Rect}
    
  57.         style={{
    
  58.           opacity: isDimmed ? 0.5 : 1,
    
  59.         }}
    
  60.       />
    
  61.       {width >= minWidthToDisplay && (
    
  62.         <foreignObject
    
  63.           width={width}
    
  64.           height={height}
    
  65.           className={styles.ForeignObject}
    
  66.           style={{
    
  67.             paddingLeft: x < 0 ? -x : 0,
    
  68.             opacity: isDimmed ? 0.75 : 1,
    
  69.             display: width < minWidthToDisplay ? 'none' : 'block',
    
  70.           }}
    
  71.           y={0}>
    
  72.           <div className={styles.Div} style={textStyle}>
    
  73.             {label}
    
  74.           </div>
    
  75.         </foreignObject>
    
  76.       )}
    
  77.     </g>
    
  78.   );
    
  79. }