Skip to content

Support secondary axes on cartesian traces #120

Open

Description

@jvdd

Need

A user wants to show two quantities with different units on one figure, for example temperature and pressure on one time axis. Plotly does this with a second y-axis (yaxis2 with overlaying: "y"). FlexViz cannot draw a second axis.

Current state

What is needed

  1. Adapter. Draw the second axis (yaxis2 with overlaying: "y" and side: "right", and maybe xaxis2). Send its viewport key (fig/y2). Give it the same zoom, reset and lock controls as the main axes.
  2. Engine to trace. _trace_update_range (flexviz/engine.py) keys update_range by anchor id, for example "y2". The traces read it by role: hist.py reads prop_key, hist2d.py reads "x" and "y", and line.py reads "x". Map anchor to role before the trace reads the range. A line on ("x", "y2") works now, because it re-aggregates on x only. A horizontal histogram on ("x", "y2") does not.
  3. Cube path. The target lookup in FlexEngine.build_cubes (flexviz/engine.py, _axis_range) reads backend_data.get(axis), but backend_data is keyed by role. A temporal zoom on x2 becomes the full data domain, and a hist2d target on y2 skips the full-data gate.
  4. Shared histogram domains. _histogram_domain_cols_by_uid has a latent anchor mismatch for secondary axes (see Architecture.md, cube section).
  5. Anchor validation. figure_axis_columns (flexviz/spec.py) assumes that axes[0] is an x anchor and axes[1] is a y anchor. axes=("y", "x") maps the columns to the wrong axes (Axis handling gaps found while reviewing linked axes #81 item 2). Reject that form in the spec.
  6. Linked axes. The DashboardSpec validator accepts only x and y in a link group. Decide if y2 can link.
  7. Public API. Add the option back only after items 1 to 5 work. A single flag, for example add_line(..., secondary_y=True), is simpler than a free anchor tuple.
  8. Tests. Engine tests for zoom on the second axis. A browser test that a zoom on y2 re-aggregates a trace that binds y2, and that a zoom on x still re-aggregates a line on ("x", "y2").

Update Architecture.md when the anchor contract changes.

Activity

  1. added
    enhancement
    on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions