Skip to the content

Taisen Brackets対戦

Knockout brackets as SVG, from a list of ties.

Taisen (対戦, たいせん) is Japanese for a matchup: two sides facing each other. About the name

Contents

Reference · Where every tie sits

DrawOptionstype

Everything a drawing can be told: the layout, look, size, theme, background, language, marks, flags, trophy, links and titles.

Import it

import type { DrawOptions } from "@johnmorrisdotca/taisen-brackets/layout";

Also exported from: @johnmorrisdotca/taisen-brackets

Definition

interface DrawOptions extends LayoutOptions {
    layout?: LayoutName;
    headers?: boolean;
    at?: boolean;
    standings?: "points" | "record";
    qualify?: number;
    judo?: boolean;
    style?: boolean;
    styleScope?: string;
    size?: SizeName | {
        width: number;
        height?: number | null;
    };
    orientation?: "auto" | "horizontal" | "vertical";
    detail?: Detail;
    theme?: ThemeName;
    background?: boolean | BackgroundPresetName | BackgroundOptions | BackgroundImageOptions;
    vs?: boolean;
    codes?: boolean;
    title?: string;
    subtitle?: string;
    roundNames?: readonly string[] | {
        rounds: readonly {
            name: string;
        }[];
    };
    roundLabels?: boolean;
    scores?: boolean;
    seeds?: boolean;
    markShape?: "round" | "square" | "none";
    champion?: boolean;
    trophy?: string;
    emblems?: EmblemRenderer;
    emblemStyle?: EmblemStyle;
    emblemTint?: string;
    flags?: FlagRenderer;
    flagHref?: (code: string) => string | null | undefined;
    tieClass?: (tie: Tie) => string | null | undefined;
    look?: Look;
    href?: (tie: Tie, side?: 0 | 1) => string | null | undefined;
    highlightPath?: SideId;
    thirdPlace?: "below" | "hide";
    winnerHighlight?: boolean;
    locale?: string | Locale;
    words?: Partial<Words>;
    teamName?: (team: Team, locale: Locale) => string | undefined;
    id?: string;
    className?: string;
}

Members

NameTypeDescription
layout (optional)LayoutName | undefined

tree (the default): the halves meeting at the final. rows: each team a row, its name on the left and its mark on the right, a slot for the result toward the centre. shields: marks in shields with "vs", the matchups on both sides of the trophy. update: a compact score-update card. columns: tall slots that grow toward the centre, the conferences in two colours, "VS" (or "AT") on a tag, big seed numbers. playin: the play-in games with their winners and losers going on. series: a tall card, one line a series ("BOS 4-0 MIA"), the first half above and the second below. groups: the group-stage tables. picture: the postseason picture: the two halves mirrored toward the final, each club a logo tile with its seed, each series' result beside its pair ("CLE wins 3-2"), the round's name and its length ("Best of 5") under its column, the champion big in the middle.

headers (optional)boolean | undefined

Big title tiles (the halves' groups: West and East, AFC and NFC) over each half, in any layout: each half's group name in the colour of that half. Default false.

at (optional)boolean | undefined

In the columns layout, write "AT" (the word at of the language) in place of "VS" between the two sides of a tie: the first side is the visitor and the second the home side (Matchup.home says otherwise). Default false.

standings (optional)"points" | "record" | undefined

In the groups layout, the columns of a group's table: points (played, won, drawn, lost, goal difference, points) or record (won and lost, softball's). Default points.

qualify (optional)number | undefined

In the groups layout, how many teams of each group go through: their rows are marked. Default 0, none.

judo (optional)boolean | undefined

For bracketStyle: include the judo rules (the white and blue side bars, the shido cards). drawBracket adds them by itself when a tie has judo scores.

style (optional)boolean | undefined

Write the <style> into the drawing. Default true; false leaves it out, for a second drawing of a page that shares the first's (styleScope, bracketStyle).

styleScope (optional)string | undefined

A class that carries this drawing's rules in place of its own: two drawings with the same styleScope take their colours from one <style>, and the second can leave it out (style: false). A word of letters, digits, - and _.

size (optional)SizeName | { width: number; height?: number | null; } | undefined

wide 1200 by 675, square 1080 by 1080, card 1080 by 1350 (a tall post), phone 390 wide and as tall as it needs; or a size of your own. Default wide.

orientation (optional)"auto" | "horizontal" | "vertical" | undefined

horizontal: the rounds are columns. vertical: the rounds are rows, for a tall page. Default horizontal; the phone's is vertical.

detail (optional)Detail | undefined
theme (optional)ThemeName | undefined

auto follows the page's light or dark; poster is dark with gold lines; none writes no style, for your own CSS. Default auto.

background (optional)boolean | "midnight" | "crimson" | "royal" | "emerald" | "pitch" | "ice" | "hardwood" | "infield" | "turf" | "ball-panels" | "swirl" | "waves" | "glow" | "floodlights" | "confetti" | "carbon" | "aurora" | "sunburst" | "chevrons" | "halftone" | "argyle" | "contour" | "stardust" | "mesh" | "spotlight" | BackgroundOptions | BackgroundImageOptions | undefined

The background. true (the default) is the look's plain colour and false a transparent drawing. A preset's name ("midnight", "ice", see BACKGROUND_PRESETS) draws that poster background in the look's light or dark variant (auto draws both and shows the one that fits the page), and the text, lines, boxes and marks take the colours that read over it. An object tunes a preset ({ preset, colors, angle, intensity, seed }) or draws your own picture ({ image, fit, dim }).

