Skip to content

CDD-3550: Add responsive full and compact chart configurations - #3408

Open
dw-ukhsa wants to merge 13 commits into
mainfrom
feature/CDD-3526-chart-orientation
Open

dw-ukhsa wants to merge 13 commits into
mainfrom
feature/CDD-3526-chart-orientation

Conversation

@dw-ukhsa

@dw-ukhsa dw-ukhsa commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR adds responsive Plotly configuration to encoded chart responses so the frontend can switch between full, compact and compact_rotated chart layouts.

The response contract changes from the precious x-axis-only configuration to:

{
  "figure_config": {
    "full": {
      "data": [],
      "layout": {}
    },
    "compact": {
      "data": [],
      "layout": {}
    },
    "compact_rotated": {
      "data": [],
      "layout": {}
    }
  }
}

All three configurations are provided for every encoded chart response, including charts that are not eligible for rotation. This gives the frontend a consistent contract that can be applied without chart-specific response handling.

  • full contains full-width, unrotated config
  • compact contatins compact-width, unrotated config
  • compact_rotated contains compact-width and rotation overrides (where eligible) for rotation

Rotation Rules

Compact rotation is enabled for:

  • Single-category, non-time-series charts where every plot is a bar.
  • Dual-category, non-time-series stacked bar charts.
  • Subplot charts, including shapes and annotations (currently not supported in frontend)

Compact rotation is not enabled for:

  • Any time-series chart, including time-series bar and stacked-bar charts.
  • Line charts.
  • Charts containing a combination of bar and line plots.
  • Any other non-bar style single-category
Data Plots Compact rotation
Non-time-series Bar only Yes
Non-time-series Bar and line No
Non-time-series Line only No
Time-series Bar only No
Time-series Bar and line No
Time-series Line only No

Responsive transformations

For charts eligible for compact rotation, compact_rotated:

  • Swaps trace x and y values.
  • Changes Plotly bar orientation to h.
  • Swaps the semantic x-axis and y-axis configuration.
  • Updates hover-template x/y references.
  • Moves vertical error bars from error_y to error_x.
  • Rotates shapes and annotations, including threshold lines and labels.
  • Sets the dynamic chart height based on the number of distinct bar category positions.

Rotated chart height is calculated as:
max(400, 200 + (category count x 25))

Distinct category positions are counted across bar traces so stacked series so not incorrectly increase the height.

The original figure remains unchanged and continues to be used for static and non-JavaScript output.

Tick behaviour

The existing responsive x-axis tick behaviour is retained:

  • Full time-series layout uses up to 13 x-axis ticks.
  • Compact time-series layout uses up to 5 x-axis ticks.
  • Headline and categorical bar axes retains their one-to-one category labels.

API and serializer changes

  • Adds required data and layout objects for full, compact and compact_rotated.
  • Adds figure_config to single-category, dual-category and subplot encoded responses (ignored by frontend for now, due to be implemented in seperate work).
  • Ensures non-eligible charts still return data overrides for all modes.
  • Centralises responsive configuration generation in metrics/domain/charts/figure_config.py.

Testing

Unit coverage has been added or updated for:

  • All three-mode response contract.
  • Responsive time-series tick limits without rotation.
  • Rotation eligibility for single category and dual category charts.
  • Bar trace x/y and orientation changes.
  • Hover-template rotation.
  • Confidence interval/error-bar rotation.
  • Threshold shapes and annotations.
  • Preservation of subplot axis positioning.
  • Dynamic rotated height, including 400px minimum.
  • Consistent configuration for non-eligible and empty figures.
  • Response serializer contract validation.

Fixes #3550


Type of change

Please select the options that are relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Tech debt item (this is focused solely on addressing any relevant technical debt)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests at the right levels to prove my change is effective
  • I have added screenshots or screen grabs where appropriate
  • I have added docstrings in the correct style (google)

@dw-ukhsa
dw-ukhsa marked this pull request as ready for review October 27, 2026 14:59
@dw-ukhsa
dw-ukhsa requested a review from a team as a code owner October 27, 2026 14:59
@dw-ukhsa dw-ukhsa changed the title CDD-3526: Add responsive full and compact chart configurations CDD-3550: Add responsive full and compact chart configurations Nov 2, 2026
phill-stanley
phill-stanley previously approved these changes Nov 2, 2026
@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

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.

3 participants