import plotly.express as px


import plotly.graph_objects as go


def load_data():
    votes = px.data.election().iloc[0]
    return [(candidate, int(votes[candidate])) for candidate in ("Coderre", "Bergeron", "Joly")]


def value_table(data):
    return {"columns": ["Candidate", "Votes"], "rows": [list(row) for row in data]}


def make_before(data) -> go.Figure:
    names, votes = zip(*data, strict=True)
    fig = go.Figure(
        go.Pie(labels=names, values=votes, marker={"colors": ["#245a80", "#80547b", "#b98442"]})
    )
    fig.update_layout(template="simple_white")
    return fig


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