Skip to content

fix(adapters): keep log axis viewports in data units - #113

Merged
jvdd merged 4 commits into
mainfrom
fix/log-axis-viewport
Sep 28, 2026
Merged

jvdd merged 4 commits into
mainfrom
fix/log-axis-viewport

Conversation

@jvdd

@jvdd jvdd commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #74. Does step 1 of #98.

Change

  • Plotly holds a log axis range in log10 units. Client state (state.viewport, client_state.axis_lock_ranges) now always holds data units, as the server and the selections expect.
  • Two helpers in plotly/render.js, plotlyRangeToData and plotlyRangeFromData, convert where Plotly ranges meet client state:
    • read: the relayout handler, the axis lock capture, and the selection band fill (second commit);
    • write: syncLayoutViewport and fvApplyAxisLocks.
  • The declared axis type decides (isLogAxis): the axis type, else the type in the layout template, as in Plotly. The first render writes the layout before Plotly draws the div, so both directions use the same source.
  • The exponent is clamped to the float range, so a far zoom-out never sends Infinity (JSON null, HTTP 422) or 0.
  • link_axes still rejects log axes. The message now says that log axes are not linkable yet, and the comment gives the reasons: a linear member of a group can zoom to a range at or below 0, and a group of log axes only is not designed yet.
  • Architecture.md describes the units and the conversion.

Impact

  • A zoom or pan on a log axis now re-aggregates the visible range. Before, line, histogram and histogram2d traces aggregated with log10 values as data bounds, so the zoomed figure showed the wrong data. This also holds for a log axis declared through update_layout(template=...).
  • A lock on a log axis stores and restores data units.
  • Second commit: a one-axis selection band on a figure with a log axis (for example an x brush on a histogram with a log count axis) now spans the whole axis. Before, it was placed in log10 units and fell outside the plot.
  • A share URL made before this fix with a zoomed log axis stored log10 values. They now read as data units. Those URLs already aggregated the wrong range.

Not in this PR

Tests

  • New TestLogAxisBrowser: a real mouse drag zoom (with the log type on the axis and in the layout template), a saved viewport on open, a far zoom-out, an axis lock with double-click and reset, and a selection band on a log count axis. Each fails on main, except the far zoom-out: main sends the log10 bounds, which are finite, so that test guards the clamp of this PR. The template case also fails without its commit.
  • On this branch merged with main: pytest tests: 2289 passed, 1 skipped. pytest -m browser tests: 323 passed, 12 skipped.

@codspeed

codspeed Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing fix/log-axis-viewport (c422efd) with main (ea7939b)

Open in CodSpeed

@jvdd
jvdd force-pushed the fix/log-axis-viewport branch from 6abd79c to 22adf68 Compare September 27, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zooming a log axis aggregates with log10 values as data bounds

1 participant