"""
Borderless choropleth
======================

Metropolitan France alone, with no chrome around the map: no ocean panel,
no frame and no drop shadow. Leaving ``facecolor`` unset and
``border_radius=0`` places the choropleth directly on the page background,
for a clean figure to drop into a document.

Hover a department to read its value.
"""

from pathlib import Path

import pandas as pd

from mappyng import Map, ChoroplethLayer
from mappyng.data import load_france_departments

deps = load_france_departments().to_crs(2154)
# Metropolitan France only: its department codes have two characters,
# while every overseas department or collectivity has three.
deps = deps[deps["COD_GEO"].str.len() == 2]
df = pd.read_csv(Path("data") / "cardio_mortalite_dep.csv", dtype={"code_dep": str})
deps = deps.merge(df, left_on="COD_GEO", right_on="code_dep", how="left")

m = Map(deps, width=820, height="auto", border_radius=0)
m.add(ChoroplethLayer(deps, column="taux_mortalite", cmap="Reds",
                      method="Quantiles", num_classes=5, stroke_width=0.2,
                      legend={"title": "Deaths / 100,000 inhabitants",
                              "orientation": "horizontal", "decimals": 0,
                              "nodata_label": "No data"}))

m.title("Mortality from heart failure",
        subtitle="Metropolitan France, standardised rate")
m.source("Source: Sante publique France (ODISSE)")

# Hover tooltips. The gallery embeds an interactive SVG from this dict; the
# same call also yields a standalone HTML file.
TOOLTIP = {"columns": ["LIB_GEO", "taux_mortalite"],
           "aliases": {"LIB_GEO": "Department", "taux_mortalite": "Rate"}}
interactive = m.to_interactive(**TOOLTIP)
# interactive.save("choropleth_borderless.html")
