import "./Node.css" import * as React from "react" import classnames from "classnames" import useTooltip from "../Tooltip/useTooltip" import { Tooltip } from "../Tooltip/Tooltip" import NumberOfChildren, { NumberOfChildrenPlacement } from "./NumberOfChildren" import { getNumberItemsWidthByNumberOfChars } from "./helpers" import LabelNewLine from "./LabelNewLine" export interface NodeProps { /* HierarchyRectangularNode properties */ x0?: number y0?: number x1?: number y1?: number bgColor: string borderColor: string textColorBorderColorBg: string textColor: string className?: string hasChildren: boolean id: number isSelectedNode: boolean label: string nodeTotalNodes: number numberOfChildrenPlacement: NumberOfChildrenPlacement onClickDrillDown?: (ev?: React.MouseEvent) => void onClick?: (ev?: React.MouseEvent) => void onClickBack?: (ev?: React.MouseEvent) => void style?: React.CSSProperties treemapId?: string url: string value: string splitRegExp?: RegExp } const Node: React.FunctionComponent = ({ bgColor, borderColor, textColorBorderColorBg, className, hasChildren, id, isSelectedNode, label, nodeTotalNodes, onClick, onClickBack, onClickDrillDown, textColor, treemapId, url, value, x0, x1, y0, y1, style, numberOfChildrenPlacement, splitRegExp, }) => { const currentXTranslated = Math.max(0, x0) const currentYTranslated = Math.max(0, y0) const currentWidth = Math.max(0, x1 - x0) const currentHeight = Math.max(0, y1 - y0) const fontSize = Number(style.fontSize) const itemsWidth = getNumberItemsWidthByNumberOfChars( fontSize, nodeTotalNodes.toString().length ) const showNumberOfItems = !(numberOfChildrenPlacement === NumberOfChildrenPlacement.None) && hasChildren const nodePaddingTop = !isNaN(style.paddingTop as number) ? Number(style.paddingTop) : 2 const nodePaddingLeft = !isNaN(style.paddingLeft as number) ? Number(style.paddingLeft) : 5 const nodePaddingRight = !isNaN(style.paddingRight as number) ? Number(style.paddingRight) : 5 const paddedCurrentWidth = currentWidth - nodePaddingLeft - nodePaddingRight const clipWidth = Math.max( 0, showNumberOfItems && numberOfChildrenPlacement === NumberOfChildrenPlacement.TopRight ? paddedCurrentWidth - itemsWidth : paddedCurrentWidth ) const { hideTooltip, showTooltip, disableTooltip } = useTooltip() const handleMouseMove = React.useCallback( (ev: React.MouseEvent) => { showTooltip(, ev) }, [label, showTooltip, value] ) const handleMouseLeave = React.useCallback(() => { hideTooltip() }, [hideTooltip]) const extraPadding = onClickBack || onClickDrillDown ? 20 : 0 return ( {onClickBack ? ( ) : null} {onClickDrillDown ? ( ) : null} {showNumberOfItems && ( )} ) } export default Node