// nivo import { BarDatum } from "@nivo/bar"; // components import { IAnalyticsParams, IAnalyticsResponse } from "@plane/types"; import { Tooltip } from "@plane/ui"; // ui import { BarGraph } from "@/components/ui"; // helpers import { generateBarColor, generateDisplayName } from "@/helpers/analytics.helper"; import { findStringWithMostCharacters } from "@/helpers/array.helper"; // types import { CustomTooltip } from "./custom-tooltip"; type Props = { analytics: IAnalyticsResponse; barGraphData: { data: BarDatum[]; xAxisKeys: string[]; }; params: IAnalyticsParams; yAxisKey: "count" | "estimate"; fullScreen: boolean; }; export const AnalyticsGraph: React.FC = ({ analytics, barGraphData, params, yAxisKey, fullScreen }) => { const generateYAxisTickValues = () => { if (!analytics) return []; let data: number[] = []; if (params.segment) // find the total no of issues in each segment data = Object.keys(analytics.distribution).map((segment) => { let totalSegmentIssues = 0; analytics.distribution[segment].map((s) => { totalSegmentIssues += s[yAxisKey] as number; }); return totalSegmentIssues; }); else data = barGraphData.data.map((d) => d[yAxisKey] as number); return data; }; const longestXAxisLabel = findStringWithMostCharacters(barGraphData.data.map((d) => `${d.name}`)); return ( generateBarColor( params.segment ? `${datum.id}` : `${datum.indexValue}`, analytics, params, params.segment ? "segment" : "x_axis" ) } customYAxisTickValues={generateYAxisTickValues()} tooltip={(datum) => } height={fullScreen ? "400px" : "300px"} margin={{ right: 20, bottom: params.x_axis === "assignees__id" ? 50 : longestXAxisLabel.length * 5 + 20, }} axisBottom={{ tickSize: 0, tickPadding: 10, tickRotation: barGraphData.data.length > 7 ? -45 : 0, renderTick: params.x_axis === "assignees__id" ? (datum) => { const assignee = analytics.extras.assignee_details?.find((a) => a?.assignees__id === datum?.value); if (assignee?.assignees__avatar && assignee?.assignees__avatar !== "") return ( ); else return ( {params.x_axis === "assignees__id" ? datum.value && datum.value !== "None" ? generateDisplayName(datum.value, analytics, params, "x_axis")[0].toUpperCase() : "?" : datum.value && datum.value !== "None" ? `${datum.value}`.toUpperCase()[0] : "?"} ); } : (datum) => ( 7 ? "end" : "middle"}`} fontSize={10} fill="rgb(var(--color-text-200))" className={`${barGraphData.data.length > 7 ? "-rotate-45" : ""}`} > {generateDisplayName(datum.value, analytics, params, "x_axis")} ), }} theme={{ axis: {}, }} /> ); };