11import React , { useState , useEffect } from 'react' ;
2- import { PieChart , Pie , Cell , Tooltip , Legend , ResponsiveContainer } from 'recharts' ;
2+ import { useSelector } from 'react-redux' ;
3+ import { PieChart , Pie , Cell , Tooltip , ResponsiveContainer } from 'recharts' ;
34import styles from './DistributionLaborHours.module.css' ;
45
5- const COLORS = [ '#f9f3e3 ' , '#2a647c ' , '#2e8ea3 ' , '#ffab91 ' , '#ffccbb ' , '#bbbbbbff ' ] ;
6+ const COLORS = [ '#2a647c ' , '#2e8ea3 ' , '#ffab91 ' , '#ffccbb ' , '#bbbbbb ' , '#f9f3e3 ' ] ;
67
7- const CustomTooltip = ( { active, payload, total } ) => {
8+ const CustomTooltip = ( { active, payload, total, darkMode } ) => {
89 if ( active && payload && payload . length ) {
9- const category = payload [ 0 ] . name ;
10- const value = payload [ 0 ] . value ;
10+ const { name, value } = payload [ 0 ] ;
1111 const percent = ( ( value / total ) * 100 ) . toFixed ( 1 ) ;
1212 return (
13- < div className = { styles . tooltip } >
14- < p > { category } </ p >
13+ < div
14+ className = { styles . tooltip }
15+ style = { {
16+ backgroundColor : darkMode ? '#2E3E5A' : '#fff' ,
17+ color : darkMode ? '#fff' : '#000' ,
18+ border : darkMode ? '1px solid #555' : '1px solid #ccc' ,
19+ } }
20+ >
21+ < p > { name } </ p >
1522 < p > { `Hours: ${ value } hrs` } </ p >
1623 < p > { `Percentage: ${ percent } %` } </ p >
1724 </ div >
@@ -21,6 +28,8 @@ const CustomTooltip = ({ active, payload, total }) => {
2128} ;
2229
2330export default function DistributionLaborHours ( ) {
31+ const darkMode = useSelector ( state => state . theme . darkMode ) ;
32+
2433 const [ originalData , setOriginalData ] = useState ( [ ] ) ;
2534 const [ filteredData , setFilteredData ] = useState ( [ ] ) ;
2635 const [ dateRange , setDateRange ] = useState ( { from : '' , to : '' } ) ;
@@ -56,47 +65,55 @@ export default function DistributionLaborHours() {
5665 const totalHours = filteredData . reduce ( ( sum , item ) => sum + item . value , 0 ) ;
5766
5867 return (
59- < div className = { styles . container } >
60- < h3 className = { styles . title } > Distribution of Labor Hours</ h3 >
68+ < div
69+ className = { styles . container }
70+ style = { {
71+ backgroundColor : darkMode ? '#2E3E5A' : '#fff' ,
72+ color : darkMode ? '#f5f5f5' : '#000' ,
73+ } }
74+ >
75+ < h3 className = { styles . title } style = { { color : darkMode ? '#ffffff' : '#000000' } } >
76+ Distribution of Labor Hours
77+ </ h3 >
6178
79+ { /* Filters */ }
6280 < div className = { styles . filters } >
63- < label >
81+ < label style = { { color : darkMode ? '#ffffff' : '#000000' } } >
6482 From:
6583 < input
6684 type = "date"
6785 value = { dateRange . from }
6886 onChange = { e => setDateRange ( { ...dateRange , from : e . target . value } ) }
6987 />
7088 </ label >
71- < label >
89+ < label style = { { color : darkMode ? '#ffffff' : '#000000' } } >
7290 To:
7391 < input
7492 type = "date"
7593 value = { dateRange . to }
7694 onChange = { e => setDateRange ( { ...dateRange , to : e . target . value } ) }
7795 />
7896 </ label >
79- < label >
97+ < label style = { { color : darkMode ? '#ffffff' : '#000000' } } >
8098 Project:
8199 < select onChange = { e => setProjectFilter ( e . target . value ) } value = { projectFilter } >
82100 < option value = "" > All</ option >
83101 < option value = "Project A" > Project A</ option >
84102 < option value = "Project B" > Project B</ option >
85103 </ select >
86104 </ label >
87- < label >
105+ < label style = { { color : darkMode ? '#ffffff' : '#000000' } } >
88106 Member:
89107 < select onChange = { e => setMemberFilter ( e . target . value ) } value = { memberFilter } >
90108 < option value = "" > All</ option >
91109 < option value = "Member 1" > Member 1</ option >
92110 < option value = "Member 2" > Member 2</ option >
93111 </ select >
94112 </ label >
95- < button className = { styles . button } onClick = { ( ) => window . location . reload ( ) } >
96- Submit
97- </ button >
113+ < button className = { styles . button } > Submit</ button >
98114 </ div >
99115
116+ { /* Chart + Legend */ }
100117 < div className = { styles . chartWrapper } >
101118 < div className = { styles . legend } >
102119 { filteredData . map ( ( entry , index ) => (
@@ -105,7 +122,9 @@ export default function DistributionLaborHours() {
105122 className = { styles . colorBox }
106123 style = { { backgroundColor : COLORS [ index % COLORS . length ] } }
107124 />
108- { entry . name } : { entry . value } hrs
125+ < span style = { { color : darkMode ? '#f5f5f5' : '#000' } } >
126+ { entry . name } : { entry . value } hrs
127+ </ span >
109128 </ div >
110129 ) ) }
111130 </ div >
@@ -120,13 +139,14 @@ export default function DistributionLaborHours() {
120139 cx = "50%"
121140 cy = "50%"
122141 outerRadius = { 100 }
123- onClick = { data => alert ( `Drilldown for: ${ data . name } ` ) }
142+ labelLine = { false }
143+ label = { ( { value } ) => `${ ( ( value / totalHours ) * 100 ) . toFixed ( 1 ) } %` }
124144 >
125145 { filteredData . map ( ( entry , index ) => (
126146 < Cell key = { `cell-${ index } ` } fill = { COLORS [ index % COLORS . length ] } />
127147 ) ) }
128148 </ Pie >
129- < Tooltip content = { < CustomTooltip total = { totalHours } /> } />
149+ < Tooltip content = { < CustomTooltip total = { totalHours } darkMode = { darkMode } /> } />
130150 </ PieChart >
131151 </ ResponsiveContainer >
132152 </ div >
0 commit comments