161 lines
5.9 KiB
TypeScript
161 lines
5.9 KiB
TypeScript
import React from 'react';
|
|
import {
|
|
LineChart,
|
|
Line,
|
|
XAxis,
|
|
YAxis,
|
|
CartesianGrid,
|
|
Tooltip,
|
|
Legend,
|
|
ResponsiveContainer,
|
|
BarChart,
|
|
Bar,
|
|
Cell,
|
|
} from 'recharts';
|
|
import { MultiCoopChartPoint, MultiCoopWeightSummary } from '../../types';
|
|
import { formatWeight } from '../../utils/weightUtils';
|
|
|
|
const chartColors = ['#ef4444', '#3b82f6', '#16a34a', '#f97316', '#8b5cf6'];
|
|
|
|
const ChartContainer: React.FC<{ title: string; children: React.ReactNode }> = ({
|
|
title,
|
|
children,
|
|
}) => (
|
|
<div className="bg-white p-6 rounded-xl shadow-sm">
|
|
<h3 className="text-xl font-bold mb-4">{title}</h3>
|
|
<div className="h-96">{children}</div>
|
|
</div>
|
|
);
|
|
|
|
interface MultiCoopAnalysisProps {
|
|
chartData: MultiCoopChartPoint[];
|
|
summaryData: MultiCoopWeightSummary[];
|
|
coopNames: string[];
|
|
}
|
|
|
|
const MultiCoopAnalysis: React.FC<MultiCoopAnalysisProps> = ({
|
|
chartData,
|
|
summaryData,
|
|
coopNames,
|
|
}) => {
|
|
const targetAdg = 85; // Example target ADG in grams
|
|
const targetUniformity = 85; // Example target uniformity in %
|
|
|
|
return (
|
|
<div>
|
|
<h2 className="text-2xl font-bold text-gray-800 mb-6">Analisis Visual Komparatif</h2>
|
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-8">
|
|
<ChartContainer title="Perbandingan Pertambahan Bobot Harian (ADG)">
|
|
<ResponsiveContainer width="100%" height="100%">
|
|
<BarChart data={summaryData} margin={{ top: 5, right: 20, left: -10, bottom: 20 }}>
|
|
<CartesianGrid strokeDasharray="3 3" stroke="#e0e0e0" />
|
|
<XAxis
|
|
dataKey="coopName"
|
|
fontSize={12}
|
|
tick={{ fill: '#6b7280' }}
|
|
angle={-25}
|
|
textAnchor="end"
|
|
height={50}
|
|
/>
|
|
<YAxis fontSize={12} tick={{ fill: '#6b7280' }} unit="g" />
|
|
<Tooltip
|
|
contentStyle={{
|
|
backgroundColor: 'rgba(255, 255, 255, 0.9)',
|
|
border: '1px solid #ccc',
|
|
borderRadius: '8px',
|
|
}}
|
|
formatter={(value: number) => [`${value} g`, 'ADG']}
|
|
/>
|
|
<Bar dataKey="adg" name="ADG" barSize={30}>
|
|
{summaryData.map((entry, index) => {
|
|
const percentageOfTarget = entry.adg / targetAdg;
|
|
let color = '#16a34a'; // green-600
|
|
if (percentageOfTarget < 0.9)
|
|
color = '#ef4444'; // red-500
|
|
else if (percentageOfTarget < 1) color = '#f59e0b'; // yellow-500
|
|
return <Cell key={`cell-${index}`} fill={color} />;
|
|
})}
|
|
</Bar>
|
|
</BarChart>
|
|
</ResponsiveContainer>
|
|
</ChartContainer>
|
|
<ChartContainer title="Perbandingan Keseragaman (Uniformity)">
|
|
<ResponsiveContainer width="100%" height="100%">
|
|
<BarChart data={summaryData} margin={{ top: 5, right: 20, left: -10, bottom: 20 }}>
|
|
<CartesianGrid strokeDasharray="3 3" stroke="#e0e0e0" />
|
|
<XAxis
|
|
dataKey="coopName"
|
|
fontSize={12}
|
|
tick={{ fill: '#6b7280' }}
|
|
angle={-25}
|
|
textAnchor="end"
|
|
height={50}
|
|
/>
|
|
<YAxis
|
|
fontSize={12}
|
|
tick={{ fill: '#6b7280' }}
|
|
unit="%"
|
|
domain={[70, 'dataMax + 5']}
|
|
/>
|
|
<Tooltip
|
|
contentStyle={{
|
|
backgroundColor: 'rgba(255, 255, 255, 0.9)',
|
|
border: '1px solid #ccc',
|
|
borderRadius: '8px',
|
|
}}
|
|
formatter={(value: number) => [`${value.toFixed(1)}%`, 'Keseragaman']}
|
|
/>
|
|
<Bar dataKey="uniformity" name="Keseragaman" barSize={30}>
|
|
{summaryData.map((entry, index) => {
|
|
let color = '#16a34a'; // green-600
|
|
if (entry.uniformity < 80)
|
|
color = '#ef4444'; // red-500
|
|
else if (entry.uniformity < targetUniformity) color = '#f59e0b'; // yellow-500
|
|
return <Cell key={`cell-${index}`} fill={color} />;
|
|
})}
|
|
</Bar>
|
|
</BarChart>
|
|
</ResponsiveContainer>
|
|
</ChartContainer>
|
|
</div>
|
|
<ChartContainer title="Grafik Tren Pertumbuhan Komparatif">
|
|
<ResponsiveContainer width="100%" height="100%">
|
|
<LineChart data={chartData} margin={{ top: 5, right: 20, left: -10, bottom: 5 }}>
|
|
<CartesianGrid strokeDasharray="3 3" stroke="#e0e0e0" />
|
|
<XAxis
|
|
dataKey="day"
|
|
fontSize={12}
|
|
tick={{ fill: '#6b7280' }}
|
|
label={{ value: 'Hari ke-', position: 'insideBottom', offset: -5 }}
|
|
/>
|
|
<YAxis fontSize={12} tick={{ fill: '#6b7280' }} width={60} />
|
|
<Tooltip
|
|
contentStyle={{
|
|
backgroundColor: 'rgba(255, 255, 255, 0.9)',
|
|
border: '1px solid #ccc',
|
|
borderRadius: '8px',
|
|
}}
|
|
formatter={(value: number) => [formatWeight(value), '']}
|
|
/>
|
|
<Legend wrapperStyle={{ fontSize: '14px' }} verticalAlign="top" align="right" />
|
|
{coopNames.map((name, index) => (
|
|
<Line
|
|
key={name}
|
|
type="monotone"
|
|
dataKey={name}
|
|
stroke={name === 'Target' ? '#8884d8' : chartColors[index % chartColors.length]}
|
|
strokeWidth={name === 'Target' ? 2 : 2.5}
|
|
strokeDasharray={name === 'Target' ? '5 5' : undefined}
|
|
dot={name !== 'Target' ? { r: 3 } : false}
|
|
activeDot={name !== 'Target' ? { r: 5 } : false}
|
|
/>
|
|
))}
|
|
</LineChart>
|
|
</ResponsiveContainer>
|
|
</ChartContainer>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default MultiCoopAnalysis;
|