Skip to content

Commit

Permalink
fix: Prevent child shapes whose parents aren't align box shapes from …
Browse files Browse the repository at this point in the history
…attending to a align box shape

- Child shapes belonging to tree root shapes other than group shapes should be exluded.
  - => Only align box shapes can be parents when a shape can attend to a align box shape.
  • Loading branch information
miyanokomiya committed May 3, 2024
1 parent 0f058b0 commit 9652433
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
14 changes: 11 additions & 3 deletions src/composables/alignHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,23 @@ describe("canAttendToAlignBox", () => {
id: "child1",
parentId: "unknown",
});
const align = createShape(getCommonStruct, "align_box", {
id: "align",
});
const align_child = createShape(getCommonStruct, "rectangle", {
id: "align_child",
parentId: align.id,
});
const shapeComposite = newShapeComposite({
shapes: [rect0, line0, label0, group0, child0, child1],
shapes: [rect0, line0, label0, group0, child0, child1, align, align_child],
getStruct: getCommonStruct,
});
expect(canAttendToAlignBox(shapeComposite, rect0)).toBe(true);
expect(canAttendToAlignBox(shapeComposite, line0)).toBe(false);
expect(canAttendToAlignBox(shapeComposite, label0)).toBe(false);
expect(canAttendToAlignBox(shapeComposite, group0)).toBe(true);
expect(canAttendToAlignBox(shapeComposite, child0)).toBe(false);
expect(canAttendToAlignBox(shapeComposite, child1)).toBe(true);
expect(canAttendToAlignBox(shapeComposite, child0), "child of group shape").toBe(false);
expect(canAttendToAlignBox(shapeComposite, child1), "child of missing shape").toBe(true);
expect(canAttendToAlignBox(shapeComposite, align_child), "child of align box shape").toBe(true);
});
});
12 changes: 6 additions & 6 deletions src/composables/alignHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { renderArrowUnit, renderValueLabel } from "../utils/renderer";
import { COLORS } from "../utils/color";
import { getPaddingRect } from "../utils/boxPadding";
import { isLineShape } from "../shapes/line";
import { isGroupShape } from "../shapes/group";
import { isLineLabelShape } from "../utils/lineLabel";

export type AlignHitResult = {
Expand Down Expand Up @@ -883,11 +882,12 @@ export function getModifiedAlignRootIds(
export function canAttendToAlignBox(shapeComposite: ShapeComposite, shape: Shape): boolean {
if (isLineShape(shape)) return false;
if (isLineLabelShape(shapeComposite, shape)) return false;
return (
!shape.parentId ||
!shapeComposite.shapeMap[shape.parentId] ||
!isGroupShape(shapeComposite.shapeMap[shape.parentId])
);
if (!shape.parentId) return true;

const parent = shapeComposite.shapeMap[shape.parentId];
if (!parent) return true;

return isAlignBoxShape(parent);
}

export function generateAlignTemplate(
Expand Down

0 comments on commit 9652433

Please sign in to comment.