import plotly.graph_objects as go


def load_data():
    return [
        (1, 82),
        (2, 95),
        (3, 108),
        (4, 116),
        (5, 104),
        (6, 97),
    ]


def value_table(data):
    return {
        "columns": ["Week", "Households in emergency shelter"],
        "rows": [list(row) for row in data],
    }


def _shelter_use_chart(data, font_family: str, mark_color: str) -> go.Figure:
    weeks, households = zip(*data, strict=True)
    fig = go.Figure(go.Bar(x=weeks, y=households, marker_color=mark_color))
    fig.update_layout(
        template="simple_white",
        font={"family": font_family, "color": "#1f2937"},
        title={"text": "Emergency shelter use after the flood", "x": 0.08},
        xaxis={"title": "Week after the flood", "tickmode": "array", "tickvals": list(weeks)},
        yaxis={"title": "Households in shelter", "range": [0, 130]},
        margin={"l": 72, "r": 28, "t": 72, "b": 62},
    )
    return fig


def make_before(data) -> go.Figure:
    return _shelter_use_chart(data, "Comic Sans MS, cursive", "#e631a3")


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