Skip to content

Commit 3c528a2

Browse files
committed
Add new commentary
1 parent d459db0 commit 3c528a2

File tree

6 files changed

+368
-0
lines changed

6 files changed

+368
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { Box, Flex } from 'theme-ui'
2+
import {
3+
Axis,
4+
Chart,
5+
Grid,
6+
Plot,
7+
TickLabels,
8+
Ticks,
9+
Label,
10+
} from '@carbonplan/charts'
11+
12+
import Project from './project'
13+
14+
const YEARS = [
15+
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022,
16+
]
17+
18+
const Summary = () => {
19+
return (
20+
<Box sx={{ height: 200 }}>
21+
<Chart x={[2010, 2023]} y={[10, 0]} padding={{ top: 20, left: 0 }}>
22+
<Grid vertical values={YEARS} />
23+
<Axis bottom />
24+
<Ticks bottom />
25+
<TickLabels bottom />
26+
<Grid
27+
vertical
28+
values={[2012]}
29+
sx={{ borderColor: 'primary', borderStyle: 'dashed' }}
30+
/>
31+
<Grid
32+
vertical
33+
values={[2022]}
34+
sx={{ borderColor: 'primary', borderStyle: 'dashed' }}
35+
/>
36+
37+
<Plot>
38+
<Project years={YEARS} project={'CAR516'} y={3} />
39+
</Plot>
40+
41+
<Label x={2012} y={0} sx={{ ml: 2, maxWidth: '40%', color: 'primary' }}>
42+
<Box as='span' sx={{ color: 'green' }}>
43+
Crediting stops,
44+
</Box>{' '}
45+
<Box as='span' sx={{ color: 'blue' }}>
46+
gas collection continues
47+
</Box>{' '}
48+
</Label>
49+
50+
<Label x={2022} y={0} align='right' sx={{ mr: 2, color: 'primary' }}>
51+
<Flex sx={{ justifyContent: 'flex-end' }}>
52+
<Box sx={{ maxWidth: ['80%', 'inherit', 'inherit', 'inherit'] }}>
53+
<Box as='span' sx={{ color: 'yellow' }}>
54+
non-additional <br />
55+
crediting begins
56+
</Box>{' '}
57+
</Box>
58+
</Flex>
59+
</Label>
60+
61+
<Label
62+
x={2010}
63+
y={3}
64+
sx={{ color: 'background', ml: 2 }}
65+
height={2}
66+
verticalAlign='middle'
67+
>
68+
Crediting
69+
</Label>
70+
<Label
71+
x={2010}
72+
y={6}
73+
sx={{ color: 'background', ml: 2 }}
74+
height={2}
75+
verticalAlign='middle'
76+
>
77+
Gas collection operation
78+
</Label>
79+
</Chart>
80+
</Box>
81+
)
82+
}
83+
export default Summary
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"CAR466": {
3+
"credit_data": [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2022],
4+
"epa_data": [
5+
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021,
6+
2022
7+
]
8+
},
9+
"CAR473": {
10+
"credit_data": [2010, 2011, 2018, 2019, 2020, 2021, 2022],
11+
"epa_data": [
12+
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021,
13+
2022
14+
]
15+
},
16+
"CAR512": {
17+
"credit_data": [
18+
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2021, 2022, 2023
19+
],
20+
"epa_data": [
21+
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021,
22+
2022
23+
]
24+
},
25+
"CAR514": {
26+
"credit_data": [2010, 2011, 2012, 2022],
27+
"epa_data": [
28+
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021,
29+
2022
30+
]
31+
},
32+
"CAR515": {
33+
"credit_data": [2010, 2011, 2022],
34+
"epa_data": [
35+
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021,
36+
2022
37+
]
38+
},
39+
"CAR516": {
40+
"credit_data": [2010, 2011, 2022],
41+
"epa_data": [
42+
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021,
43+
2022
44+
]
45+
}
46+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { useMemo } from 'react'
2+
import { Rect } from '@carbonplan/charts'
3+
4+
import data from './data.json'
5+
6+
const Timeline = ({ activeYears, color, y, years }) => {
7+
const yearData = useMemo(() => {
8+
let hasInactivated
9+
const result = years.reduce((rects, year) => {
10+
const currentRect = rects[rects.length - 1]
11+
const active = activeYears.includes(year)
12+
let status = 'active'
13+
let fill = color
14+
if (!active) {
15+
fill = 'none'
16+
status = 'inactive'
17+
} else if (hasInactivated) {
18+
fill = 'yellow'
19+
status = 'reactivated'
20+
}
21+
22+
if (!currentRect || currentRect.end || currentRect.status !== status) {
23+
rects.push({
24+
start: year,
25+
status,
26+
fill,
27+
})
28+
if (currentRect && currentRect.status !== status) {
29+
currentRect.end = year - 1
30+
}
31+
}
32+
hasInactivated ||= !active
33+
return rects
34+
}, [])
35+
result[result.length - 1].end ||= years[years.length - 1]
36+
return result
37+
}, [activeYears, color, years])
38+
39+
return (
40+
<g>
41+
{yearData.map(({ start, end, fill }) => (
42+
<Rect key={start} x={[start, end + 1]} y={[y, y + 2]} color={fill} />
43+
))}
44+
</g>
45+
)
46+
}
47+
48+
const Project = ({ project, y, years }) => {
49+
return (
50+
<>
51+
<Timeline
52+
years={years}
53+
color='green'
54+
activeYears={data[project].credit_data}
55+
y={y}
56+
/>
57+
<Timeline
58+
years={years}
59+
color='blue'
60+
activeYears={data[project].epa_data}
61+
y={y + 3}
62+
/>
63+
</>
64+
)
65+
}
66+
67+
export default Project
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Box } from 'theme-ui'
2+
import {
3+
Axis,
4+
Chart,
5+
Grid,
6+
Plot,
7+
TickLabels,
8+
Ticks,
9+
Label,
10+
} from '@carbonplan/charts'
11+
12+
import Project from './project'
13+
import data from './data.json'
14+
const YEARS = [
15+
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022,
16+
]
17+
18+
const Summary = () => {
19+
return (
20+
<Box sx={{ height: 400 }}>
21+
<Chart x={[2010, 2023]} y={[70, 0]} padding={{ left: 0 }}>
22+
<Grid vertical values={YEARS} />
23+
<Axis bottom />
24+
<Ticks bottom />
25+
<TickLabels bottom />
26+
<Plot>
27+
{Object.keys(data).map((project, i) => (
28+
<g key={project}>
29+
<Project
30+
years={YEARS}
31+
key={project}
32+
project={project}
33+
y={(i + 0.24) * 12}
34+
/>
35+
</g>
36+
))}
37+
</Plot>
38+
{Object.keys(data).map((project, i) => (
39+
<Label
40+
key={project}
41+
x={0}
42+
y={(i + 0.24) * 12 - 2.75}
43+
sx={{
44+
mr: [4, 5, 5, 6],
45+
color: 'primary',
46+
mt: '-5px',
47+
}}
48+
>
49+
{project}
50+
</Label>
51+
))}
52+
</Chart>
53+
</Box>
54+
)
55+
}
56+
export default Summary

0 commit comments

Comments
 (0)