Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(draw): fix create swimlane error by drawing #WIK-15860 #924

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading