fix: x-axis labels overlapping in mobile view

This commit is contained in:
LAKHAN BAHETI 2024-01-30 17:15:23 +05:30
parent c7616fda11
commit 960bf03ac1
2 changed files with 68 additions and 46 deletions

View File

@ -65,7 +65,7 @@ export const AnalyticsScope: React.FC<Props> = ({ defaultAnalytics }) => (
); );
}, },
}} }}
margin={{ top: 20 }} margin={{ top: 20, right: 20 }}
theme={{ theme={{
axis: {}, axis: {},
}} }}

View File

@ -6,54 +6,76 @@ import emptyGraph from "public/empty-state/empty_graph.svg";
import { IDefaultAnalyticsResponse } from "@plane/types"; import { IDefaultAnalyticsResponse } from "@plane/types";
// constants // constants
import { MONTHS_LIST } from "constants/calendar"; import { MONTHS_LIST } from "constants/calendar";
import { useEffect, useState } from "react";
type Props = { type Props = {
defaultAnalytics: IDefaultAnalyticsResponse; defaultAnalytics: IDefaultAnalyticsResponse;
}; };
export const AnalyticsYearWiseIssues: React.FC<Props> = ({ defaultAnalytics }) => ( export const AnalyticsYearWiseIssues: React.FC<Props> = ({ defaultAnalytics }) => {
<div className="rounded-[10px] border border-custom-border-200 py-3"> // states
<h1 className="px-3 text-base font-medium">Issues closed in a year</h1> const [width, setWidth] = useState(window.innerWidth);
{defaultAnalytics.issue_completed_month_wise.length > 0 ? ( useEffect(() => {
<LineGraph // event listener to update the width
data={[ window.addEventListener("resize", () => {
{ if (width <= 768 && window.innerWidth > 768) {
id: "issues_closed", setWidth(window.innerWidth);
color: "rgb(var(--color-primary-100))", } else if (width >= 768 && window.innerWidth < 768) {
data: Object.entries(MONTHS_LIST).map(([index, month]) => ({ setWidth(window.innerWidth);
x: month.shortTitle, }
y: });
defaultAnalytics.issue_completed_month_wise.find((data) => data.month === parseInt(index, 10))?.count || }, []);
0,
})), return (
}, <div className="rounded-[10px] border border-custom-border-200 py-3">
]} <h1 className="px-3 text-base font-medium">Issues closed in a year</h1>
customYAxisTickValues={defaultAnalytics.issue_completed_month_wise.map((data) => data.count)} {defaultAnalytics.issue_completed_month_wise.length > 0 ? (
height="300px" <LineGraph
colors={(datum) => datum.color} data={[
curve="monotoneX" {
margin={{ top: 20 }} id: "issues_closed",
enableSlices="x" color: "rgb(var(--color-primary-100))",
sliceTooltip={(datum) => ( data: Object.entries(MONTHS_LIST).map(([index, month]) => ({
<div className="rounded-md border border-custom-border-200 bg-custom-background-80 p-2 text-xs"> x: month.shortTitle,
{datum.slice.points[0].data.yFormatted} y:
<span className="text-custom-text-200"> issues closed in </span> defaultAnalytics.issue_completed_month_wise.find((data) => data.month === parseInt(index, 10))
{datum.slice.points[0].data.xFormatted} ?.count || 0,
</div> })),
)} },
theme={{ ]}
background: "rgb(var(--color-background-100))", axisBottom={{
}} // if width is less than 768px, rotate the x-axis labels
enableArea ...(width < 768 && {
/> tickRotation: -45,
) : ( }),
<div className="px-7 py-4"> }}
<ProfileEmptyState customYAxisTickValues={defaultAnalytics.issue_completed_month_wise.map((data) => data.count)}
title="No Data yet" height="300px"
description="Close issues to view analysis of the same in the form of a graph." colors={(datum) => datum.color}
image={emptyGraph} curve="monotoneX"
margin={{ top: 20, right: 20 }}
enableSlices="x"
sliceTooltip={(datum) => (
<div className="rounded-md border border-custom-border-200 bg-custom-background-80 p-2 text-xs">
{datum.slice.points[0].data.yFormatted}
<span className="text-custom-text-200"> issues closed in </span>
{datum.slice.points[0].data.xFormatted}
</div>
)}
theme={{
background: "rgb(var(--color-background-100))",
}}
enableArea
/> />
</div> ) : (
)} <div className="px-7 py-4">
</div> <ProfileEmptyState
); title="No Data yet"
description="Close issues to view analysis of the same in the form of a graph."
image={emptyGraph}
/>
</div>
)}
</div>
);
};