import plotly.graph_objects as go


def load_data():
    return [
        ("Car", 42),
        ("Bus", 31),
        ("Walking", 26),
        ("Bicycle", 19),
        ("Train", 14),
    ]


def value_table(data):
    return {"columns": ["Commute mode", "Respondents (%)"], "rows": [list(row) for row in data]}


def make_before(data) -> go.Figure:
    modes, percentages = zip(*data, strict=True)
    fig = go.Figure(
        go.Pie(
            labels=modes,
            values=percentages,
            texttemplate="%{label}<br>%{value}%",
            textposition="outside",
            hovertemplate="%{label}: %{value}%<extra></extra>",
            marker_colors=["#356890", "#5583a5", "#76a0ba", "#97b7c9", "#bfd3df"],
        )
    )
    fig.update_layout(
        template="simple_white",
        font={"family": "Inter, system-ui, -apple-system, sans-serif", "color": "#1f2937"},
        title="Share of commuters by mode",
        showlegend=False,
        margin={"l": 48, "r": 48, "t": 56, "b": 40},
    )
    return fig


if __name__ == "__main__":
    print(make_before(load_data()).to_json())
