Skip to content

feat: horizontal canvas bar charts by placing the measure on x - #9911

Open
nishantmonu51 wants to merge 3 commits into
mainfrom
nishant/canvas-horizontal-bar-orientation
Open

nishantmonu51 wants to merge 3 commits into
mainfrom
nishant/canvas-horizontal-bar-orientation

Conversation

@nishantmonu51

@nishantmonu51 nishantmonu51 commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Adds horizontal bar charts to canvas dashboards for bar_chart, stacked_bar and stacked_bar_normalized. x and y always name the field drawn on that axis, so a horizontal chart puts the measure on x and the dimension on y; there is no separate orientation property.

bar_chart:
  metrics_view: sales
  x: { field: revenue, type: quantitative }
  y: { field: region, type: nominal, sort: -x }   # sort categories by the measure
  • Sort values stay channel-relative (-x on y = by measure); x_delta/-x_delta added for delta sorts on x.
  • The provider, the bar builders, the TDD link helper and chart-type switching normalize a horizontal spec to the vertical layout through toVerticalSpec, so queries, sorting, tooltips and comparison logic are untouched. Builders still emit the vertical spec and a single transposeCartesianSpec pass swaps x/y, xOffset/yOffset, band sizes, hover encodings, axis.orient and sort strings, pinning grid lines to the measure axis.
  • Covers single-measure, multi-measure (rill_measures) and time-comparison modes. Brushing is disabled when horizontal since brush signal discovery is x-only.
  • Inspector: pickers are labelled Dimension / Measure with a badge for the axis they drive (dimension always listed first), plus an Orientation switcher whose value is derived from the spec and which swaps the x/y blocks in the YAML (rewriting sort and axis placement). Switching a horizontal bar to a line, area or non-bar chart swaps back to the vertical layout first.
  • Runtime: validateCartesianChart resolves roles from x.type and accepts a quantitative x only for the three bar renderers; create_chart validates x.fields. Chart JSON schema, AI instructions, canvas generator guidance and docs updated. New i18n keys in en and es.

The first commit implemented this as an orientation property; the second replaces it with the swapped x/y layout per review.

Screenshot 2026-09-21 at 11 11 21 PM

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

@AdityaHegde AdityaHegde left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not update the yaml spec and just transposing at the end? Feels weird when x & y in yaml remains the same for horizontal charts.

How about we swap x & y directly in yaml? We will need to rename X-axis to Dimension and Y-axis to Measure in the sidebar editor. We can show what axis they are beside them and add a button to toggle x/y.

@nishantmonu51

nishantmonu51 commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

Kept the keys fixed on purpose: x/y roles are baked into the provider (top-N query, limit, temporal detection, multi-measure fields), the sort semantics (-y = by measure, including delta sort), the Go validators in the reconciler and create_chart, and the explore/TDD/pivot link builders. Swapping them means resolving roles from field types in all of those plus normalizing keys on chart-type switch, while the rendering side stays the same. That is a much bigger change than this PR, so i intentionally chose a path with minimal change

A bar chart is horizontal when its measure sits on `x` (quantitative) and its
dimension on `y`, replacing the `orientation` property. The provider and the
spec builders normalize to the vertical layout and transpose the rendered
spec; the inspector shows Dimension/Measure pickers with an axis badge and an
Orientation switcher that swaps the keys. The reconciler accepts a quantitative
`x` only for the three bar renderers.
@nishantmonu51 nishantmonu51 changed the title feat: add orientation: horizontal to canvas bar charts feat: horizontal canvas bar charts by placing the measure on x Sep 22, 2026
Resolves conflicts in the chart docs and i18n catalogs, and passes the final
channel to the axis label layout so horizontal bars keep upright category labels.

This branch has not been deployed

No deployments
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.

2 participants