import plotly.graph_objects as go


FONT = {"family": "Inter, system-ui, -apple-system, sans-serif", "color": "#1f2937"}


def load_data():
    return [
        ("Central", 82),
        ("East", 86),
        ("Harbor", 88),
        ("North", 90),
        ("West", 92),
    ]


def value_table(data):
    return {
        "columns": ["Hub", "Parcels per hour"],
        "rows": [list(row) for row in data],
    }


def make_after(data) -> go.Figure:
    hubs, rates = zip(*sorted(data, key=lambda row: row[1]), strict=True)
    fig = go.Figure(
        go.Scatter(
            x=rates,
            y=hubs,
            mode="markers+text",
            marker={"size": 10, "color": "#2877a0"},
            text=rates,
            textposition="middle right",
            hovertemplate="%{y}: %{x} parcels per hour<extra></extra>",
        )
    )
    fig.update_layout(
        template="simple_white",
        font=FONT,
        title="Parcel throughput by hub",
        xaxis={"title": "Parcels per hour", "range": [80, 95], "dtick": 5},
        yaxis={"categoryorder": "array", "categoryarray": hubs},
        margin={"l": 80, "r": 24, "t": 56, "b": 64},
    )
    return fig


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