import plotly.express as px


import plotly.graph_objects as go


def load_data():
    iris = px.data.iris()
    setosa = iris[iris["species"] == "setosa"]
    return [
        (round(float(sl), 2), round(float(sw), 2))
        for sl, sw in setosa[["sepal_length", "sepal_width"]].itertuples(index=False, name=None)
    ]


def value_table(data):
    xs = [row[0] for row in data]
    ys = [row[1] for row in data]
    return {
        "columns": ["Measurement", "Min (cm)", "Max (cm)", "Count"],
        "rows": [
            ["Sepal length", min(xs), max(xs), len(xs)],
            ["Sepal width", min(ys), max(ys), len(ys)],
        ],
    }


def make_before(data) -> go.Figure:
    xs = [row[0] for row in data]
    ys = [row[1] for row in data]
    fig = go.Figure(
        go.Scatter(
            x=xs,
            y=ys,
            mode="markers",
            marker={"size": 9, "color": "#0072B2", "opacity": 0.75},
        )
    )
    fig.update_layout(
        template="simple_white",
        xaxis_title="Sepal length (cm)",
        yaxis_title="Sepal width (cm)",
        xaxis_range=[min(xs), max(xs)],
        yaxis_range=[min(ys), max(ys)],
        margin={"l": 60, "r": 24, "t": 28, "b": 48},
    )
    return fig


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