import { ComputedDatum } from "@nivo/bar"; import { Theme } from "@nivo/core"; // components import { TIssuePriorities } from "@plane/types"; import { BarGraph } from "@/components/ui"; // helpers import { PRIORITY_GRAPH_GRADIENTS } from "@/constants/dashboard"; import { ISSUE_PRIORITIES } from "@/constants/issue"; import { capitalizeFirstLetter } from "@/helpers/string.helper"; // types // constants type Props = { borderRadius?: number; data: { priority: TIssuePriorities; priority_count: number; }[]; height?: number; onBarClick?: ( datum: ComputedDatum & { color: string; } ) => void; padding?: number; theme?: Theme; }; const PRIORITY_TEXT_COLORS = { urgent: "#CE2C31", high: "#AB4800", medium: "#AB6400", low: "#1F2D5C", none: "#60646C", }; export const IssuesByPriorityGraph: React.FC = (props) => { const { borderRadius = 8, data, height = 300, onBarClick, padding = 0.05, theme } = props; const chartData = data.map((priority) => ({ priority: capitalizeFirstLetter(priority.priority), value: priority.priority_count, })); return ( p.priority_count)} axisBottom={{ tickPadding: 8, tickSize: 0, }} tooltip={(datum) => (
{datum.data.priority}: {datum.value}
)} colors={({ data }) => `url(#gradient${data.priority})`} defs={PRIORITY_GRAPH_GRADIENTS} fill={ISSUE_PRIORITIES.map((p) => ({ match: { id: p.key, }, id: `gradient${p.title}`, }))} onClick={(datum) => { if (onBarClick) onBarClick(datum); }} theme={{ axis: { domain: { line: { stroke: "transparent", }, }, ticks: { text: { fontSize: 13, }, }, }, grid: { line: { stroke: "transparent", }, }, ...theme, }} /> ); };