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_after(data) -> go.Figure:
    names, votes = zip(*sorted(data, key=lambda row: row[1]), strict=True)
    fig = go.Figure(go.Bar(x=votes, y=names, orientation="h", text=votes, textposition="outside"))
    fig.update_layout(template="simple_white", xaxis_title="Votes", xaxis_range=[0, 3500])
    fig.update_layout(
        font={"family": "Inter, system-ui, -apple-system, sans-serif", "color": "#1f2937"},
        colorway=["#3b82c4", "#d97706", "#14967f", "#8b5cf6", "#dc4c3e", "#78716c"],
    )
    return fig


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