File size: 2,302 Bytes
fee2f22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
 * DataQualityChart component - Before/after comparison bar chart
 */

import React from 'react';
import {
  Box,
  Typography,
  Paper,
} from '@mui/material';
import {
  Chart as ChartJS,
  CategoryScale,
  LinearScale,
  BarElement,
  Title,
  Tooltip,
  Legend,
} from 'chart.js';
import { Bar } from 'react-chartjs-2';

ChartJS.register(
  CategoryScale,
  LinearScale,
  BarElement,
  Title,
  Tooltip,
  Legend
);

interface DataQualityChartProps {
  beforeCleaning: {
    missingValues: number;
    duplicates: number;
    outliers: number;
    qualityScore: number;
  };
  afterCleaning: {
    missingValues: number;
    duplicates: number;
    outliers: number;
    qualityScore: number;
  };
  title?: string;
}

const DataQualityChart: React.FC<DataQualityChartProps> = ({
  beforeCleaning,
  afterCleaning,
  title = 'Data Quality Comparison',
}) => {
  const labels = ['Missing Values (%)', 'Duplicates', 'Outliers', 'Quality Score'];

  const data = {
    labels,
    datasets: [
      {
        label: 'Before Cleaning',
        data: [
          beforeCleaning.missingValues,
          beforeCleaning.duplicates,
          beforeCleaning.outliers,
          beforeCleaning.qualityScore * 100,
        ],
        backgroundColor: 'rgba(54, 162, 235, 0.7)',
        borderColor: 'rgba(54, 162, 235, 1)',
        borderWidth: 1,
      },
      {
        label: 'After Cleaning',
        data: [
          afterCleaning.missingValues,
          afterCleaning.duplicates,
          afterCleaning.outliers,
          afterCleaning.qualityScore * 100,
        ],
        backgroundColor: 'rgba(75, 192, 192, 0.7)',
        borderColor: 'rgba(75, 192, 192, 1)',
        borderWidth: 1,
      },
    ],
  };

  const options = {
    responsive: true,
    maintainAspectRatio: false,
    plugins: {
      legend: {
        position: 'top' as const,
      },
      title: {
        display: false,
      },
    },
    scales: {
      y: {
        beginAtZero: true,
      },
    },
  };

  return (
    <Paper elevation={2} sx={{ p: 3 }}>
      <Typography variant="h6" gutterBottom sx={{ fontWeight: 600 }}>
        {title}
      </Typography>
      <Box sx={{ height: 300 }}>
        <Bar data={data} options={options} />
      </Box>
    </Paper>
  );
};

export default DataQualityChart;