Skip to content

Commit

Permalink
fix(draw): fix create swimlane error by drawing #WIK-15860 (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
huanhuanwa authored Jun 27, 2024
1 parent 4bd014d commit 9c1e653
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-spies-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@plait/draw': patch
---

fix create swimlane error by drawing
16 changes: 11 additions & 5 deletions packages/draw/src/utils/swimlane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ export const getDefaultSwimlanePoints = (pointer: SwimlaneDrawSymbols, centerPoi
export const createDefaultSwimlane = (shape: SwimlaneDrawSymbols, points: [Point, Point]) => {
const header = isSwimlaneWithHeader(shape);
const dataShape = adjustSwimlaneShape(shape);
const rows = createDefaultRowsOrColumns(dataShape, 'row', header);
const columns = createDefaultRowsOrColumns(dataShape, 'column', header);
const width = points[1][0] - points[0][0];
const height = points[1][1] - points[0][1];
const rows = createDefaultRowsOrColumns(dataShape, 'row', header, height);
const columns = createDefaultRowsOrColumns(dataShape, 'column', header, width);
const swimlane = {
id: idCreator(),
type: 'swimlane',
Expand All @@ -62,7 +64,7 @@ export const createDefaultSwimlane = (shape: SwimlaneDrawSymbols, points: [Point
return swimlane;
};

export const createDefaultRowsOrColumns = (shape: SwimlaneSymbols, type: 'row' | 'column', header: boolean) => {
export const createDefaultRowsOrColumns = (shape: SwimlaneSymbols, type: 'row' | 'column', header: boolean, size: number) => {
const createItems = (count: number) => new Array(count).fill('').map(() => ({ id: idCreator() }));
let data = createItems(3);
if (
Expand All @@ -71,11 +73,15 @@ export const createDefaultRowsOrColumns = (shape: SwimlaneSymbols, type: 'row' |
) {
data = header ? data : createItems(2);
const dimension = type === 'row' ? 'height' : 'width';
let defaultSize = SWIMLANE_HEADER_SIZE;
if (size < SWIMLANE_HEADER_SIZE * data.length) {
defaultSize = Math.min((size / data.length / SWIMLANE_HEADER_SIZE) * SWIMLANE_HEADER_SIZE, SWIMLANE_HEADER_SIZE);
}
data = data.map((item, index) => {
if (index === 0 || (index === 1 && header)) {
return {
...item,
[dimension]: SWIMLANE_HEADER_SIZE
[dimension]: defaultSize
};
}
return item;
Expand All @@ -101,7 +107,7 @@ export const createDefaultCells = (
if (index < 3) {
const rowId = shape === SwimlaneSymbols.swimlaneVertical ? rows[startIndex].id : rows[index].id;
const columnId = shape === SwimlaneSymbols.swimlaneVertical ? columns[index].id : columns[startIndex].id;
return createCell(rowId, columnId, header? 'Lane': 'New Swimlane');
return createCell(rowId, columnId, header ? 'Lane' : 'New Swimlane');
}
const rowId = shape === SwimlaneSymbols.swimlaneVertical ? rows[startIndex + 1].id : rows[index - 3].id;
const columnId = shape === SwimlaneSymbols.swimlaneVertical ? columns[index - 3].id : columns[startIndex + 1].id;
Expand Down

0 comments on commit 9c1e653

Please sign in to comment.