Skip to content

Commit

Permalink
fix(view): label not breaking correctly when green bar is too small
Browse files Browse the repository at this point in the history
  • Loading branch information
MauriceNino committed Sep 18, 2022
1 parent 6b969c3 commit 1cd5e7b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
26 changes: 26 additions & 0 deletions apps/view/src/components/chart-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Area,
AreaChart,
BarChart,
LabelProps,
Pie,
PieChart,
Sector,
Expand Down Expand Up @@ -232,6 +233,31 @@ const ToolTipContainer = styled.div`
gap: 5px;
`;

export const VertBarStartLabel: FC<
LabelProps & {
labelRenderer: (value: number) => string;
}
> = props => {
const theme = useTheme();

return (
<text
x={props.x}
y={(props.y as number) + (props.height as number) / 2}
width={props.width}
height={props.height}
offset={props.offset}
className='recharts-text recharts-label'
text-anchor='start'
fill={theme.colors.text}
>
<tspan x={(props.x as number) + (props.offset as number)} dy='0.355em'>
{props.labelRenderer(props.value as number)}
</tspan>
</text>
);
};

type DefaultVertBarChartProps = {
height: number;
width: number;
Expand Down
12 changes: 7 additions & 5 deletions apps/view/src/widgets/storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useTheme } from 'styled-components';
import {
DefaultPieChart,
DefaultVertBarChart,
VertBarStartLabel,
} from '../components/chart-components';
import {
ChartContainer,
Expand Down Expand Up @@ -225,12 +226,13 @@ export const StorageChart: FC<StorageChartProps> = ({
position='insideLeft'
offset={15}
dataKey='usedPercent'
formatter={(value: number) =>
`%: ${(value * 100).toFixed(1)}`
content={
<VertBarStartLabel
labelRenderer={value =>
`%: ${(value * 100).toFixed(1)}`
}
/>
}
style={{
fill: theme.colors.text,
}}
/>
)}
</Bar>
Expand Down

0 comments on commit 1cd5e7b

Please sign in to comment.