diff --git a/web/src/features/maps/MapList.tsx b/web/src/features/maps/MapList.tsx index e350588..50d2cc5 100644 --- a/web/src/features/maps/MapList.tsx +++ b/web/src/features/maps/MapList.tsx @@ -391,9 +391,9 @@ function MapStats({ if (!hasTiers && newest.length === 0 && playedThisWeek.length === 0) return null; return ( - + {hasTiers && ( -
+
+

{href ? ( diff --git a/web/src/ui/TierSpread.tsx b/web/src/ui/TierSpread.tsx index 79b80f6..a63c783 100644 --- a/web/src/ui/TierSpread.tsx +++ b/web/src/ui/TierSpread.tsx @@ -1,87 +1,284 @@ -// Map difficulty filters with matching controls for all tiers and individual tiers. +// How many maps hold each tier: a donut split by tier, each slice in its tier's color, beside each tier's count and +// share. Every slice and row links to the maps of that tier; the chosen tier stays bright and the others dim. +// Maps without a tier fill the donut's end in a neutral color. On a phone, where the donut and its list stood +// nearly a screen tall, it's a bar split by tier and the tiers as a grid of small tiles instead. +import type { CSSProperties } from "react"; import { classNames } from "./classNames"; import { Link } from "./Link"; -import { TierBadge } from "./TierBadge"; +import { TierBadge, tierColor } from "./TierBadge"; +/** Each tier's share of all maps, so the shares (with "No tier") add up to the whole list. */ +const percent = new Intl.NumberFormat("en", { + style: "percent", + maximumFractionDigits: 0, +}); const number = new Intl.NumberFormat("en"); +/** The ring's radius and width, in the SVG's 100-unit box. */ +const RADIUS = 40; +const WIDTH = 16; +/** Space between slices, in hundredths of the ring. */ +const GAP = 0.6; + +/** "All tiers", in the look of the page's filter menus and tier tiles: bordered, raised when it's the choice. */ +const allTiersClasses = (chosen: boolean) => + classNames( + "flex h-7 w-full items-center justify-between gap-2 rounded-sm border px-2 text-sm font-medium transition-colors duration-(--duration-fast)", + chosen + ? "bg-surface-raised border-border-strong text-text" + : "border-border text-text-muted hover:text-accent", + ); + +const rowClasses = + "col-span-3 grid grid-cols-subgrid items-center rounded-sm px-2 py-0.5 transition-[opacity,background-color] duration-(--duration-base)"; + +/** A quiet highlight keeps the tier colors in the badges and chart. */ +const chosenTier = "bg-text/8"; + export function TierSpread({ byTier, untiered, selected, tierHref, }: { - /** Map counts in tier order, easiest first. */ + /** Maps per tier, tier 1 first; its length is the tier count. */ byTier: number[]; - /** Maps which have no tier assigned. */ untiered: number; - /** The selected tier, if the map list is filtered. */ + /** The tier the list is filtered to, if any. */ selected?: number; - /** Where a tier tile should link. Null returns to the complete list. */ + /** Where a tier leads; null for the whole list. */ tierHref: (tier: number | null) => string; }) { const total = byTier.reduce((sum, count) => sum + count, untiered); if (total === 0) return null; const tierCount = byTier.length; + const dimmed = (tier: number) => selected != null && selected !== tier; + + // Each slice is a dashed stroke around the ring: as long as its share, starting where the last one ended. + // Strokes rather than wedge paths, so a slice is one circle and grows its width on hover. + const slices = byTier.map((count, index) => ({ + tier: index + 1, + count, + start: + (byTier.slice(0, index).reduce((sum, c) => sum + c, 0) / total) * 100, + length: (count / total) * 100, + })); + const tieredShare = (byTier.reduce((sum, c) => sum + c, 0) / total) * 100; + const chosen = selected != null ? byTier[selected - 1] : undefined; + const half = Math.ceil(tierCount / 2); + // The first column holds the lower half; the second the rest and "No tier" after them. + const rows = Math.max(half, tierCount - half + (untiered > 0 ? 1 : 0)); + const tierRow = ({ tier, count }: (typeof slices)[number]) => ( +
  • + + + {number.format(count)} + + {percent.format(count / total)} + + +
  • + ); + return ( -
    -
    -

    Difficulty

    - +
    + {/* The donut's shares laid end to end. */} +
    - All tiers - - {number.format(total)} - - -
    -
      - {byTier.map((count, index) => { - const tier = index + 1; - const active = tier === selected; - return ( -
    • + {slices.map( + ({ tier, count }) => + count > 0 && ( + + ), + )} + {untiered > 0 && } +
    +
    + + All tiers + + {number.format(total)} maps + + + {untiered > 0 && ( + + {number.format(untiered)} without a tier + + )} +
    +
      + {slices.map(({ tier, count }) => ( +
    • - - + + {number.format(count)}
    • - ); - })} -
    - {untiered > 0 && ( -

    - {number.format(untiered)} without a tier -

    - )} -
    + ))} + +

    +
    + + {untiered > 0 && ( + + )} + {slices.map( + ({ tier, count, start, length }) => + count > 0 && ( + + {`Tier ${tier}: ${number.format(count)} maps`} + + + ), + )} + {/* Counter-rotated, so the middle reads upright inside the turned ring. */} + + + {selected != null ? `T${selected}` : "All"} + + {chosen != null && ( + + {number.format(chosen)} maps + + )} + + + + {/* "All tiers", always there to go back to, centered over the two columns it sums; the tiers split evenly + below it, low tiers first, and "No tier" ends the second column. */} +
    + + All tiers + + {number.format(total)} maps + + +
      + {slices.slice(0, half).map(tierRow)} + {slices.slice(half).map(tierRow)} + {untiered > 0 && ( +
    • + No tier + + {number.format(untiered)} + + + {percent.format(untiered / total)} + +
    • + )} +
    +
    +
    + ); }