import plotly.graph_objects as go


def load_data():
    exports = {
        "Indochina": (1969, 2352, 2248),
        "Morocco": (1934, 2585, 2829),
        "Tunisia": (1243, 1894, 2832),
        "Algeria": (6646, 8217, 11610),
    }
    return [
        (territory, year, count)
        for territory, counts in exports.items()
        for year, count in zip(range(1927, 1930), counts, strict=True)
    ]


def value_table(data):
    return {"columns": ["Territory", "Year", "Car exports"], "rows": [list(row) for row in data]}


def make_before(data) -> go.Figure:
    fig = go.Figure()
    for territory in dict.fromkeys(row[0] for row in data):
        years, counts = zip(
            *((year, count) for name, year, count in data if name == territory), strict=True
        )
        fig.add_trace(
            go.Scatter3d(x=years, y=counts, z=[0] * len(years), name=territory, mode="markers")
        )
    fig.update_layout(
        template="simple_white",
        scene={"xaxis_title": "Year", "yaxis_title": "Cars", "zaxis_title": "Depth"},
    )
    return fig


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