@@ -11,54 +11,84 @@ import {
1111 Tooltip ,
1212 Legend ,
1313 ResponsiveContainer ,
14- } from 'recharts' ;
15- import { Card } from '@/components/ui/card' ;
14+ } from "recharts" ;
1615
1716interface TimeSeriesViewProps {
1817 data : EnhancedTechPartnerData [ ] ;
1918}
2019
20+
2121interface CustomTooltipProps {
2222 active ?: boolean ;
2323 payload ?: {
2424 name : string ;
25- value : number ;
25+ value : number ;
26+ payload :Record < string , number | string > ;
2627 } [ ] ;
2728 label ?: string ;
2829}
2930
3031const CustomTooltip = ( { active, payload, label } : CustomTooltipProps ) => {
3132 if ( ! active || ! payload ?. length || ! label ) return null ;
33+ console . log ( "The payload is" , payload ) ;
3234
33- const weekNumber = label . replace ( / W e e k W e e k / , 'Week' ) ;
35+ const weekNumber = label . replace ( / W e e k W e e k / , "Week" ) ;
36+ const insightsElements = payload [ 0 ] ;
3437
3538 return (
36- < Card className = "p-3 bg-white/95 shadow-lg border-0" >
37- < div className = "space-y-2" >
38- < div className = "font-medium" > { weekNumber } </ div >
39- < div className = "grid gap-1 text-sm" >
39+ < div className = "p-4 bg-white rounded-lg shadow-sm border border-gray-200" >
40+ < div className = "text-base font-medium text-gray-800 pb-3 border-b border-gray-100" >
41+ { weekNumber }
42+ </ div >
43+
44+ { /* Key Metrics Component */ }
45+ < div className = "py-4 text-sm text-gray-700 space-y-1" >
46+ < div className = "flex justify-between items-center" >
47+ < span className = "text-gray-600" > Avg. Engagement</ span >
48+ < span className = "font-medium text-gray-900" >
49+ { insightsElements ?. payload != null
50+ ? Number ( insightsElements . payload . avgEngagement )
51+ : "N/A" }
52+ </ span >
53+ </ div >
54+ < div className = "flex justify-between items-center" >
55+ < span className = "text-gray-600" > Issues per capita</ span >
56+ < span className = "font-medium text-gray-900" >
57+ { insightsElements ?. payload != null
58+ ? Number ( insightsElements . payload . issuesPerCapita )
59+ : "N/A" }
60+ </ span >
61+ </ div >
62+ </ div >
63+
64+ { /* Partners & Issues List */ }
65+ < div className = "pt-3" >
66+ < div className = "text-xs uppercase font-medium text-gray-500 mb-2" > Partners & Issues </ div >
67+ < div className = "divide-y divide-gray-100" >
4068 { payload . map ( ( entry , index ) => (
41- < div key = { index } className = "flex items-center gap-2" >
42- < div
43- className = "w-3 h-3 rounded-full"
44- style = { { backgroundColor : entry . name } }
45- />
46- < span >
47- { entry . name } : { entry . value } { ' ' }
48- { entry . value === 1 ? 'issue' : 'issues' }
49- </ span >
69+ < div key = { index } className = "flex items-center py-2 text-sm w-full" >
70+ < div className = "flex items-center gap-2 flex-1" >
71+ < span
72+ className = "inline-block w-3 h-3 rounded-full flex-shrink-0"
73+ style = { { backgroundColor : entry . name } }
74+ />
75+ < span className = "text-gray-800" > { entry . name } </ span >
76+ </ div >
77+ < div className = "ml-6 text-gray-700 font-medium" >
78+ { entry . value } { entry . value === 1 ? "issue" : "issues" }
79+ </ div >
5080 </ div >
5181 ) ) }
5282 </ div >
5383 </ div >
54- </ Card >
84+ </ div >
5585 ) ;
5686} ;
5787
88+
5889export function TimeSeriesView ( { data } : TimeSeriesViewProps ) {
59- const chartData = useMemo ( ( ) => {
90+ const chartData = React . useMemo ( ( ) => {
6091 if ( ! data ?. length ) return [ ] ;
61-
6292 // Get all unique weeks and format them
6393 const allWeeks = new Set < string > ( ) ;
6494 data . forEach ( ( partner ) => {
@@ -69,7 +99,9 @@ export function TimeSeriesView({ data }: TimeSeriesViewProps) {
6999 if ( weekNum ) allWeeks . add ( `Week ${ weekNum } ` ) ;
70100 }
71101 } ) ;
72- } ) ;
102+ } ) ;
103+
104+
73105
74106 // Sort weeks by number
75107 const sortedWeeks = Array . from ( allWeeks ) . sort ( ( a , b ) => {
@@ -78,8 +110,12 @@ export function TimeSeriesView({ data }: TimeSeriesViewProps) {
78110 return weekA - weekB ;
79111 } ) ;
80112
113+
81114 // Create data points for each week
82115 return sortedWeeks . map ( ( weekLabel ) => {
116+ let totalEngagement = 0 ;
117+ let totalContributors = 0 ;
118+ let totalIssues = 0 ;
83119 const point : Record < string , string | number > = { week : weekLabel } ;
84120
85121 // Process each partner's data for this week
@@ -90,11 +126,20 @@ export function TimeSeriesView({ data }: TimeSeriesViewProps) {
90126 const currentWeekNum = weekLabel . match ( / W e e k ( \d + ) / ) ?. [ 1 ] ;
91127 return tsWeekNum === currentWeekNum ;
92128 } ) ;
93-
129+
130+ const contributors = weekData ?. contributors . length || 0 ;
131+ const engagement = weekData ?. engagementLevel || 0 ;
94132 // Add the issue count for this partner
95133 point [ partner . partner ] = weekData ?. issueCount || 0 ;
96- } ) ;
97134
135+ if ( contributors > 0 ) {
136+ totalEngagement = engagement ;
137+ totalContributors += contributors ;
138+ totalIssues += weekData ?. issueCount || 0 ;
139+ }
140+ } ) ;
141+ point [ "avgEngagement" ] = ( totalEngagement / data . length ) . toFixed ( 2 ) || 0 ;
142+ point [ "issuesPerCapita" ] = totalContributors > 0 ? ( totalIssues / totalContributors ) . toFixed ( 2 ) : 0 ;
98143 return point ;
99144 } ) ;
100145 } , [ data ] ) ;
0 commit comments