From c41a3440af24a0fcf5b4dd76c5046b9419ff539e Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Date: Tue, 24 Oct 2023 13:46:05 -0400 Subject: [PATCH] Fix for label location --- .../demo-app-ts/src/components/StyleGroup.tsx | 2 +- .../groups/DefaultGroupExpanded.tsx | 62 ++++++++++--------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/packages/demo-app-ts/src/components/StyleGroup.tsx b/packages/demo-app-ts/src/components/StyleGroup.tsx index 6e8e7333..80a11a0e 100644 --- a/packages/demo-app-ts/src/components/StyleGroup.tsx +++ b/packages/demo-app-ts/src/components/StyleGroup.tsx @@ -84,7 +84,7 @@ const StyleGroup: React.FunctionComponent = ({ collapsedWidth={collapsedWidth} collapsedHeight={collapsedHeight} showLabel={detailsLevel === ScaleDetailsLevel.high} - hulledOutline={true} + hulledOutline={false} {...rest} {...passedData} > diff --git a/packages/module/src/components/groups/DefaultGroupExpanded.tsx b/packages/module/src/components/groups/DefaultGroupExpanded.tsx index 84778c6a..f409abc4 100644 --- a/packages/module/src/components/groups/DefaultGroupExpanded.tsx +++ b/packages/module/src/components/groups/DefaultGroupExpanded.tsx @@ -123,30 +123,31 @@ const DefaultGroupExpanded: React.FunctionComponent = // cast to number and coerce const padding = maxPadding(element.getStyle().padding ?? 17); const hullPadding = (point: PointWithSize | PointTuple) => (point[2] || 0) + padding; - - if (hulledOutline) { - if (!droppable || !pathRef.current || !labelLocation.current) { - const children = element.getNodes().filter(c => c.isVisible()); - if (children.length === 0) { - return null; + + if (!droppable || !pathRef.current || !labelLocation.current) { + const children = element.getNodes().filter(c => c.isVisible()); + if (children.length === 0) { + return null; + } + const points: (PointWithSize | PointTuple)[] = []; + _.forEach(children, c => { + if (c.getNodeShape() === NodeShape.circle) { + const bounds = c.getBounds(); + const { width, height } = bounds; + const { x, y } = bounds.getCenter(); + const radius = Math.max(width, height) / 2; + points.push([x, y, radius] as PointWithSize); + } else { + // add all 4 corners + const { width, height, x, y } = c.getBounds(); + points.push([x, y, 0] as PointWithSize); + points.push([x + width, y, 0] as PointWithSize); + points.push([x, y + height, 0] as PointWithSize); + points.push([x + width, y + height, 0] as PointWithSize); } - const points: (PointWithSize | PointTuple)[] = []; - _.forEach(children, c => { - if (c.getNodeShape() === NodeShape.circle) { - const bounds = c.getBounds(); - const { width, height } = bounds; - const { x, y } = bounds.getCenter(); - const radius = Math.max(width, height) / 2; - points.push([x, y, radius] as PointWithSize); - } else { - // add all 4 corners - const { width, height, x, y } = c.getBounds(); - points.push([x, y, 0] as PointWithSize); - points.push([x + width, y, 0] as PointWithSize); - points.push([x, y + height, 0] as PointWithSize); - points.push([x + width, y + height, 0] as PointWithSize); - } - }); + }); + + if (hulledOutline) { const hullPoints: (PointWithSize | PointTuple)[] = points.length > 2 ? polygonHull(points as PointTuple[]) : (points as PointTuple[]); if (!hullPoints) { @@ -158,11 +159,9 @@ const DefaultGroupExpanded: React.FunctionComponent = // Compute the location of the group label. labelLocation.current = computeLabelLocation(hullPoints as PointWithSize[]); - } - } else { - if (!droppable || !boxRef.current) { - // change the box only when not dragging + } else { boxRef.current = nodeElement.getBounds(); + labelLocation.current = [boxRef.current.x + boxRef.current.width / 2, boxRef.current.y + boxRef.current.height, 0]; } } @@ -189,15 +188,18 @@ const DefaultGroupExpanded: React.FunctionComponent = - {hulledOutline && } - {!hulledOutline && } + {hulledOutline ? ( + + ) : ( + + )} {showLabel && (label || element.getLabel()) && (