-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of [email protected]:CodeforKarlsruhe/klimadashboard…
…-ka.git into main
- Loading branch information
Showing
16 changed files
with
311 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const DATA = `year,category,type,co2,note | ||
2007,Private Haushalte,real,715.7857296,BICO2BW-Bilanz | ||
2007,Gewerbe+Sonstiges,real,549.7853971,BICO2BW-Bilanz | ||
2007,Industrie,real,1243.614282,BICO2BW-Bilanz | ||
2007,Stadt,real,56.10044454,BICO2BW-Bilanz | ||
2007,Verkehr,real,711.03089,BICO2BW-Bilanz | ||
2008,Private Haushalte,real,697.5581534,BICO2BW-Bilanz | ||
2008,Gewerbe+Sonstiges,real,545.0097993,BICO2BW-Bilanz | ||
2008,Industrie,real,1140.871711,BICO2BW-Bilanz | ||
2008,Stadt,real,50.97856918,BICO2BW-Bilanz | ||
2008,Verkehr,real,702.205135,BICO2BW-Bilanz | ||
2009,Private Haushalte,real,628.371129,BICO2BW-Bilanz | ||
2009,Gewerbe+Sonstiges,real,658.8991141,BICO2BW-Bilanz | ||
2009,Industrie,real,597.5579779,BICO2BW-Bilanz | ||
2009,Stadt,real,56.69074899,BICO2BW-Bilanz | ||
2009,Verkehr,real,684.0569772,BICO2BW-Bilanz | ||
2010,Private Haushalte,real,621.9082222,BICO2BW-Bilanz | ||
2010,Gewerbe+Sonstiges,real,667.7497841,BICO2BW-Bilanz | ||
2010,Industrie,real,689.4283378,BICO2BW-Bilanz | ||
2010,Stadt,real,57.32559262,BICO2BW-Bilanz | ||
2010,Verkehr,real,715.8740622,BICO2BW-Bilanz | ||
2011,Private Haushalte,real,615.9078358,BICO2BW-Bilanz | ||
2011,Gewerbe+Sonstiges,real,685.6976806,BICO2BW-Bilanz | ||
2011,Industrie,real,565.8099097,BICO2BW-Bilanz | ||
2011,Stadt,real,56.18431549,BICO2BW-Bilanz | ||
2011,Verkehr,real,740.1116281,BICO2BW-Bilanz | ||
2012,Private Haushalte,real,623.0563941,BICO2BW-Bilanz | ||
2012,Gewerbe+Sonstiges,real,699.9896774,BICO2BW-Bilanz | ||
2012,Industrie,real,621.3028508,BICO2BW-Bilanz | ||
2012,Stadt,real,57.30441635,BICO2BW-Bilanz | ||
2012,Verkehr,real,751.6276603,BICO2BW-Bilanz | ||
2013,Private Haushalte,real,617.9786349,BICO2BW-Bilanz | ||
2013,Gewerbe+Sonstiges,real,696.4071405,BICO2BW-Bilanz | ||
2013,Industrie,real,610.1295835,BICO2BW-Bilanz | ||
2013,Stadt,real,58.89856204,BICO2BW-Bilanz | ||
2013,Verkehr,real,718.0446757,BICO2BW-Bilanz | ||
2014,Private Haushalte,real,590.6941375,BICO2BW-Bilanz | ||
2014,Gewerbe+Sonstiges,real,669.4391353,BICO2BW-Bilanz | ||
2014,Industrie,real,596.5971585,BICO2BW-Bilanz | ||
2014,Stadt,real,55.1173043,BICO2BW-Bilanz | ||
2014,Verkehr,real,720.9729018,BICO2BW-Bilanz | ||
2015,Private Haushalte,real,572.8919902,BICO2BW-Bilanz | ||
2015,Gewerbe+Sonstiges,real,652.768532,BICO2BW-Bilanz | ||
2015,Industrie,real,551.3734595,BICO2BW-Bilanz | ||
2015,Stadt,real,53.53516003,BICO2BW-Bilanz | ||
2015,Verkehr,real,720.4470444,BICO2BW-Bilanz | ||
2016,Private Haushalte,real,565.495805,BICO2BW-Bilanz | ||
2016,Gewerbe+Sonstiges,real,625.9263231,BICO2BW-Bilanz | ||
2016,Industrie,real,529.920139,BICO2BW-Bilanz | ||
2016,Stadt,real,50.48617793,BICO2BW-Bilanz | ||
2016,Verkehr,real,737.855184,BICO2BW-Bilanz | ||
2017,Private Haushalte,real,548.5219508,BICO2BW-Bilanz | ||
2017,Gewerbe+Sonstiges,real,593.2834612,BICO2BW-Bilanz | ||
2017,Industrie,real,546.8242273,BICO2BW-Bilanz | ||
2017,Stadt,real,49.43572772,BICO2BW-Bilanz | ||
2017,Verkehr,real,740.5684128,BICO2BW-Bilanz | ||
2018,Private Haushalte,real,561.7789551,BICO2BW-Bilanz | ||
2018,Gewerbe+Sonstiges,real,589.4456169,BICO2BW-Bilanz | ||
2018,Industrie,real,491.0646023,BICO2BW-Bilanz | ||
2018,Stadt,real,52.06610186,BICO2BW-Bilanz | ||
2018,Verkehr,real,710.5163637,BICO2BW-Bilanz | ||
2019,Private Haushalte,real,548.4206526,BICO2BW-Bilanz | ||
2019,Gewerbe+Sonstiges,real,574.8490281,BICO2BW-Bilanz | ||
2019,Industrie,real,474.1086754,BICO2BW-Bilanz | ||
2019,Stadt,real,47.19236622,BICO2BW-Bilanz | ||
2019,Verkehr,real,706.5434952,BICO2BW-Bilanz | ||
` | ||
|
||
export default DATA; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as d3 from "d3"; | ||
import * as geo from "d3-geo"; | ||
import * as dsv from "d3-dsv"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import csvInput from './data'; | ||
|
||
export async function GET( | ||
req: NextRequest, | ||
): Promise<NextResponse> { | ||
let agg: { | ||
time: string; | ||
min: number; | ||
max: number; | ||
mean: number; | ||
}[] = []; | ||
|
||
const data = d3.csvParse(csvInput); | ||
|
||
return NextResponse.json({ | ||
data: data, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"use client"; | ||
import PlotFigure from "@/components/PlotFigure"; | ||
import Card from "@/components/Card"; | ||
import * as Plot from "@observablehq/plot"; | ||
import * as d3 from "d3"; | ||
import { useEffect, useMemo, useRef } from "react"; | ||
import useSWR from "swr"; | ||
|
||
const fetcher = (input: URL | RequestInfo, init?: RequestInit | undefined) => | ||
fetch(input, init).then((res) => res.json()); | ||
|
||
const CarsharingChart = () => { | ||
const containerRef = useRef(); | ||
|
||
const { data } = useSWR("api/test-data2", fetcher); | ||
|
||
const data2 = useMemo( | ||
() => | ||
data?.data | ||
?.filter((d) => d[1] === "Angemeldete Carsharing-Nutzer*") | ||
.map((d) => ({ | ||
year: d[2], | ||
value: d[3], | ||
})), | ||
[data] | ||
); | ||
|
||
useEffect(() => { | ||
if (data2) { | ||
const plot = Plot.plot({ | ||
color: { legend: true, scheme: "BuYlRd" }, | ||
marks: [Plot.lineY(data2, { x: "year", y: "value" })], | ||
}); | ||
containerRef.current.append(plot); | ||
return () => plot.remove(); | ||
} | ||
}, [data2]); | ||
|
||
return ( | ||
<Card title="Angemeldete Carsharing-Nutzer" description="Teilnehmer"> | ||
<div ref={containerRef} /> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default CarsharingChart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"use client"; | ||
import PlotFigure from "@/components/PlotFigure"; | ||
import Card from "@/components/Card"; | ||
import * as Plot from "@observablehq/plot"; | ||
import * as d3 from "d3"; | ||
import { useEffect, useMemo, useRef } from "react"; | ||
import useSWR from "swr"; | ||
|
||
const fetcher = (input: URL | RequestInfo, init?: RequestInit | undefined) => | ||
fetch(input, init).then((res) => res.json()); | ||
|
||
const EnergySectorChart = () => { | ||
const containerRef = useRef(); | ||
|
||
const { data } = useSWR("api/test-data2", fetcher); | ||
|
||
const data2 = useMemo( | ||
() => | ||
data?.data | ||
?.filter((d) => d[0] === "Energieverbrauch nach Sektoren") | ||
.map((d) => ({ | ||
year: d[2], | ||
source: d[1], | ||
value: d[3], | ||
})), | ||
[data], | ||
); | ||
|
||
useEffect(() => { | ||
if (data2) { | ||
const plot = Plot.plot({ | ||
color: { legend: true, scheme: "BuYlRd" }, | ||
marks: [ | ||
Plot.barY(data2, { x: "year", y: "value", fill: "source" }), | ||
Plot.crosshair(data2, { x: "year", y: "value" }), | ||
], | ||
}); | ||
containerRef.current.append(plot); | ||
return () => plot.remove(); | ||
} | ||
}, [data2]); | ||
|
||
return ( | ||
<Card title="Energieverbrauch nach Sektoren" description="Einheit GWh"> | ||
<div ref={containerRef} /> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default EnergySectorChart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"use client"; | ||
|
||
import { useEffect, useRef } from "react"; | ||
import * as Plot from "@observablehq/plot"; | ||
import * as d3 from "d3"; | ||
import { useData4 } from "@/app/data"; | ||
import Card from "./Card"; | ||
|
||
const GreenhouseGasesChart: React.FC = () => { | ||
const { data, isError, isLoading } = useData4(); | ||
|
||
const containerRef = useRef(); | ||
|
||
useEffect(() => { | ||
if (isLoading || !data) return; | ||
|
||
const betterData = data.data.map(({ co2, ...x }) => ({ | ||
co2: parseInt(co2), | ||
...x, | ||
})); | ||
|
||
const plot = Plot.plot({ | ||
color: { legend: true }, | ||
marks: [ | ||
Plot.rectY(betterData, { | ||
x: "year", | ||
y: "co2", | ||
fill: "category", | ||
}), | ||
Plot.crosshair(betterData, { x: "year", y: "co2" }), | ||
], | ||
}); | ||
|
||
containerRef.current.append(plot); | ||
return () => plot.remove(); | ||
}, [isLoading, data]); | ||
|
||
return ( | ||
<Card | ||
title="Treibhaus Gase" | ||
description="Treibhaus Gase von verschiedenen Quellen in den letzten Jahren" | ||
> | ||
<div ref={containerRef} /> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default GreenhouseGasesChart; |
Oops, something went wrong.