// nivo import { BarDatum } from "@nivo/bar"; // components import { CustomTooltip } from "./custom-tooltip"; // ui import { BarGraph } from "components/ui"; // helpers import { findStringWithMostCharacters } from "helpers/array.helper"; import { generateBarColor } from "helpers/analytics.helper"; // types import { IAnalyticsParams, IAnalyticsResponse } from "types"; // constants 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__email" ? 50 : longestXAxisLabel.length * 5 + 20, }} axisBottom={{ tickSize: 0, tickPadding: 10, tickRotation: barGraphData.data.length > 7 ? -45 : 0, renderTick: params.x_axis === "assignees__email" ? (datum) => { const avatar = analytics.extras.assignee_details?.find( (a) => a.assignees__email === datum.value )?.assignees__avatar; if (avatar && avatar !== "") return ( ); else return ( {datum.value && datum.value !== "None" ? `${datum.value}`.toUpperCase()[0] : "?"} ); } : undefined, }} theme={{ background: "rgb(var(--color-bg-base))", axis: {}, }} /> ); };