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 position of child matches #45

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 8 additions & 12 deletions src/bracket-single/connectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,22 @@ const Connectors = ({
offsetY,
});
const previousBottomPosition = (rowIndex + 1) * 2 - 1;
const previousTopMatchPosition = calculatePositionOfMatch(
previousBottomPosition - 1,
columnIndex - 1,
{
const previousTopMatchPosition =
bracketSnippet.previousTopMatch &&
calculatePositionOfMatch(previousBottomPosition - 1, columnIndex - 1, {
canvasPadding,
rowHeight,
columnWidth,
offsetY,
}
);
const previousBottomMatchPosition = calculatePositionOfMatch(
previousBottomPosition,
columnIndex - 1,
{
});
const previousBottomMatchPosition =
bracketSnippet.previousBottomMatch &&
calculatePositionOfMatch(previousBottomPosition, columnIndex - 1, {
canvasPadding,
rowHeight,
columnWidth,
offsetY,
}
);
});

return (
<Connector
Expand Down
20 changes: 12 additions & 8 deletions src/bracket-single/single-elim-bracket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,22 @@ const SingleEliminationBracket = ({

const generateColumn = matchesColumn => {
const previousMatchesColumn = matchesColumn.reduce((result, match) => {
const previousMatches = matches
.filter(m => m.nextMatchId === match.id)
.sort((a, b) => sortAlphanumerically(a.name, b.name))

if (previousMatches.length === 1) previousMatches.unshift(null);
if (previousMatches.length === 0) previousMatches.unshift(null, null);
return [
...result,
...matches
.filter(m => m.nextMatchId === match.id)
.sort((a, b) => sortAlphanumerically(a.name, b.name)),
...previousMatches,
];
}, []);

if (previousMatchesColumn.length > 0) {
if (previousMatchesColumn.length > 0 && previousMatchesColumn.every(Boolean)) {
return [...generateColumn(previousMatchesColumn), previousMatchesColumn];
}
return [previousMatchesColumn];
return [previousMatchesColumn.some(Boolean)? previousMatchesColumn : []];
};
const generate2DBracketArray = final => {
return final
Expand Down Expand Up @@ -123,7 +127,7 @@ const SingleEliminationBracket = ({
canvasPadding={canvasPadding}
width={width}
numOfRounds={columns.length}
tournamentRoundText={match.tournamentRoundText}
tournamentRoundText={match?.tournamentRoundText}
columnIndex={columnIndex}
/>
)}
Expand All @@ -143,7 +147,7 @@ const SingleEliminationBracket = ({
}}
/>
)}
<g>
{match && <g>
<MatchWrapper
x={x}
y={
Expand All @@ -164,7 +168,7 @@ const SingleEliminationBracket = ({
style={style}
matchComponent={matchComponent}
/>
</g>
</g>}
</>
);
})
Expand Down