{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "# Lacrosse, tennis, volleyball and curling\n",
    "\n",
    "Seven examples from the four sports whose surfaces sdvplot draws but whose teams it does not hold yet: every lacrosse\n",
    "field and box, the men's and women's goal areas, a box rink turned and recolored, a tennis court on three surfaces, the volleyball\n",
    "courts and a curling sheet. `surface()` draws them all through sportypy, from sportyR's dimensions. None of these keys is an SDV\n",
    "team league, so there is no team to color by; sportypy's `color_updates`, `display_range` and `rotation` work as on\n",
    "any other surface. There is no data on this page: the SportsDataverse publishes none for these sports yet."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "import sdvplot"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2",
   "metadata": {},
   "source": [
    "## 1. Every lacrosse field and box\n",
    "\n",
    "Seven lacrosse surfaces: the NLL and World Lacrosse play box lacrosse in a rink with boards; the PLL, NCAA and USA\n",
    "Lacrosse fields are outdoor field lacrosse, with the men's and women's rule books marking the goal areas differently."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3",
   "metadata": {
    "sdvplot_gallery": {
     "alt": "Seven lacrosse surfaces drawn by sdvplot.surface(): the NLL and World Lacrosse boxes, and the PLL, NCAA and USA Lacrosse fields",
     "title": "Every lacrosse field and box"
    },
    "tags": [
     "gallery"
    ]
   },
   "outputs": [],
   "source": [
    "lacrosse = [\n",
    "    (\"nll\", \"NLL (box)\"),\n",
    "    (\"pll\", \"PLL\"),\n",
    "    (\"world_lacrosse\", \"World Lacrosse (box)\"),\n",
    "    (\"ncaa_mlacrosse\", \"NCAA men\"),\n",
    "    (\"ncaa_wlacrosse\", \"NCAA women\"),\n",
    "    (\"usa_mlacrosse\", \"USA Lacrosse boys\"),\n",
    "    (\"usa_wlacrosse\", \"USA Lacrosse girls\"),\n",
    "]\n",
    "fig, axes = plt.subplots(2, 4, figsize=(15, 6.5))\n",
    "for ax, (league, label) in zip(axes.flat[:-1], lacrosse, strict=True):\n",
    "    sdvplot.surface(league, ax=ax)\n",
    "    ax.set_title(f\"{label}: surface({league!r})\", fontsize=9)\n",
    "axes.flat[-1].set_axis_off()\n",
    "fig.suptitle(\"Every lacrosse surface\", x=0.01, ha=\"left\", fontweight=\"bold\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4",
   "metadata": {},
   "source": [
    "## 2. The men's and women's goal areas\n",
    "\n",
    "`display_range=\"offense\"` draws the attacking half. The NCAA men's field has a crease and a box around the goal;\n",
    "the women's has the 8-meter arc and the 12-meter fan in front of it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5",
   "metadata": {},
   "outputs": [],
   "source": [
    "fig, axes = plt.subplots(1, 2, figsize=(12, 6))\n",
    "for ax, league in zip(axes, (\"ncaa_mlacrosse\", \"ncaa_wlacrosse\"), strict=True):\n",
    "    sdvplot.surface(league, ax=ax, display_range=\"offense\")\n",
    "    ax.set_title(f\"surface({league!r}, display_range='offense')\", fontsize=10)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6",
   "metadata": {},
   "source": [
    "## 3. A box lacrosse rink, turned and recolored\n",
    "\n",
    "`rotation=90` turns the rink a quarter turn, and `color_updates` repaints any feature by its sportypy name: here the\n",
    "boards and the field. The NLL key takes no team, so a team's colors go in by hand the same way."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7",
   "metadata": {},
   "outputs": [],
   "source": [
    "fig, ax = plt.subplots(figsize=(5, 9))\n",
    "sdvplot.surface(\n",
    "    \"nll\",\n",
    "    ax=ax,\n",
    "    rotation=90,\n",
    "    color_updates={\n",
    "        \"boards\": \"#1d428a\",\n",
    "        \"defensive_zone\": \"#2e6b30\",\n",
    "        \"neutral_zone\": \"#2e6b30\",\n",
    "        \"offensive_zone\": \"#2e6b30\",\n",
    "    },\n",
    ")\n",
    "ax.set_title(\"surface('nll', rotation=90)\", fontsize=10)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8",
   "metadata": {},
   "source": [
    "## 4. Tennis on clay, grass and a hard court\n",
    "\n",
    "The six tennis keys (`atp`, `wta`, `itf`, `ita`, `usta`, `ncaa_tennis`) draw one regulation court. `color_updates`\n",
    "gives it a surface: the court's areas (`backcourt`, `deuce_court`, `ad_court`, `doubles_alley`) and the\n",
    "`court_apron` around them."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9",
   "metadata": {
    "sdvplot_gallery": {
     "alt": "Three ATP tennis courts drawn by sdvplot.surface(), recolored as clay, grass and a blue hard court",
     "title": "A tennis court on clay, grass and a hard court"
    },
    "tags": [
     "gallery"
    ]
   },
   "outputs": [],
   "source": [
    "surfaces = {\n",
    "    \"Clay\": (\"#c75b39\", \"#c75b39\"),\n",
    "    \"Grass\": (\"#5a8f3a\", \"#4c7a31\"),\n",
    "    \"Hard court\": (\"#3c638e\", \"#6c935c\"),\n",
    "}\n",
    "fig, axes = plt.subplots(1, 3, figsize=(15, 4.5))\n",
    "for ax, (label, (court, apron)) in zip(axes, surfaces.items(), strict=True):\n",
    "    areas = dict.fromkeys([\"backcourt\", \"deuce_court\", \"ad_court\", \"doubles_alley\"], court)\n",
    "    sdvplot.surface(\"atp\", ax=ax, color_updates={**areas, \"court_apron\": apron})\n",
    "    ax.set_title(label, fontsize=10)\n",
    "fig.suptitle(\"One tennis court, three surfaces\", x=0.01, ha=\"left\", fontweight=\"bold\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "10",
   "metadata": {},
   "source": [
    "## 5. Volleyball: the free zone differs\n",
    "\n",
    "FIVB, USA Volleyball and NCAA courts share the 18 x 9 m court and differ in the free zone around it: FIVB's\n",
    "reaches 6.5 m past the end lines and 5 m past the sidelines, USA Volleyball's and the NCAA's 4.5 m and 3 m."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "11",
   "metadata": {},
   "outputs": [],
   "source": [
    "fig, axes = plt.subplots(1, 3, figsize=(15, 4.5))\n",
    "for ax, league in zip(axes, (\"fivb\", \"usa_volleyball\", \"ncaa_volleyball\"), strict=True):\n",
    "    sdvplot.surface(league, ax=ax)\n",
    "    ax.set_title(f\"surface({league!r})\", fontsize=10)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12",
   "metadata": {},
   "source": [
    "## 6. Curling: the sheet and the house\n",
    "\n",
    "A curling sheet is long and narrow: turn it with `rotation=90`, and `display_range=\"house\"` zooms on one house.\n",
    "World Curling's sheet (`wcf`) and Curling Canada's (`curling_canada`) share their dimensions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13",
   "metadata": {},
   "outputs": [],
   "source": [
    "fig, (sheet, house) = plt.subplots(1, 2, figsize=(13, 6), width_ratios=[1, 2])\n",
    "sdvplot.surface(\"wcf\", ax=sheet, rotation=90)\n",
    "sheet.set_title(\"surface('wcf', rotation=90)\", fontsize=9)\n",
    "sdvplot.surface(\"wcf\", ax=house, display_range=\"house\")\n",
    "house.set_title(\"surface('wcf', display_range='house')\", fontsize=9)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14",
   "metadata": {},
   "source": [
    "## 7. A team on these keys is an error\n",
    "\n",
    "The keys of a sport without SDV team identities refuse a team rather than draw a plain surface silently, as in\n",
    "sdvplotR and sdvplot-js. A key that is a team league, such as `ncaa_softball`, takes one."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "15",
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    sdvplot.surface(\"atp\", \"Sinner\")\n",
    "except ValueError as e:  # sdvplot.InputError\n",
    "    print(type(e).__name__, e)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "sdvplot": {
   "description": "Lacrosse, tennis, volleyball and curling surfaces: every lacrosse field and box, men's and women's goal areas, tennis on three surfaces, volleyball free zones and curling sheets.",
   "label": "Lacrosse, tennis, volleyball & curling",
   "position": 60
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
