diff --git a/src/components/reusable/AnalyticsChart.tsx b/src/components/reusable/AnalyticsChart.tsx index 66089bc..e9b1e47 100644 --- a/src/components/reusable/AnalyticsChart.tsx +++ b/src/components/reusable/AnalyticsChart.tsx @@ -91,12 +91,22 @@ export function AnalyticsChart({ data, gridCols }: AnalyticsChartProps) { chartType = 3; // Pie } else if (lowerKey.includes('route')) { chartType = 4; // Donut + } else if (lowerKey.includes('calls')) { + chartType = 6; // Horizontal Bar } else if (lowerKey.includes('brand') || lowerKey.includes('product')) { chartType = 5; // Table } else if (lowerKey.includes('monthly') || lowerKey.includes('yearly')) { chartType = 0; // Bar } + if (chartType === 6) { + finalData.sort((a, b) => { + const aVal = hasSeries ? a[seriesKeys[0]] || 0 : a.value || 0; + const bVal = hasSeries ? b[seriesKeys[0]] || 0 : b.value || 0; + return aVal - bVal; + }); + } + // Determine if it should span full width const isFullWidth = (gridCols === 1) || (!gridCols && charts.length <= 2) || hasSeries || lowerKey.includes('monthly') || lowerKey.includes('yearly') || finalData.length > 8; @@ -104,37 +114,65 @@ export function AnalyticsChart({ data, gridCols }: AnalyticsChartProps) { const minChartWidth = 100; - const renderChartContent = () => { + const renderChartContent = (isHorizontal = false) => { return ( <> - + - + - - - + + {isHorizontal ? ( + <> + + { + if (typeof text === 'string' && text.length > 14) { + return `${text.substring(0, 14)}...`; + } + return text; + }} + /> + + ) : ( + <> + { + if (typeof text === 'string' && text.length > 14) { + return `${text.substring(0, 14)}...`; + } + return text; + }} + /> + + + )} ); @@ -245,16 +283,20 @@ export function AnalyticsChart({ data, gridCols }: AnalyticsChartProps) { ) : chartType === 1 ? ( - - {renderChartContent()} + + {renderChartContent(false)} ) : chartType === 2 ? ( - - {renderChartContent()} + + {renderChartContent(false)} + ) : chartType === 6 ? ( + + {renderChartContent(true)} + ) : ( - - {renderChartContent()} + + {renderChartContent(false)} )}