import { Utility } from "@hpcc-js/common"; import * as React from "@hpcc-js/preact-shim"; import { Icon } from "./icon"; import { TextBox } from "./text"; import { VertexProps } from "./vertex"; export interface Vertex3Props extends VertexProps { id: string; origData?: any; categoryID?: string; text: string; textHeight?: number; textPadding?: number; textboxStrokeWidth?: number; icon?: Icon; annotations?: Icon[]; annotationsHeight?: number; annotationGutter?: number; textFill?: string; textboxFill?: string; textboxStroke?: string; textFontFamily?: string; cornerRadius?: number; subText?: TextBox; onSizeUpdate?: (size: { width: number, height: number }) => void; showLabel?: boolean; noLabelRadius?: number; expansionIcon?: Icon; scale?: number; } export const Vertex3: React.FunctionComponent = ({ text = "", textHeight = 10, textPadding = 4, textFill = "#287EC4", textboxFill = "white", textboxStroke = "#CCCCCC", textboxStrokeWidth = 1, textFontFamily = "Verdana", annotationGutter = 2, annotations = [], cornerRadius = 3, icon = {}, subText = { text: "" }, showLabel = true, noLabelRadius = 5, expansionIcon, scale = 1 }) => { icon = { height: 50, imageChar: "?", imageFontFamily: "FontAwesome", imageCharFill: "#555555", fill: "transparent", strokeWidth: 0, ...icon }; subText = { text: "", fill: "white", textFill: "#555555", ...subText }; expansionIcon = expansionIcon ? { height: 16, shape: "circle", padding: 6, imageChar: "?", imageFontFamily: "FontAwesome", imageCharFill: "black", fill: "whitesmoke", stroke: "whitesmoke", strokeWidth: 0, ...expansionIcon } : undefined; let fullAnnotationWidth = 0; const annoOffsetY = 0; const labelWidth = React.useMemo(() => { return Utility.textSize(text, textFontFamily, textHeight, false).width; }, [text, textFontFamily, textHeight]); let labelShapeWidth = 0; if (text !== "") { labelShapeWidth = labelWidth + (textPadding * 2) + (textboxStrokeWidth * 2); } fullAnnotationWidth += labelShapeWidth + annotationGutter; const textOffsetX = fullAnnotationWidth - (labelShapeWidth / 2); const textShapeHeight = textHeight + (textPadding * 2) + (textboxStrokeWidth * 2); const annotationArr = []; annotations.forEach((anno, idx) => { const annoText = anno.imageChar; const annoShapeWidth = textShapeHeight; fullAnnotationWidth += annoShapeWidth + annotationGutter; const annoOffsetX = fullAnnotationWidth - (annoShapeWidth / 2); annotationArr.push( ); }); if (annotations.length > 0) { fullAnnotationWidth += annotationGutter * (annotations.length - 1); } const textElement = {!showLabel || text === "" ? : } ; const iconHeight = icon.height || 20; const iconStrokeWidth = icon.strokeWidth || 0; const iconOffsetX = 0; let iconOffsetY = 0; const subTextOffsetX = 0; let subTextOffsetY = textShapeHeight + (annotationGutter * 2); if (text !== "" || annotationArr.length > 0) { iconOffsetY = - (iconHeight / 2) - (iconStrokeWidth) - (textShapeHeight / 2) - (annotationGutter * 2); } else if (subText.text !== "") { subTextOffsetY = (iconHeight / 2) + iconStrokeWidth + (annotationGutter * 2); } const subtextElement = subText.text === "" ? null : ; return {expansionIcon && } {textElement} {annotationArr} {subtextElement} ; }; export const CentroidVertex3: React.FunctionComponent = function ({ id, categoryID = "", text = "", textHeight = 12, textPadding = 10, textFill = "#287EC4", textboxFill = "white", textboxStroke = "#CCCCCC", textboxStrokeWidth = 1, textFontFamily = "Verdana", annotationGutter = 2, annotations = [], cornerRadius, icon = {}, subText = {}, expansionIcon, scale = 1 }) { icon = { height: 91, padding: 40, imageCharFill: "#555555", imageFontFamily: "FontAwesome", fill: "#FFCC33", stroke: "#DFDFDF", imageChar: "?", strokeWidth: 4, yOffset: -15, ...icon }; subText = { text: "", fill: "transparent", textFill: "#555555", ...subText }; const props = { id, categoryID, text, textHeight, textPadding, textFill, textboxFill, textboxStroke, textboxStrokeWidth, textFontFamily, annotationGutter, annotations, cornerRadius, icon, subText, expansionIcon, scale }; return ; };