@@ -20,6 +20,9 @@ import PercentDifference from '../../utils/PercentDifference'
2020import { DataFilterContext } from '../../../stores/data-filter-store'
2121import { DATA_FILTER_CONSTANTS as DFC } from '../../../constants'
2222import ChartTitle from '../../data-viz/ChartTitle'
23+ import GlossaryTerm from '../../GlossaryTerm/GlossaryTerm'
24+ import Rect from '../../../components/data-viz/svg/Rect'
25+ import * as d3 from 'd3'
2326
2427const useStyles = makeStyles ( theme => ( {
2528 comparisonTable : {
@@ -28,10 +31,7 @@ const useStyles = makeStyles(theme => ({
2831 } ,
2932 } ,
3033 comparisonTableContent : {
31- height : '210px' ,
32- [ theme . breakpoints . down ( 'sm' ) ] : {
33- height : 'auto'
34- }
34+ marginBottom : '1em'
3535 } ,
3636 tableCellRoot : {
3737 fontSize : '1rem' ,
@@ -55,7 +55,7 @@ const ComparisonTable = forwardRef((props, ref) => {
5555
5656 const classes = useStyles ( )
5757 const theme = useTheme ( )
58- const matchesSmDown = useMediaQuery ( theme . breakpoints . down ( 'sm' ) )
58+ const matchesSmDown = true ; // useMediaQuery(theme.breakpoints.down('sm'))
5959
6060 // //console.debug('ComparisonTable props: ', props)
6161
@@ -110,6 +110,7 @@ const ComparisonTable = forwardRef((props, ref) => {
110110 // Text output
111111 const month = ( monthly === DFC . MONTHLY_CAPITALIZED && selectedItem . month ) && selectedItem . month . substring ( 0 , 3 )
112112 const previousYearText = `${ periodAbbr } ${ previousYear } `
113+ const currentYearText = `${ periodAbbr } ${ currentYear } `
113114 const changeText = 'Change'
114115
115116 // grouped data
@@ -160,14 +161,11 @@ const ComparisonTable = forwardRef((props, ref) => {
160161
161162 return newObj
162163 } )
163- // //console.debug('comparisonData :', comparisonData)
164+
164165 comparisonData . sort ( ( a , b ) => yOrderBy . indexOf ( a . previous [ yGroupBy ] ) - yOrderBy . indexOf ( b . previous [ yGroupBy ] ) )
165166
166167 const cData = comparisonData . slice ( ) . sort ( ( a , b ) => yOrderBy . indexOf ( a . key ) - yOrderBy . indexOf ( b . key ) )
167168
168- // console.log('comparisonData: ', comparisonData)
169- // console.log('cData: ', cData)
170-
171169 // get previous/current year totals
172170 const previousYearTotals = comparisonData . map ( item => item . previous . sum )
173171 const previousYearTotal = previousYearTotals . reduce ( ( acc , item ) => acc + item )
@@ -212,8 +210,31 @@ const ComparisonTable = forwardRef((props, ref) => {
212210 return utils . formatToDollarInt ( sum )
213211 }
214212 }
215- // //console.debug("Comparison CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCdata ", cData)
216- // //console.debug("Comparison "+currentYearTotal+" && "+previousYearTotal+" && "+currentYearTotal +"!== 0 && " + previousYearTotal +" !== 0")
213+
214+ const primaryColor = '#37253c'
215+ const secondaryColor = '#c4d99b'
216+
217+ // color Scale
218+ const color = ( flipColorRange = false , scaleLinear = false ) => {
219+ let color
220+
221+ if ( scaleLinear ) {
222+ color = d3 . scaleLinear ( )
223+ . domain ( [ 0 , yOrderBy . length > 0 ? yOrderBy . length - 1 : 0 || 4 ] )
224+ . range ( flipColorRange ? [ secondaryColor , primaryColor ] : [ primaryColor , secondaryColor ] )
225+ }
226+ else {
227+ const colorDomain = flipColorRange
228+ ? [ yOrderBy . length > 0 ? yOrderBy . length - 1 : 0 || 4 , 0 ]
229+ : [ 0 , yOrderBy . length > 0 ? yOrderBy . length - 1 : 0 || 4 ]
230+ color = d3 . scaleSequential ( d3 . interpolateViridis )
231+ . domain ( colorDomain )
232+ }
233+ return color
234+ }
235+
236+ const colorScale = color ( true )
237+
217238 return (
218239 < Box ref = { ref } >
219240 { comparisonTitle && < ChartTitle compact = { false } > { comparisonTitle } </ ChartTitle > }
@@ -229,6 +250,13 @@ const ComparisonTable = forwardRef((props, ref) => {
229250 < Box fontWeight = "bold" style = { { textTransform : 'capitalize' } } > { yGroupBy } </ Box >
230251 </ TableCell >
231252 }
253+ < TableCell component = "th" align = "right" classes = { { root : classes . tableCellRoot , head : classes . tableCellHead } } >
254+ < Box fontWeight = "bold" >
255+ { month
256+ ? `${ month } ${ currentYear } ${ ( dataType === DFC . PRODUCTION ) ? unitText : '' } `
257+ : `${ currentYearText } ${ comparisonText } ${ ( dataType === DFC . PRODUCTION ) ? unitText : '' } ` }
258+ </ Box >
259+ </ TableCell >
232260 < TableCell component = "th" align = "right" classes = { { root : classes . tableCellRoot , head : classes . tableCellHead } } >
233261 < Box fontWeight = "bold" >
234262 { month
@@ -238,18 +266,31 @@ const ComparisonTable = forwardRef((props, ref) => {
238266 </ TableCell >
239267 < TableCell component = "th" align = "right" classes = { { root : classes . tableCellRoot , head : classes . tableCellHead } } >
240268 < Box fontWeight = "bold" > { changeText } </ Box >
241- { /* <Box fontSize="14px">{changeAdditionalText}</Box> */ }
242269 </ TableCell >
243270 </ TableRow >
244271 </ TableHead >
245272 < TableBody >
246273 { cData && cData . map ( ( item , index ) => (
247274 < TableRow key = { `tr__${ index } ` } >
248- { matchesSmDown &&
249- < TableCell classes = { { root : classes . tableCellRoot } } >
250- < Box fontSize = "16px" > { item . key || '' } </ Box >
251- </ TableCell >
252- }
275+ < TableCell classes = { { root : classes . tableCellRoot } } >
276+ < Rect
277+ width = { 20 }
278+ height = { 20 }
279+ title = { item . key }
280+ styles = { { fill : colorScale ( index ) , marginTop : 0 , marginRight : '1rem' } }
281+ />
282+ < GlossaryTerm
283+ termKey = { item . key }
284+ isInTable = { true }
285+ style = { { whiteSpace : 'inherit' } } >
286+ { item . key }
287+ </ GlossaryTerm >
288+ </ TableCell >
289+ < TableCell align = "right" classes = { { root : classes . tableCellRoot } } >
290+ < Box >
291+ { ( item . current && item . current . sum !== 0 ) ? formatSum ( item . current . sum ) : '-' }
292+ </ Box >
293+ </ TableCell >
253294 < TableCell align = "right" classes = { { root : classes . tableCellRoot } } >
254295 < Box >
255296 { ( item . previous && item . previous . sum !== 0 ) ? formatSum ( item . previous . sum ) : '-' }
@@ -273,6 +314,11 @@ const ComparisonTable = forwardRef((props, ref) => {
273314 { matchesSmDown &&
274315 < TableCell classes = { { root : classes . tableCellRoot } } > </ TableCell >
275316 }
317+ < TableCell align = "right" classes = { { root : classes . tableCellRoot } } >
318+ < Box fontWeight = "bold" >
319+ { currentYearTotal !== 0 ? formatSum ( currentYearTotal ) : '-' }
320+ </ Box >
321+ </ TableCell >
276322 < TableCell align = "right" classes = { { root : classes . tableCellRoot } } >
277323 < Box fontWeight = "bold" >
278324 { previousYearTotal !== 0 ? formatSum ( previousYearTotal ) : '-' }
@@ -298,6 +344,8 @@ const ComparisonTable = forwardRef((props, ref) => {
298344 )
299345} )
300346
347+ ComparisonTable . displayName = 'ComparisonTable'
348+
301349export default ComparisonTable
302350
303351ComparisonTable . propTypes = {
0 commit comments