Skip to content

Commit a31b3de

Browse files
committed
4031: Updates layout and production tab
1 parent 59de5b3 commit a31b3de

7 files changed

Lines changed: 158 additions & 109 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Monthly Fact Sheet
2+
3+
[Fact sheet](/fact-sheet) summarizing disbursements, revenue, and production data by month on federal and Native American lands.

src/components/data-viz/StackedBarChart/StackedBarChart2.js

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const StackedBarChart2 = ({ data, ...options }) => {
4343
legendHeaders: []
4444
})
4545

46+
const hideLegend = options.hideLegend || false
47+
4648
const [collapsed, setCollapsed] = useState(collapsedLegend || false)
4749
const title = options.title || ''
4850
const buttonValue = collapsed ? 'Show details' : 'Hide details'
@@ -396,7 +398,7 @@ const StackedBarChart2 = ({ data, ...options }) => {
396398
return (
397399
<>
398400
{title && <ChartTitle compact={options.compact}>{title}</ChartTitle>}
399-
<svg width="100%" height="200" viewBox={`0 0 ${ viewBoxWidth } ${ viewBoxHeight }`} pointerEvents="none">
401+
<svg width="100%" height="225" viewBox={`0 0 ${ viewBoxWidth } ${ viewBoxHeight }`} pointerEvents="none">
400402
<title>{svgTitle}</title>
401403
<Translate>
402404
<MaxExtent
@@ -446,23 +448,35 @@ const StackedBarChart2 = ({ data, ...options }) => {
446448
{...bottomAxis.size} />
447449
</Translate>
448450
</svg>
449-
{ collapsibleLegend && <LegendButton variant='text' onClick={ () => setCollapsed(!collapsed) }>{buttonValue}</LegendButton> }
450-
<Collapse in={!collapsed}>
451-
<Legend
452-
data={dataset.legendData}
453-
activeNode={activeNode}
454-
legendHeaders={legendHeaders(legendHeader)}
455-
legendFormat={legendFormat}
456-
legendReverse={false}
457-
legendTotal={true}
458-
xAxis={xAxis}
459-
yAxis={yAxis}
460-
xDomain={xDomain}
461-
colorScale={legendColorScale}
462-
yOrderBy={yOrderBy}
463-
yGroupBy={yGroupBy}
464-
/>
465-
</Collapse>
451+
{ !hideLegend && (
452+
<>
453+
{collapsibleLegend && (
454+
<LegendButton
455+
variant='text'
456+
onClick={() => setCollapsed(!collapsed)}
457+
>
458+
{buttonValue}
459+
</LegendButton>
460+
)}
461+
462+
<Collapse in={!collapsed}>
463+
<Legend
464+
data={dataset.legendData}
465+
activeNode={activeNode}
466+
legendHeaders={legendHeaders(legendHeader)}
467+
legendFormat={legendFormat}
468+
legendReverse={false}
469+
legendTotal={true}
470+
xAxis={xAxis}
471+
yAxis={yAxis}
472+
xDomain={xDomain}
473+
colorScale={legendColorScale}
474+
yOrderBy={yOrderBy}
475+
yGroupBy={yGroupBy}
476+
/>
477+
</Collapse>
478+
</>
479+
)}
466480
</>
467481
)
468482
}

src/components/sections/ComparisonTable/ComparisonTable.js

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import PercentDifference from '../../utils/PercentDifference'
2020
import { DataFilterContext } from '../../../stores/data-filter-store'
2121
import { DATA_FILTER_CONSTANTS as DFC } from '../../../constants'
2222
import 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

2427
const 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+
301349
export default ComparisonTable
302350

303351
ComparisonTable.propTypes = {

src/components/sections/Explore/Explore.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const useStyles = makeStyles(theme => ({
1616
borderBottom: '2px solid #cde3c3',
1717
marginBottom: '1em',
1818
paddingBottom: '.41667rem',
19-
}
19+
marginTop: '0 !important'
20+
},
2021
}))
2122

