import plotly.express as px


import plotly.graph_objects as go


def load_data() -> list[tuple[str, float, float]]:
    iris = px.data.iris()
    return list(zip(iris["species"], iris["petal_length"], iris["petal_width"], strict=True))


def value_table(data: list[tuple[str, float, float]]) -> dict:
    return {
        "columns": ["Species", "Petal length (cm)", "Petal width (cm)"],
        "rows": [list(row) for row in data],
    }


def make_after(data: list[tuple[str, float, float]]) -> go.Figure:
    fig = go.Figure()
    for species, symbol in (
        ("setosa", "circle"),
        ("versicolor", "square"),
        ("virginica", "diamond"),
    ):
        x, y = zip(
            *((length, width) for name, length, width in data if name == species), strict=True
        )
        fig.add_trace(
            go.Scatter(
                x=x,
                y=y,
                name=species,
                mode="markers",
                marker={"color": "#245a80", "symbol": symbol, "size": 8, "opacity": 0.6},
            )
        )
    fig.update_layout(
        width=620,
        height=430,
        template="simple_white",
        title="Iris petals by species",
        xaxis_title="Petal length (cm)",
        yaxis_title="Petal width (cm)",
        legend={"orientation": "h", "y": 1.02, "yanchor": "bottom"},
        margin={"l": 52, "r": 16, "t": 82, "b": 58},
    )
    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())
