/* eslint-disable no-debugger, no-console */ 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 IVertex4Annotation extends Icon { shapeOffsetX?: number; shapeOffsetY?: number; } export interface IVertex4 extends VertexProps { textboxStrokeWidth?: number; annotations?: IVertex4Annotation[]; iconAnnotations?: IVertex4Annotation[]; annotationGutter?: number; cornerRadius?: number; subText?: any; noLabelRadius?: number; iconBorderWidth?: number; iconBorderColor?: string; iconBackgroundColor?: string; shapeOffsetX?: number; shapeOffsetY?: number; iconOffsetX?: number; iconOffsetY?: number; iconPadding?: number; iconFontSize?: number; iconFontColor?: string; iconFontFamily?: string; iconText?: string; shapeRendering?: "auto" | "optimizeSpeed" | "crispEdges" | "geometricPrecision"; } export const Vertex4: React.FunctionComponent = ({ categoryID = "", text = "", textHeight = 10, textPadding = 4, textFill = "#287EC4", textboxFill = "white", textboxStroke = "#CCCCCC", textboxStrokeWidth = 1, textFontFamily = "Verdana", annotationGutter = 2, annotations = [], iconAnnotations = [], cornerRadius = 3, icon = {}, subText = {}, showLabel = true, noLabelRadius = 5, iconBorderWidth = 1, iconBorderColor = "#333", iconBackgroundColor = "#fff", iconFontColor = "#000", iconFontSize = 20, iconFontFamily = "FontAwesome", shapeOffsetX = 0, shapeOffsetY = 0, iconOffsetX = 0, iconOffsetY = 0, iconPadding = 4, iconText = "?", shapeRendering = "auto" }) => { icon = { height: 50, imageChar: "?", imageFontFamily: "FontAwesome", imageCharFill: "#555555", fill: "transparent", strokeWidth: 0, ...icon }; subText = { text: "", fill: "white", textFill: "#555555", ...subText }; 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); } let fullAnnotationWidth = labelShapeWidth + annotationGutter; const textOffsetX = fullAnnotationWidth - (labelShapeWidth / 2); const textShapeHeight = textHeight + (annotationGutter * 2) + (textboxStrokeWidth * 2); const annoWidthArr = annotations.map((anno, i) => { return Utility.textSize(anno.imageChar, anno.imageFontFamily, anno.height, false).width; }); const annotationArr = []; let _labelAnnoOffsetX = fullAnnotationWidth; annotations.forEach((anno, i) => { const annoText = anno.imageChar; const annoTextHeight = anno.height ?? textShapeHeight; _labelAnnoOffsetX += annoWidthArr[i] + annotationGutter; const annoOffsetX = _labelAnnoOffsetX - (annoWidthArr[i] / 2); annotationArr.push( ); }); if (annotations.length > 0) { fullAnnotationWidth += annotationGutter * (annotations.length - 1); } const iconAnnotationArr = []; iconAnnotations.forEach((anno, i) => { const x = anno.shapeOffsetX; const y = anno.shapeOffsetY; iconAnnotationArr.push( ); }); const textElement = {!showLabel || text === "" ? : } ; const subTextOffsetX = 0; const subTextOffsetY = textShapeHeight + (annotationGutter * 2); const subtextElement = subText.text === "" ? null : ; return {iconAnnotationArr} {textElement} {annotationArr} {subtextElement} ; }; export const CentroidVertex4: React.FunctionComponent = function ({ id, categoryID = "", text = "", textHeight = 12, textPadding = 10, textFill = "#287EC4", textboxFill = "white", textboxStroke = "#CCCCCC", textboxStrokeWidth = 1, textFontFamily = "Verdana", annotationGutter = 2, annotations = [], iconAnnotations = [], cornerRadius, icon = {}, subText = {}, showLabel = true, noLabelRadius = 5, iconBorderWidth = 1, iconBorderColor = "#333", iconBackgroundColor = "#fff", iconFontColor = "#000", iconFontSize = 20, iconFontFamily = "FontAwesome", shapeOffsetX = 0, shapeOffsetY = 0, iconOffsetX = 0, iconOffsetY = 0, iconPadding = 4, iconText = "?", shapeRendering = "auto" }) { 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, iconAnnotations, cornerRadius, icon, subText, showLabel, noLabelRadius, iconBorderWidth, iconBorderColor, iconBackgroundColor, iconFontColor, iconFontSize, iconFontFamily, shapeOffsetX, shapeOffsetY, iconOffsetX, iconOffsetY, iconPadding, iconText, shapeRendering }; return ; };