Interval and "max data points" calculation in Prometheus queries

Hello, I’m working on creating per-panel annotations in my dashboard that depend on re-running prometheus queries that my graph panels run. I’m not able to get the correct value for dynamic step to use in my prometheus queries which is causing my annotations to have incorrect timestamps. From looking at the “Query options” drop-down it appears that the interval there matches the dynamic step that grafana uses when it runs prometheus queries (interval = Time range / max data points)

I already have the time range and I can determine the width of the panel, but I’m unable to determine the “max data points” value accurately enough from the width. How exactly does prometheus calculate “max data points”? I’ve tried to look at the source code but I don’t have a good enough understanding of React/Javascript to figure this out. I’m hoping somebody in this community can help me out.

Thanks,
AB