import plotly.graph_objects as go


def load_data():
    return [(1978, 18), (1985, 27.5)]


def value_table(data):
    return {
        "columns": ["Deadline", "Standard (miles per gallon)"],
        "rows": [list(row) for row in data],
    }


def make_after(data) -> go.Figure:
    years, values = zip(*data, strict=True)
    fig = go.Figure(
        go.Bar(
            x=years,
            y=values,
            marker_color="#3b82c4",
            text=[f"{v:g} mpg" for v in values],
            textposition="outside",
            cliponaxis=False,
            hovertemplate="%{x}: %{y:g} mpg<extra></extra>",
        )
    )
    fig.update_layout(
        template="simple_white",
        font={"family": "Inter, system-ui, -apple-system, sans-serif", "color": "#1f2937"},
        title={
            "text": "Federal fuel economy standard, 1978 and 1985",
            "x": 0,
            "xanchor": "left",
            "subtitle": {"text": "Zero baseline keeps bar lengths proportional to the 53% rise"},
        },
        xaxis_title="Deadline",
        xaxis_tickvals=list(years),
        yaxis_title="Miles per gallon",
        yaxis_range=[0, 32],
        margin={"l": 60, "r": 24, "t": 84, "b": 64},
    )
    return fig


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