Skip to content
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

Dynamically set y-axis label width for credits chart #12625

Merged
merged 2 commits into from
May 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions airbyte-webapp/src/components/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from "react";
import { CartesianGrid, BarChart as BasicBarChart, ResponsiveContainer, XAxis, YAxis, Bar, Label } from "recharts";
import { Bar, BarChart as BasicBarChart, CartesianGrid, Label, ResponsiveContainer, XAxis, YAxis } from "recharts";
import { barChartColors, theme } from "theme";

type BarChartProps = {
data?: {
data: {
name: string;
value: number | number[];
value: number;
edmundito marked this conversation as resolved.
Show resolved Hide resolved
}[];
legendLabels: string[];
xLabel?: string;
Expand All @@ -16,6 +16,11 @@ const BarChart: React.FC<BarChartProps> = ({ data, legendLabels, xLabel, yLabel
const chartLinesColor = theme.greyColor20;
const chartTicksColor = theme.lightTextColor;

const width = Math.min(
Copy link
Contributor

Choose a reason for hiding this comment

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

There's some sorting happening. I think it deserves a memo

Math.max([...data].sort((a, b) => b.value - a.value)[0].value.toFixed(0).length * 10, 80),
Copy link
Contributor

Choose a reason for hiding this comment

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

Assumes that there's always at least 1 item in the array?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default data is an array of dates + values at 0.

130
);

return (
<ResponsiveContainer>
<BasicBarChart data={data} margin={{ right: 12, top: 25 }}>
Expand All @@ -38,11 +43,18 @@ const BarChart: React.FC<BarChartProps> = ({ data, legendLabels, xLabel, yLabel
tick={{ fontSize: "11px" }}
tickSize={7}
/>
<YAxis axisLine={false} tickLine={false} stroke={chartTicksColor} tick={{ fontSize: "11px" }} tickSize={10}>
<YAxis
axisLine={false}
tickLine={false}
stroke={chartTicksColor}
tick={{ fontSize: "11px" }}
tickSize={10}
width={width}
>
<Label value={yLabel} fontSize={11} fill={chartTicksColor} fontWeight={600} position="top" offset={10} />
</YAxis>
{legendLabels.map((barName, key) => (
<Bar dataKey={barName} fill={barChartColors[key]} />
<Bar dataKey={barName} key={barName} fill={barChartColors[key]} />
))}
</BasicBarChart>
</ResponsiveContainer>
Expand Down