77 CartesianGrid ,
88 Legend ,
99 Line ,
10- LineChart ,
10+ ComposedChart ,
1111 ResponsiveContainer ,
1212 Tooltip ,
1313 XAxis ,
@@ -48,7 +48,7 @@ import './PulseReportPage.css';
4848// Recharts doesn't support using CSS variables, so we can't
4949// easily use color variables defined in variables.css.
5050const ociDarkBlue = '#2c519e' ;
51- // const ociLightBlue = '#76c8d4'; // not currently used
51+ const ociLightBlue = '#76c8d4' ;
5252// const ociOrange = '#f8b576'; // too light
5353const orange = '#b26801' ;
5454
@@ -145,7 +145,7 @@ const PulseReportPage = () => {
145145 // This creates data in the format that recharts needs from pulse data.
146146 useEffect ( ( ) => {
147147 const averageData = { } ; // key is member id
148- const lineChartData = [ ] ;
148+ const lineChartDataPoints = [ ] ;
149149 const frequencies = [ ] ;
150150 for ( let i = 1 ; i <= 5 ; i ++ ) {
151151 frequencies . push ( { score : i , internal : 0 , external : 0 } ) ;
@@ -162,11 +162,16 @@ const PulseReportPage = () => {
162162 const [ year , month , day ] = submissionDate ;
163163 const monthPadded = month . toString ( ) . padStart ( 2 , '0' ) ;
164164 const dayPadded = day . toString ( ) . padStart ( 2 , '0' ) ;
165- lineChartData . push ( {
166- date : `${ year } -${ monthPadded } -${ dayPadded } ` ,
167- internal : internalScore ,
168- external : externalScore
169- } ) ;
165+ const date = `${ year } -${ monthPadded } -${ dayPadded } ` ;
166+ const found = lineChartDataPoints . find ( points => points . date === date )
167+ if ( found ) {
168+ found ?. datapoints ?. push ( pulse ) ;
169+ } else {
170+ lineChartDataPoints . push ( {
171+ date,
172+ datapoints : [ pulse ]
173+ } ) ;
174+ }
170175
171176 frequencies [ internalScore - 1 ] . internal ++ ;
172177 frequencies [ externalScore - 1 ] . external ++ ;
@@ -200,7 +205,14 @@ const PulseReportPage = () => {
200205 }
201206 }
202207
203- setLineChartData ( lineChartData ) ;
208+ setLineChartData ( lineChartDataPoints . map ( day => (
209+ {
210+ date : day . date ,
211+ internal : day . datapoints . reduce ( ( acc , current ) => acc + current . internalScore , 0 ) / day . datapoints . length ,
212+ external : day . datapoints . reduce ( ( acc , current ) => acc + current . externalScore , 0 ) / day . datapoints . length ,
213+ responses : day . datapoints . length ,
214+ }
215+ ) ) ) ;
204216 setBarChartData ( frequencies ) ;
205217
206218 for ( const memberId of Object . keys ( averageData ) ) {
@@ -425,7 +437,7 @@ const PulseReportPage = () => {
425437 />
426438 < CardContent >
427439 < ResponsiveContainer width = "100%" aspect = { 3.0 } >
428- < LineChart data = { lineChartData } height = { 300 } >
440+ < ComposedChart data = { lineChartData } height = { 300 } >
429441 < CartesianGrid strokeDasharray = "3 3" />
430442 < XAxis
431443 angle = { - 90 }
@@ -438,18 +450,24 @@ const PulseReportPage = () => {
438450 < Tooltip />
439451 < Legend />
440452 < Line
441- type = "monotone"
442453 dataKey = "internal"
443454 stroke = { ociDarkBlue }
444455 dot = { false }
456+ type = "monotone"
445457 />
446458 < Line
447459 dataKey = "external"
448460 dot = { false }
449461 stroke = { orange }
450462 type = "monotone"
451463 />
452- </ LineChart >
464+ < Bar
465+ dataKey = "responses"
466+ barSize = { 20 }
467+ fill = { ociLightBlue }
468+ type = "monotone"
469+ />
470+ </ ComposedChart >
453471 </ ResponsiveContainer >
454472 </ CardContent >
455473 </ Card >
0 commit comments