feat(CartesianChart): add Bar and a layout prop for horizontal bars - #2880
feat(CartesianChart): add Bar and a layout prop for horizontal bars#2880BenniEngel wants to merge 8 commits into
Conversation
Bars render through the ComposedChart the CartesianChart already hosts, so
axes, grid, legend, tooltip and emptyView are reused as-is. Bar mirrors Area:
dataKey prop or dataKey function with label, categorical or custom color, and
a TypedBar entry in typedCartesianChart.
Grouped is the default — stacking is opt-in via stackId, unlike Area, which
always stacks. Corner radius comes from the new bar.corner-radius token and
lands on the growing end of the bar (top when horizontal, right when
vertical); stacked segments stay square, since recharts cannot round only the
last segment of a stack.
The new layout prop on CartesianChart moves the category axis to the y-axis
("vertical"), which needs XAxis type="number" and YAxis type="category". A
context carries the layout to Bar so it can pick the rounded corners.
Purely additive — no change to existing @flr-generate props.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2c66bec to
cf84bfe
Compare
Coverage Report for ./packages/components/
File CoverageNo changed files found. |
🚀 Preview DeploymentPreview environments are ready:
Images:
|
Co-authored-by: BenniEngel <187296787+BenniEngel@users.noreply.github.com>
|
|
||
| --- | ||
|
|
||
| # Ausrichtung |
There was a problem hiding this comment.
Die Ausrichtung muss meiner Meinung nach ein unter Überschrift von Bar werden. Weil nur bei Bar macht es sinn das Chart zu drehen, Line und Area wird und sollte man auch nicht vertikal darstellen.
| @@ -1,22 +1,4 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <project version="4"> | |||
| <component name="NxAngularConfigService" workspaceLocation="file://$PROJECT_DIR$/nx.json"> | |||
There was a problem hiding this comment.
das sollte nicht mit rein, hat ja auch nix mit der Änderung am Chart zu tun
| <> | ||
| <ExampleChart data={data} /> | ||
| <ExampleChart data={[]} /> | ||
| <BarChart layout="horizontal" /> |
There was a problem hiding this comment.
ich guck mir das grad mal an, das scheint nicht an den Bars zu liegen, tritt auch mit anderen Charts auf
There was a problem hiding this comment.
Ich mach für das Problem ein eigenes Issue auf, du kannst das hier aber so bauen, dann funktioniert es trotzdem:
const createBarData = () => [
{ project: "Alpha", Shields: 68, Hull: 24 },
{ project: "Beta", Shields: 42, Hull: 13 },
{ project: "Gamma", Shields: 21, Hull: 39 },
];
const barData = {
horizontal: createBarData(),
vertical: createBarData(),
};
<CartesianChart data={barData[layout]} height="300px" layout={layout}>
| * The orientation of the axes and graphical items. `"horizontal"` puts the | ||
| * category axis on the x-axis — bars grow upwards. `"vertical"` puts it on | ||
| * the y-axis — bars grow to the side. A vertical layout needs a numeric | ||
| * `XAxis` (`type="number"`) and a categorical `YAxis` (`type="category"` with |
There was a problem hiding this comment.
wenn das immer gesetzt werden muss könnte man es evtl über den Context automatisch setzen?
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
What & why
Adds a bar chart — as a
<Bar>insideCartesianChart, not as a separateBarChart— plus alayoutprop so bars can run vertically or horizontally.CartesianChartalready hosts a rechartsComposedChart, which renders<Bar>natively. So axes, grid, legend, tooltip,
emptyViewandsyncIdare reusedunchanged, and bar/line combinations come for free. A separate component would
have duplicated all of it.
BarmirrorsArea:dataKeyprop ordataKeyfunction withdataKeyLabel, categorical or customcolor,stackId,barSize/maxBarSize/minPointSize,unit. It is@flr-generate all, so it ships asflr-barand as aTypedBarentry intypedCartesianChart.Grouped is the default — stacking is opt-in via
stackId. That deviatesfrom
Area, which always stacks, because side-by-side is what bars are usuallyreached for.
Corner radius comes from the new
bar.corner-radiustoken(
{corner-radius.s}) and lands on the growing end of the bar: top in ahorizontal layout, right in a vertical one. Stacked segments stay square —
recharts cannot round only the last segment of a stack.
layoutonCartesianChartis"horizontal"(default) or"vertical".Vertical moves the category axis to the y-axis and needs
<XAxis type="number" />plus<YAxis type="category" dataKey="…" />; both aredocumented on the prop and in the docs page. A small context carries the layout
down to
Barso it can pick the rounded corners. The provider sits outsideComposedChart, so recharts' children detection is untouched.Purely additive: no change to existing
@flr-generateprops, no migrationneeded.
Also covered: stories (grouped, stacked, horizontal, bars+line), docs page
sections "Darstellungstypen" and "Ausrichtung" with three live examples, type
tests for
Bar, three visual tests across both layouts (Local and Remote),and both orientations on the remote-dom-demo chart page.
Open for UX: should the top of a stack be rounded? Right now the whole
stack is square, which is at least predictable.
Base branch & title
feat(CartesianChart): add Bar and a layout prop for horizontal barsmain—nextdoes not exist before the 1.0.0 cut, so the routingguard is dormant and
feat:targetsmain.Checklist
pnpm lintis clean andpnpm affected:testpasses (browser tests ifbehavior changed)
git diffis empty after the relevantbuild:*targets)de-DEanden-USlocale files —n/a, this change adds no UI text
updated snapshots / the
update-screenshotslabelpnpm test(unit + compile, 8 projects) andpnpm build(no generated diff)are green.
pnpm affected:test:browseris green except three failures thatpredate this branch and are unrelated —
Initials(Local + Remote) andMarkdownEditor states (Local); both reproduce with this branch's changesstashed.
The three new visual tests only have
-darwinbaselines locally, so this PRneeds the
update-screenshotslabel for CI to write the-webkit-linuxones.