-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[WEB-4855] refactor: bar chart improvements #7731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
67887ef
d063573
aa6b71a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ const BAR_TOP_BORDER_RADIUS = 4; // Border radius for the top of bars | |||||||||||||||||||||||||||
| const BAR_BOTTOM_BORDER_RADIUS = 4; // Border radius for the bottom of bars | ||||||||||||||||||||||||||||
| const DEFAULT_LOLLIPOP_LINE_WIDTH = 2; // Width of lollipop stick | ||||||||||||||||||||||||||||
| const DEFAULT_LOLLIPOP_CIRCLE_RADIUS = 8; // Radius of lollipop circle | ||||||||||||||||||||||||||||
| const DEFAULT_BAR_FILL_COLOR = "#6B7280"; // Default color when fill is a function - using a neutral gray from design system | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Types | ||||||||||||||||||||||||||||
| interface TShapeProps { | ||||||||||||||||||||||||||||
|
|
@@ -108,7 +109,7 @@ const CustomBar = React.memo((props: TBarProps) => { | |||||||||||||||||||||||||||
| <path | ||||||||||||||||||||||||||||
| d={getBarPath(x, y, width, height, topBorderRadius, bottomBorderRadius)} | ||||||||||||||||||||||||||||
| className="transition-opacity duration-200" | ||||||||||||||||||||||||||||
| fill={typeof fill === "function" ? fill(payload) : fill} | ||||||||||||||||||||||||||||
| fill={typeof fill === "function" ? DEFAULT_BAR_FILL_COLOR : fill} | ||||||||||||||||||||||||||||
| opacity={opacity} | ||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||
| {showText && ( | ||||||||||||||||||||||||||||
|
|
@@ -139,7 +140,7 @@ const CustomBarLollipop = React.memo((props: TBarProps) => { | |||||||||||||||||||||||||||
| cx={x + width / 2} | ||||||||||||||||||||||||||||
| cy={y} | ||||||||||||||||||||||||||||
| r={DEFAULT_LOLLIPOP_CIRCLE_RADIUS} | ||||||||||||||||||||||||||||
| fill={typeof fill === "function" ? fill(payload) : fill} | ||||||||||||||||||||||||||||
| fill={typeof fill === "function" ? DEFAULT_BAR_FILL_COLOR : fill} | ||||||||||||||||||||||||||||
| stroke="none" | ||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||
|
Comment on lines
140
to
145
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Circle color inconsistent with lollipop stroke. Circle should match computed stroke color when - fill={typeof fill === "function" ? DEFAULT_BAR_FILL_COLOR : fill}
+ fill={typeof fill === "function" ? fill(payload) : fill}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| {showPercentage && ( | ||||||||||||||||||||||||||||
|
|
@@ -176,6 +177,8 @@ const createShapeVariant = | |||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| export { DEFAULT_BAR_FILL_COLOR }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| export const barShapeVariants: Record< | ||||||||||||||||||||||||||||
| TBarChartShapeVariant, | ||||||||||||||||||||||||||||
| (props: TShapeProps, bar: TBarItem<string>, stackKeys: string[]) => React.ReactNode | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,7 +19,7 @@ import { TBarChartProps } from "@plane/types"; | |||||||||||||||||
| import { getLegendProps } from "../components/legend"; | ||||||||||||||||||
| import { CustomXAxisTick, CustomYAxisTick } from "../components/tick"; | ||||||||||||||||||
| import { CustomTooltip } from "../components/tooltip"; | ||||||||||||||||||
| import { barShapeVariants } from "./bar"; | ||||||||||||||||||
| import { barShapeVariants, DEFAULT_BAR_FILL_COLOR } from "./bar"; | ||||||||||||||||||
|
|
||||||||||||||||||
| export const BarChart = React.memo(<K extends string, T extends string>(props: TBarChartProps<K, T>) => { | ||||||||||||||||||
| const { | ||||||||||||||||||
|
|
@@ -35,6 +35,7 @@ export const BarChart = React.memo(<K extends string, T extends string>(props: T | |||||||||||||||||
| x: undefined, | ||||||||||||||||||
| y: 10, | ||||||||||||||||||
| }, | ||||||||||||||||||
| customTicks, | ||||||||||||||||||
| showTooltip = true, | ||||||||||||||||||
| customTooltipContent, | ||||||||||||||||||
| } = props; | ||||||||||||||||||
|
|
@@ -65,6 +66,7 @@ export const BarChart = React.memo(<K extends string, T extends string>(props: T | |||||||||||||||||
| key={bar.key} | ||||||||||||||||||
| dataKey={bar.key} | ||||||||||||||||||
| stackId={bar.stackId} | ||||||||||||||||||
| fill={typeof bar.fill === "function" ? DEFAULT_BAR_FILL_COLOR : bar.fill} | ||||||||||||||||||
| opacity={!!activeLegend && activeLegend !== bar.key ? 0.1 : 1} | ||||||||||||||||||
| shape={(shapeProps: any) => { | ||||||||||||||||||
| const shapeVariant = barShapeVariants[bar.shapeVariant ?? "bar"]; | ||||||||||||||||||
|
|
@@ -96,7 +98,10 @@ export const BarChart = React.memo(<K extends string, T extends string>(props: T | |||||||||||||||||
| <CartesianGrid stroke="rgba(var(--color-border-100), 0.8)" vertical={false} /> | ||||||||||||||||||
| <XAxis | ||||||||||||||||||
| dataKey={xAxis.key} | ||||||||||||||||||
| tick={(props) => <CustomXAxisTick {...props} />} | ||||||||||||||||||
| tick={(props) => { | ||||||||||||||||||
| const TickComponent = customTicks?.x || CustomXAxisTick; | ||||||||||||||||||
| return <TickComponent {...props} />; | ||||||||||||||||||
| }} | ||||||||||||||||||
|
Comment on lines
+101
to
+104
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regression: X-axis tick formatter (getLabel) dropped. Same issue as LineChart; pass through - tick={(props) => {
- const TickComponent = customTicks?.x || CustomXAxisTick;
- return <TickComponent {...props} />;
- }}
+ tick={(props) => {
+ const TickComponent = customTicks?.x || CustomXAxisTick;
+ return <TickComponent {...props} getLabel={xAxis.getLabel} />;
+ }}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| tickLine={false} | ||||||||||||||||||
| axisLine={false} | ||||||||||||||||||
| label={{ | ||||||||||||||||||
|
|
@@ -118,7 +123,10 @@ export const BarChart = React.memo(<K extends string, T extends string>(props: T | |||||||||||||||||
| dx: yAxis.dx ?? -16, | ||||||||||||||||||
| className: AXIS_LABEL_CLASSNAME, | ||||||||||||||||||
| }} | ||||||||||||||||||
| tick={(props) => <CustomYAxisTick {...props} />} | ||||||||||||||||||
| tick={(props) => { | ||||||||||||||||||
| const TickComponent = customTicks?.y || CustomYAxisTick; | ||||||||||||||||||
| return <TickComponent {...props} />; | ||||||||||||||||||
| }} | ||||||||||||||||||
| tickCount={tickCount.y} | ||||||||||||||||||
| allowDecimals={!!yAxis.allowDecimals} | ||||||||||||||||||
| /> | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,6 +32,7 @@ export const LineChart = React.memo(<K extends string, T extends string>(props: | |||||||||||||||||
| x: undefined, | ||||||||||||||||||
| y: 10, | ||||||||||||||||||
| }, | ||||||||||||||||||
| customTicks, | ||||||||||||||||||
| legend, | ||||||||||||||||||
| showTooltip = true, | ||||||||||||||||||
| } = props; | ||||||||||||||||||
|
|
@@ -100,7 +101,10 @@ export const LineChart = React.memo(<K extends string, T extends string>(props: | |||||||||||||||||
| <CartesianGrid stroke="rgba(var(--color-border-100), 0.8)" vertical={false} /> | ||||||||||||||||||
| <XAxis | ||||||||||||||||||
| dataKey={xAxis.key} | ||||||||||||||||||
| tick={(props) => <CustomXAxisTick {...props} />} | ||||||||||||||||||
| tick={(props) => { | ||||||||||||||||||
| const TickComponent = customTicks?.x || CustomXAxisTick; | ||||||||||||||||||
| return <TickComponent {...props} />; | ||||||||||||||||||
| }} | ||||||||||||||||||
|
Comment on lines
+104
to
+107
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regression: X-axis tick formatter (getLabel) no longer applied.
Apply: - tick={(props) => {
- const TickComponent = customTicks?.x || CustomXAxisTick;
- return <TickComponent {...props} />;
- }}
+ tick={(props) => {
+ const TickComponent = customTicks?.x || CustomXAxisTick;
+ return <TickComponent {...props} getLabel={xAxis.getLabel} />;
+ }}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| tickLine={false} | ||||||||||||||||||
| axisLine={false} | ||||||||||||||||||
| label={ | ||||||||||||||||||
|
|
@@ -126,7 +130,10 @@ export const LineChart = React.memo(<K extends string, T extends string>(props: | |||||||||||||||||
| className: AXIS_LABEL_CLASSNAME, | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| tick={(props) => <CustomYAxisTick {...props} />} | ||||||||||||||||||
| tick={(props) => { | ||||||||||||||||||
| const TickComponent = customTicks?.y || CustomYAxisTick; | ||||||||||||||||||
| return <TickComponent {...props} />; | ||||||||||||||||||
| }} | ||||||||||||||||||
| tickCount={tickCount.y} | ||||||||||||||||||
| allowDecimals={!!yAxis.allowDecimals} | ||||||||||||||||||
| /> | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: functional fills are ignored; bars won’t use per-datapoint color.
When
fillis a function, this should callfill(payload), not a static default.📝 Committable suggestion
🤖 Prompt for AI Agents