jquery-bracket icon indicating copy to clipboard operation
jquery-bracket copied to clipboard

Render matches based on the specified number of advancing team

Open carloquilala opened this issue 8 years ago • 0 comments

So far, I've managed to extend the functionality to render group stage tournament shown in the image below.

No. of teams to advance = 4/8 image

I've added a functionality to add 'Advance' bubble which indicates teams that will be advanced to the final stage bracket. I've added an option that passes the # of teams to advance per group. In the above image, I've set this option to advance 4 teams out of 8 teams.

No. of teams to advance = 2/8 image

and with the default 1, it'll show the default bracket system which displays up to finals.

Now my question is, all are ok except to double elimination. I am having a hard time calculating the number of teams to advance :( hope you can help me with this one

This is by far my added option and function

  • groupParticipantAdvance (int)

function advanceBubbles(match) {
        var el = match.el;
        var advance = el.find('.team.advance');
        advance.append('<div class="bubble">Advanced</div>');
        return true;
}

function prepareWinners(winners, teams, isSingleElimination, opts, skipGrandFinalComeback) {
        var roundAdvanceCount = Math.log(teams.length * 2) / Math.log(2*opts.groupParticipantAdvance);
        var roundCount = Math.log(teams.length * 2) / Math.log(2);
        var matchCount = teams.length;
        var round;
        for (var r = 0; r < roundCount; r += 1) {
            round = winners.addRound(Option.empty());
            for (var m = 0; m < matchCount; m += 1) {
                var teamCb = (r === 0) ? winnerMatchSources(teams, m) : null;
                if (!(r === roundCount - 1 && isSingleElimination) && !(r === roundCount - 1 && skipGrandFinalComeback)) {
                    if (opts.groupParticipantAdvance > 1) {
                        if (r >= roundAdvanceCount)
                            round.addMatch(teamCb, Option.of(advanceBubbles));
                        else
                            round.addMatch(teamCb, Option.empty());
                    } else {
                        round.addMatch(teamCb, Option.empty());
                    }
                } else {
                    if (opts.groupParticipantAdvance > 1) {
                        if (r < roundAdvanceCount)
                            var match = round.addMatch(teamCb, Option.of(advanceBubbles));
                        else
                            var match = round.addMatch(teamCb, Option.of(winnerBubbles));
                    } else {
                        var match = round.addMatch(teamCb, Option.of(winnerBubbles));
                    }
                    
                    if (!skipGrandFinalComeback) {
                        match.setAlignCb(winnerAlignment(match, opts.skipConsolationRound));
                    }
                }
            }
            matchCount /= 2;
        }
        if (isSingleElimination) {
            winners.final().setConnectorCb(Option.empty());
            if (teams.length > 1 && !opts.skipConsolationRound) {
                var prev = winners.final().getRound().prev();
                var third_1 = prev.map(function (p) { return function () { return p.match(0).loser(); }; }).toNull();
                var fourth_1 = prev.map(function (p) { return function () { return p.match(1).loser(); }; }).toNull();
                var consol_1 = round.addMatch(function () {
                    return [
                        { source: third_1 },
                        { source: fourth_1 }
                    ];
                }, Option.of(consolationBubbles));
                consol_1.setAlignCb(function (tC) {
                    var height = (winners.el.height()) / 2;
                    consol_1.el.css('height', (height) + 'px');
                    var topShift = tC.height() / 2 + opts.matchMargin;
                    tC.css('top', (topShift) + 'px');
                });
                consol_1.setConnectorCb(Option.empty());
            }
        }
    }

carloquilala avatar Jan 30 '17 10:01 carloquilala