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_before(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},
            )
        )
    fig.update_layout(
        width=620,
        height=430,
        template="simple_white",
        title="Scatter method",
        xaxis_title="Petal length (cm)",
        yaxis_title="Petal width (cm)",
        plot_bgcolor="#f0c9a7",
        paper_bgcolor="#ffe6c9",
        legend={"orientation": "h", "y": 1.02, "yanchor": "bottom"},
        margin={"l": 52, "r": 16, "t": 82, "b": 58},
        annotations=[
            {
                "text": "150 projected marker glyphs",
                "xref": "paper",
                "yref": "paper",
                "x": 0.57,
                "y": 0.68,
                "showarrow": False,
                "bgcolor": "#ffffff",
                "bordercolor": "#663d25",
                "borderwidth": 3,
                "borderpad": 12,
            },
        ],
    )
    fig.update_xaxes(showgrid=True, gridwidth=2, gridcolor="#a46e53")
    fig.update_yaxes(showgrid=True, gridwidth=2, gridcolor="#a46e53")
    return fig


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