{"spec_id":"icicle-basic","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\nicicle-basic: Basic Icicle Chart\nLibrary: plotly 6.7.0 | Python 3.13.13\nQuality: 82/100 | Created: 2026-05-13\n\"\"\"\n\nimport os\n\nimport pandas as pd\nimport plotly.graph_objects as go\n\n\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\"\nGRID = \"rgba(26,26,23,0.10)\" if THEME == \"light\" else \"rgba(240,239,232,0.10)\"\n\nBRAND = \"#009E73\"\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\", \"#954477\"]\n\n# Data - File system hierarchy\ndata = {\n    \"name\": [\n        \"root\",\n        \"Documents\",\n        \"Photos\",\n        \"Code\",\n        \"Projects\",\n        \"Archive\",\n        \"Work_Docs\",\n        \"Personal\",\n        \"Vacation\",\n        \"Family\",\n        \"Project_A\",\n        \"Project_B\",\n        \"Project_C\",\n        \"Backup_2024\",\n    ],\n    \"parent\": [\n        \"\",\n        \"root\",\n        \"root\",\n        \"root\",\n        \"root\",\n        \"root\",\n        \"Documents\",\n        \"Documents\",\n        \"Photos\",\n        \"Photos\",\n        \"Code\",\n        \"Code\",\n        \"Code\",\n        \"Archive\",\n    ],\n    \"value\": [100, 25, 20, 30, 15, 10, 12, 13, 8, 12, 10, 12, 8, 10],\n}\n\ndf = pd.DataFrame(data)\n\n\ndef get_node_level(node, df):\n    \"\"\"Calculate depth level of node in hierarchy\"\"\"\n    level = 0\n    while True:\n        parent_row = df[df[\"name\"] == node]\n        if len(parent_row) == 0 or parent_row.iloc[0][\"parent\"] == \"\":\n            return level\n        node = parent_row.iloc[0][\"parent\"]\n        level += 1\n\n\ncolors = []\nfor _, row in df.iterrows():\n    level = get_node_level(row[\"name\"], df)\n    if level == 0:\n        colors.append(BRAND)\n    elif level == 1:\n        colors.append(IMPRINT[1])\n    elif level == 2:\n        colors.append(IMPRINT[2])\n    else:\n        colors.append(IMPRINT[3])\n\n# Create icicle chart\nfig = go.Figure(\n    go.Icicle(\n        labels=df[\"name\"],\n        parents=df[\"parent\"],\n        values=df[\"value\"],\n        marker={\"colors\": colors, \"line\": {\"color\": PAGE_BG, \"width\": 2}},\n        text=df[\"name\"],\n        textposition=\"middle center\",\n        textfont={\"size\": 16, \"color\": INK},\n        hovertemplate=\"<b>%{label}</b><br>Size: %{value}<extra></extra>\",\n        marker_colorscale=None,\n    )\n)\n\nfig.update_layout(\n    title={\n        \"text\": \"icicle-basic · plotly · anyplot.ai\",\n        \"font\": {\"size\": 28, \"color\": INK},\n        \"x\": 0.5,\n        \"xanchor\": \"center\",\n    },\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    font={\"color\": INK, \"family\": \"Arial, sans-serif\"},\n    margin={\"l\": 40, \"r\": 40, \"t\": 120, \"b\": 40},\n    showlegend=False,\n)\n\n# Save\nfig.write_image(f\"plot-{THEME}.png\", width=1600, height=900, scale=3)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}