Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Total climate pollution chart & projection to 0 by 2050 #43

Merged
merged 11 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
307 changes: 307 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"react-icons": "^3.11.0",
"react-select": "^3.1.0",
"react-svg-map": "^2.2.0",
"recharts": "^1.8.5",
"recharts": "^2.1.9",
"typescript": "^3.9.5",
"url-search-params-polyfill": "^8.1.0"
},
Expand Down
79 changes: 79 additions & 0 deletions src/components/simpleareachart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from "react"
import {
AreaChart,
Area,
XAxis,
YAxis,
CartesianGrid,
Tooltip,
Legend,
ResponsiveContainer,
ReferenceLine,
Label
} from "recharts"

export default function SimpleAreaChart ({emissions_data}) {

const annualhistoricalEmissions = emissions_data.map((item) => {
var data = { year: item.year, hist: 0 }
data.hist = Math.round(Object.entries(item)
.filter(([key, _val]) => key !== 'year')
.reduce((acc, [_key, val]) => acc + val, 0))
return data
})

const currYear = new Date().getFullYear()
const yearsLeft = 2050 - currYear
const reduceFrom = annualhistoricalEmissions[annualhistoricalEmissions.length - 1].hist
var projection = []


for (let step = 0; step < (yearsLeft + 1); step++) {
if (step == 0) { projection.push({ year: currYear, hist: reduceFrom, projected: reduceFrom }) }
else { projection.push({ year: step + currYear, projected: Math.round(reduceFrom - reduceFrom * step / yearsLeft)}) }
}

var data = annualhistoricalEmissions.concat(projection)

return (
<ResponsiveContainer width="100%" height={500}>
<AreaChart
width={800}
height={400}
data={data}
margin={{
top: 10,
right: 30,
left: 0,
bottom: 0
}}
>
{/* <Legend align="center" verticalAlign="top" iconType="square" iconSize="15" /> */}
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="year" >
<Label value="Year" offset={0} position="insideBottom"/>
</XAxis>
<YAxis />
<Tooltip />
<Area
type="monotone"
dataKey="hist"
stackId="1"
stroke="#b65c00"
fill="#e8ceb3"
name="Emissions"
/>
<Area
type="monotone"
dataKey="projected"
stackId="2"
stroke="#36a654"
fill="#c1e5cb"
name="Projection"
/>
<ReferenceLine x="2018" stroke="none" label={{value:"Emissions", angle:90, fill:"#b65c00"}} />
<ReferenceLine x="2024" stroke="none" label={{value:"Projections", angle:90, fill:"#36a654"}} />
</AreaChart>
</ResponsiveContainer>
)
}
Loading