import { forwardRef, useState } from 'react' import Charts from '../Charts' import { ChartType, ChartLegendPosition, NewNestedDataPoint, AxisType, LegendsChangeType, } from '../types' import { chartsAccessibilityReport } from './ChartsAccessibilityReport' import { generateAccessibilityReport, downloadReport, getMimeType, getFileExtension, type ReportFormat, } from '../../shared/accessibility/reportGenerator' import { Download as DownloadIcon, TrendingUp, DollarSign, Activity, BarChart3, PieChart, } from 'lucide-react' import Button from '../../Button/Button' import { ButtonType, ButtonSize } from '../../Button/types' export type ChartsAccessibilityProps = { className?: string } // Helper function to generate sample chart data const generateChartData = (): NewNestedDataPoint[] => [ { name: 'Jan', data: { revenue: { primary: { label: 'Revenue', val: 4000 } }, profit: { primary: { label: 'Profit', val: 2400 } }, expenses: { primary: { label: 'Expenses', val: 1600 } }, }, }, { name: 'Feb', data: { revenue: { primary: { label: 'Revenue', val: 3000 } }, profit: { primary: { label: 'Profit', val: 1398 } }, expenses: { primary: { label: 'Expenses', val: 1602 } }, }, }, { name: 'Mar', data: { revenue: { primary: { label: 'Revenue', val: 2000 } }, profit: { primary: { label: 'Profit', val: 800 } }, expenses: { primary: { label: 'Expenses', val: 1200 } }, }, }, { name: 'Apr', data: { revenue: { primary: { label: 'Revenue', val: 2780 } }, profit: { primary: { label: 'Profit', val: 1908 } }, expenses: { primary: { label: 'Expenses', val: 872 } }, }, }, { name: 'May', data: { revenue: { primary: { label: 'Revenue', val: 1890 } }, profit: { primary: { label: 'Profit', val: 800 } }, expenses: { primary: { label: 'Expenses', val: 1090 } }, }, }, { name: 'Jun', data: { revenue: { primary: { label: 'Revenue', val: 2390 } }, profit: { primary: { label: 'Profit', val: 1200 } }, expenses: { primary: { label: 'Expenses', val: 1190 } }, }, }, ] const ChartsAccessibility = forwardRef< HTMLDivElement, ChartsAccessibilityProps >(({ className }, ref) => { const [selectedFormat, setSelectedFormat] = useState('markdown') const [includeTestResults, setIncludeTestResults] = useState(true) const [includeRecommendations, setIncludeRecommendations] = useState(true) const [reportHtmlContent, setReportHtmlContent] = useState( null ) const [showFullReport, setShowFullReport] = useState(false) const handleDownload = () => { try { const content = generateAccessibilityReport( chartsAccessibilityReport, { format: selectedFormat, includeTestResults, includeRecommendations, } ) const filename = `charts-accessibility-report-${chartsAccessibilityReport.reportDate}.${getFileExtension(selectedFormat)}` const mimeType = getMimeType(selectedFormat) downloadReport(content, filename, mimeType) } catch (error) { console.error('Error generating report:', error) alert('Failed to generate report. Please try again.') } } const handleViewReport = () => { try { const htmlContent = generateAccessibilityReport( chartsAccessibilityReport, { format: 'html', includeTestResults, includeRecommendations, } ) setReportHtmlContent(htmlContent) setShowFullReport(true) } catch (error) { console.error('Error generating report:', error) alert('Failed to generate report. Please try again.') } } const report = chartsAccessibilityReport const compliantCount = report.criteria.filter( (c) => c.status === 'compliant' ).length const nonCompliantCount = report.criteria.filter( (c) => c.status === 'non-compliant' ).length const unsureCount = report.criteria.filter( (c) => c.status === 'unsure' ).length const totalApplicable = report.criteria.filter( (c) => c.status !== 'not-applicable' ).length const complianceRate = totalApplicable > 0 ? Math.round((compliantCount / totalApplicable) * 100) : 0 const chartData = generateChartData() return (

Charts Component Accessibility

WCAG {report.wcagVersion} • {report.conformanceLevel} • {report.reportDate}
Evaluates: WCAG 2.0, 2.1, 2.2
{report.overallStatus.toUpperCase()}
{compliantCount}
Compliant ✅
Verified & tested
{nonCompliantCount}
Non-Compliant ❌
Issues found
{unsureCount}
Unsure ⚠️
Needs verification
{complianceRate}%
Compliance Rate
Based on verified items
{unsureCount > 0 && (
⚠️

Manual Verification Required

{unsureCount} criterion/criteria marked as "unsure" require manual verification. These items need testing with contrast checkers, screen readers, or depend on application context.

)}

Summary

{report.summary}

Download Report

{showFullReport && reportHtmlContent && (

Full Accessibility Report

)}

WCAG Criteria Breakdown

{report.criteria.map((criterion) => (
{criterion.id} -{' '} {criterion.title} Level {criterion.level} {criterion.status .charAt(0) .toUpperCase() + criterion.status.slice( 1 )}

{criterion.description}

Implementation: {' '} {criterion.implementation}

{criterion.testResults && (

Test Results: {' '} {criterion.testResults}

)} {criterion.notes && (

Notes:{' '} {criterion.notes}

)}
))}

Strengths

    {report.strengths.map((strength, index) => (
  • ✓ {strength}
  • ))}

Recommendations

    {report.recommendations.map( (recommendation, index) => (
  • → {recommendation}
  • ) )}

WCAG Versions Covered

WCAG 2.0

    {report.wcagVersions['2.0'].map( (item, index) => (
  • • {item}
  • ) )}

WCAG 2.1

    {report.wcagVersions['2.1'].map( (item, index) => (
  • • {item}
  • ) )}

WCAG 2.2

    {report.wcagVersions['2.2'].length > 0 ? ( report.wcagVersions['2.2'].map( (item, index) => (
  • • {item}
  • ) ) ) : (
  • No new criteria
  • )}

Interactive Examples

Line Chart with Legends

Monthly Financial Overview } slot1={

Bar Chart

Sales Performance by Month } slot1={

Pie Chart with Right Legend

Sales by Category } slot1={

Chart with Stacked Legends

Revenue Trends with Interactive Legends } slot1={

Chart with Collapse Functionality

Expandable Chart with Header Actions } slot1={
) }) ChartsAccessibility.displayName = 'ChartsAccessibility' export default ChartsAccessibility