2223
/**
@@ -31,21 +32,19 @@ const Explore = props => {
3132
return (
3233
<Box component="section" className={classes.root}>
3334
<Box className={classes.contentHeader}>
34-
<Typography variant="h3" className={classes.h3Bar}>
35+
<Typography variant="h3"
36+
className={`${classes.h3Bar}`}>
3537
Explore {props.title}
3638
</Typography>
3739
<Typography variant="body1">
3840
{props.info}
3941
</Typography>
4042
</Box>
4143
<Grid container spacing={0}>
42-
<Grid item md={4} className={classes.exploreContent}>
44+
<Grid item md={6} className={classes.exploreContent}>
4345
{props.contentLeft}
4446
</Grid>
45-
<Grid item md={4} className={classes.exploreContent}>
46-
{props.contentCenter}
47-
</Grid>
48-
<Grid item md={4} className={classes.exploreContent}>
47+
<Grid item md={6} className={classes.exploreContent}>
4948
{props.contentRight}
5049
</Grid>
5150
<Grid item md={12}>

src/components/sections/Explore/ExploreProduction.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,30 @@ const ExploreProduction = props => {
2020
mt={0}>
2121
Query production data
2222
</Link>
23-
</>
24-
}
25-
contentCenter={
26-
<>
2723
<Link
2824
href="/how-revenue-works#the-production-process"
2925
linkType="HowWorks"
3026
mt={0}>
3127
How production works
3228
</Link>
29+
</>
30+
}
31+
contentRight={
32+
<>
3333
<Link
3434
href="/data-by-state-offshore-region"
3535
linkType="Location"
3636
mt={0}>
3737
Data by state and offshore region
3838
</Link>
39-
39+
<Link
40+
href="/downloads/#Production"
41+
linkType="DownloadData"
42+
mt={0}>
43+
Downloads and documentation
44+
</Link>
4045
</>
4146
}
42-
contentRight={
43-
<Link
44-
href="/downloads/#Production"
45-
linkType="DownloadData"
46-
mt={0}>
47-
Downloads and documentation
48-
</Link>
49-
}
5047
/>
5148
)
5249
}

src/components/sections/TotalProduction/TotalProduction.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ const TotalProduction = props => {
188188
}
189189
else if (period === DFC.PERIOD_CALENDAR_YEAR) {
190190
const maxDate = data.total_monthly_calendar_production.filter(row => row.month === 12).pop()
191-
console.debug('DWGH _------------')
192191

193192
comparisonData = data.total_monthly_calendar_production.filter(row => row.product === product)
194193
chartData = data.total_monthly_calendar_production.filter(row => row.product === product && row.year === maxDate.year)
@@ -199,12 +198,10 @@ const TotalProduction = props => {
199198

200199
const minDate = new Date(maxDate.replace(/-/g, '/') + ' 00:00:00')
201200
minDate.setFullYear(minDate.getFullYear() - 1)
202-
// console.debug("MD------", minDate)
203201
chartData = data.total_monthly_last_twelve_production.filter(row => row.product === product && new Date(row.period_date) >= minDate)
204202
}
205203

206204
xGroups = chartData.filter(row => row.product === product).reduce((g, row, i) => {
207-
// console.log('xGroup g, row: ', g, row)
208205
const r = g
209206
const year = row.period_date.substring(0, 4)
210207
const months = g[year] || []
@@ -224,7 +221,6 @@ const TotalProduction = props => {
224221
}
225222

226223
legendHeaders = (headers, row) => {
227-
// console.log('legendHeaders: ', headers, row)
228224
const dateArr = formatDate(headers[1])
229225
const year = dateArr[0]
230226
const date = new Date(dateArr[0], dateArr[1], dateArr[2])
@@ -290,7 +286,7 @@ const TotalProduction = props => {
290286
maxFiscalYear={maxFiscalYear}
291287
maxCalendarYear={maxCalendarYear} />
292288
</Grid>
293-
<Grid item xs={12} md={7}>
289+
<Grid item xs={12} md={12}>
294290
<StackedBarChart2
295291
key={`tpsbc__${ monthly }${ period }${ product }${ dataType }`}
296292
title={[commodity, ' ', <GlossaryTerm termKey={unitAbbrev}>{unitAbbrev}</GlossaryTerm>]}
@@ -316,12 +312,13 @@ const TotalProduction = props => {
316312
legendHeaders={legendHeaders}
317313
handleBarHover={d => handleBarHover(d)}
318314
svgTitle={svgTitle}
315+
hideLegend={true}
319316
/>
320-
<Box fontStyle="italic" textAlign="left" fontSize="h6.fontSize">
321-
<Link href='/downloads/production-by-month/'>Source file</Link>
322-
</Box>
323317
</Grid>
324-
<Grid item xs={12} md={5}>
318+
<Grid item
319+
xs={12}
320+
md={12}
321+
style={{ paddingBottom: 0 }}>
325322
<ComparisonTable
326323
key={`ct__${ monthly }${ period }${ product }`}
327324
ref={productionComparison}
@@ -331,6 +328,12 @@ const TotalProduction = props => {
331328
monthRange={monthRange}
332329
/>
333330
</Grid>
331+
<Grid item xs={12} md={12}
332+
style={{ paddingBottom: 0, paddingTop: 0 }}>
333+
<Box fontStyle="italic" textAlign="left" fontSize="h6.fontSize" m={0}>
334+
<Link href='/downloads/production-by-month/'>Source file</Link>
335+
</Box>
336+
</Grid>
334337
</Grid>
335338
</>
336339
)

0 commit comments

Comments
 (0)