Skip to content

Add horizontal orientation for bar charts#2744

Open
jswir wants to merge 3 commits into
malloydata:mainfrom
jswir:feat/bar-chart-horizontal
Open

Add horizontal orientation for bar charts#2744
jswir wants to merge 3 commits into
malloydata:mainfrom
jswir:feat/bar-chart-horizontal

Conversation

@jswir
Copy link
Copy Markdown
Contributor

@jswir jswir commented Mar 31, 2026

Summary

  • Add # bar_chart { horizontal } tag to render bars horizontally (categories on y-axis, values on x-axis)
  • Support all bar chart modes: basic, grouped (series), and stacked
  • Add horizontal support to createMeasureAxis for interactive reference lines, axis overlay, and brush events on the bottom axis
  • Fix left padding calculation to use label text width instead of rotated-axis height
  • Fix grouped horizontal bars with a nested catPos band scale for correct sub-bar positioning

Demo

https://www.loom.com/share/60e15fabe853477da351625571d78ddf

Test plan

  • Verify horizontal_basic story renders bars horizontally with categories on the left axis
  • Verify horizontal_with_series story renders grouped bars correctly
  • Verify horizontal_stacked story renders stacked bars correctly
  • Verify hovering over the bottom (measure) axis shows a vertical dashed reference line
  • Verify existing vertical bar chart stories are unaffected

🤖 Generated with Claude Code

jswir added 2 commits March 30, 2026 15:03
Introduce a `horizontal` tag property (`# bar_chart { horizontal }`)
that flips the category and measure axes, rendering bars left-to-right
instead of bottom-to-top. The Vega spec generator conditionally swaps
scale ranges, axis orientations, and mark encodings. Combinable with
`.stack` for horizontal stacked bars.

Made-with: Cursor
- Fix TS error: wrap horizontal tickCount in signal ref
- Fix left padding: use labelWidth instead of xAxisSettings.height
  for horizontal category labels
- Fix grouped horizontal bars: add nested catPos band scale within
  group marks so sub-bars position correctly along the height axis
- Add horizontal support to createMeasureAxis: reference lines draw
  as vertical dashed lines, overlay covers bottom axis area, brush
  events use x() instead of y() for position tracking
- Add labelWidth to XAxisSettings and ChartLayoutSettings types
I, James Swirhun <james@credibledata.com>, hereby add my Signed-off-by to this commit: 35caf90
I, James Swirhun <james@credibledata.com>, hereby add my Signed-off-by to this commit: ae9d699

Signed-off-by: James Swirhun <james@credibledata.com>
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.

1 participant