vs (optional)boolean | undefined

In the road look, write a small vs between the two marks of a box of marks alone. Default false.

codes (optional)boolean | undefined

In the road look, write each team's three-letter code under its mark in a box of marks alone. Default false for a bracket (a chart's codes is on by default).

title (optional)string | undefined
subtitle (optional)string | undefined
roundNames (optional)readonly string[] | { rounds: readonly { name: string; }[]; } | undefined

Names of the rounds, first round first (or just the last ones). Default: Final, Semi-finals, Quarter-finals, Round of 16…

roundLabels (optional)boolean | undefined

Show the round names over the columns. Default true; false in the flag-only look.

scores (optional)boolean | undefined

Show the scores. Default true.

seeds (optional)boolean | undefined

Show seeds: the number before the name in the classic look, and in the road look a small tag (C1, WC2: Matchup.seeds, else Team.tag, else Team.seed) beside each mark. Default false.

markShape (optional)"round" | "none" | "square" | undefined

round (the default), square, or none (names only).

champion (optional)boolean | undefined

Show the champion in the centre once the final is played. Default true.

trophy (optional)string | undefined

A trophy for the centre, drawn above the champion: inline SVG, an image address, or (with emblems) an emblem id such as "trophy:hockey-cup". An emblem id with no emblems renderer draws nothing and takes no room.

emblems (optional)EmblemRenderer | undefined

Draws the emblem a trophy id names: any function from an id and a request to an SVG string, such as renderEmblem from @johnmorrisdotca/dougu-sports/emblems. Called once per champion, with the size the trophy has in the drawing. Its SVG is cleaned like any inline SVG; a renderer that throws, or returns something that is not an <svg>, draws no trophy.

emblemStyle (optional)EmblemStyle | undefined

The style an emblem is drawn in: metal (the default), line or color.

emblemTint (optional)string | undefined

A colour for the emblem's main part (a hex colour or rgb()), passed to the renderer as tint.

flags (optional)FlagRenderer | undefined

Draws the flag a team's flag code names: a synchronous function from a code and { shape, size, theme } to an SVG string, such as one made from @johnmorrisdotca/hata. With none, or when it returns nothing for a code, the team's mark or its initials are drawn.

flagHref (optional)((code: string) => string | null | undefined) | undefined

The address of the flag a team's flag code names, for a flag that is a picture to load (a file on your own server) and not SVG to inline, which can be 80 kB for one flag. Tried where flags gives none; the address must be http(s), relative or data:image/…, and is written once as a symbol however many times the flag appears.

tieClass (optional)((tie: Tie) => string | null | undefined) | undefined

A class for each tie's group, from the tie: (tie) => tie.sides.some(inDivision) ? "mine" : "other". A word of letters, digits, - and _ is added to the group's classes (anything else is left out), so that a page's own style can highlight or dim ties: .mine .tb-box { stroke: … }. undefined or an empty text adds none.

look (optional)Look | undefined

classic (the default) or road: the look of the road-to-the-final chart, with large round marks, big bold scores, the loser quiet, the rounds named on pills and a dotted path. Every other option works in both.

href (optional)((tie: Tie, side?: 0 | 1) => string | null | undefined) | undefined

A link for each tie's box, from the tie and, for a link on one team's row, its side (0 or 1). Called with the tie alone first: an address makes the whole box a link; when that gives none, each side is asked, and a row with an address is a link of its own. Each is a real <a href> in the SVG with an accessible name; an address that is not http(s), relative or a # fragment is refused. undefined is no link.

highlightPath (optional)SideId | undefined

The id of a team whose path to the final is drawn as a dotted line in the look's highlight, the rest quieter.

thirdPlace (optional)"below" | "hide" | undefined

Where the third-place match goes: below the final (the default) or hide.

winnerHighlight (optional)boolean | undefined

Highlight the side that went through. Default true.

locale (optional)string | Locale | undefined

The language: en (the default), fr, ja, es, de, or a Locale you made with defineLocale. Sets the words, the round names, the number and date formats and the lang of the drawing.

words (optional)Partial<Words> | undefined

Replace any of the language's words.

teamName (optional)((team: Team, locale: Locale) => string | undefined) | undefined

The name to draw for a team in this language: undefined keeps Team.names[locale] or Team.name. countryName(team.region, locale) makes a country's name from Intl, with no list of your own.

id (optional)string | undefined

Prefix for the drawing's ids. Default: a hash of the bracket and the options. Only letters, digits, _ and - are kept (any other character becomes -), and an id that does not start with a letter gets the drawing's own prefix in front.

className (optional)string | undefined

Extra class names for the root <svg>.

shape (optional)"halves" | "ltr" | "auto" | undefined

halves (the default when two ties feed the final) draws two halves meeting at the final; ltr one tree left to right.

groupOrder (optional)readonly string[] | undefined

The order of the halves' groups, first on the left: ["West", "East"]. Left out, a name with "west" goes left and one with "east" right.

Examples

import { drawBracket, type DrawOptions } from "@johnmorrisdotca/taisen-brackets";

const options: DrawOptions = { look: "road", theme: "dark", size: "card", title: "Aurora Cup", locale: "ja" };
console.log(drawBracket([{ sides: ["Aurora", "Harbour"], score: [2, 1] }, { sides: ["Cascade", "Delta"], score: [0, 1] }, { sides: ["Aurora", "Delta"], score: [3, 1] }], options).startsWith("<svg"));
true

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/taisen-brackets 0.20.0.