{"spec_id":"chessboard-basic","library":"altair","language":"python","code":"\"\"\" anyplot.ai\nchessboard-basic: Chess Board Grid Visualization\nLibrary: altair 6.1.0 | Python 3.13.13\nQuality: 95/100 | Updated: 2026-05-17\n\"\"\"\n\nimport os\nimport sys\n\n\n# Change to script directory before importing to allow proper imports\nscript_dir = os.path.dirname(os.path.abspath(__file__))\nos.chdir(script_dir)\n\n# Remove current directory from import path temporarily\nsaved_path = sys.path[:]\nsys.path = [p for p in sys.path if p not in (\"\", \".\", script_dir)]\n\ntry:\n    import pandas as pd\n    from altair import Axis, Chart, Color, Scale, Title, X, Y\nfinally:\n    sys.path = saved_path\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nELEVATED_BG = \"#FFFDF6\" if THEME == \"light\" else \"#242420\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\n\n# Data - Create 8x8 chess board\ncolumns = list(\"abcdefgh\")\nrows = list(range(1, 9))\n\n# Generate all 64 squares with color assignments\n# Light squares at h1 and a8 corners (standard chess convention)\ndata = []\nfor col_idx, col in enumerate(columns):\n    for row in rows:\n        # Chess coloring: (col_idx + row) even = dark, odd = light\n        is_light = (col_idx + row) % 2 == 1\n        data.append({\"column\": col, \"row\": row, \"color\": \"light\" if is_light else \"dark\", \"x\": col_idx, \"y\": row - 1})\n\ndf = pd.DataFrame(data)\n\n# Create chart with rect marks for squares\n# Chess square colors work on both light and dark backgrounds\nchart = (\n    Chart(df)\n    .mark_rect(stroke=INK_SOFT, strokeWidth=2)\n    .encode(\n        x=X(\n            \"column:O\",\n            axis=Axis(\n                title=None, labelFontSize=24, labelAngle=0, orient=\"bottom\", labelPadding=10, labelColor=INK_SOFT\n            ),\n            sort=columns,\n        ),\n        y=Y(\n            \"row:O\",\n            axis=Axis(title=None, labelFontSize=24, labelPadding=10, labelColor=INK_SOFT),\n            sort=list(range(8, 0, -1)),  # 8 at top, 1 at bottom\n        ),\n        color=Color(\n            \"color:N\",\n            scale=Scale(\n                domain=[\"light\", \"dark\"],\n                range=[\"#F5DEB3\", \"#A0704F\"],  # Wheat / Medium brown (visible on both themes)\n            ),\n            legend=None,\n        ),\n    )\n    .properties(\n        width=900,\n        height=900,\n        background=PAGE_BG,\n        title=Title(\"chessboard-basic · altair · anyplot.ai\", fontSize=32, anchor=\"middle\", offset=20, color=INK),\n    )\n    .configure_view(strokeWidth=2, stroke=INK_SOFT, fill=PAGE_BG)\n    .configure_axis(domainColor=INK_SOFT, tickColor=INK_SOFT, gridColor=INK_SOFT, gridOpacity=0.0)\n)\n\n# Save outputs\nchart.save(f\"plot-{THEME}.png\", scale_factor=3.0)\nchart.save(f\"plot-{THEME}.html\")\n"}