Public
Edited
Jun 3, 2024
2 forks
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
emissions = emissionsDataset
.map((d) => {
d.year = parseInt(d.year);
d.total_ghg = parseFloat(d.total_ghg);
return d;
})
.filter(
(d) =>
d.year >= 1990 &&
(ue_countries.indexOf(d.country) !== -1 || d.country == 'European Union (27)') && d.country != 'Romania' && d.country != 'Finland' &&
!isNaN(d.total_ghg)
);
Insert cell
Insert cell
Insert cell
emissions_ext = {
const dataZ = [];
emissions.forEach((d, i) => {
const baseYearGhg = emissions.find((d) => d.country == emissions[i].country && d.year == 1990).total_ghg;
dataZ.push(
{
...d,
diff_from_base: Math.round(((percentageDecrease(baseYearGhg, d.total_ghg)) + Number.EPSILON) * 100) / 100
}
)
});
return dataZ;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Afegir ordre aquí si es vol ordenar el Heatmap

enhancedSortedEmissionsByCountry = {
const dataCountries = new Map();
var countryIdx = 0;
sortedEmissionsByCountry.forEach((countryData, key, map) => {
const dataYears = [];
countryData.forEach((yearData, index) => {
const ghgPercentageDecrease = index == 0 ? 0 : Math.round(
(percentageDecrease(
map.get(key)[index - 1].total_ghg,
yearData.total_ghg
) +
Number.EPSILON) *
100
) / 100;
dataYears.push({
index,
country_idx: countryIdx, //isoCodes.indexOf(yearData.iso_code)
iso_code: yearData.iso_code,
year: yearData.year,
total_ghg: yearData.total_ghg, // Emissions de ghg totals
difference_from_base: yearData.diff_from_base, // Diferència amb l'any 1990
yearly_change: ghgPercentageDecrease, // Diferència amb l'any anterior
ghg_increased: ghgPercentageDecrease >= 0 ? false : true,
ghg_per_capita: parseFloat(yearData.ghg_per_capita)
});
});
dataYears.push()
dataCountries.set(key, dataYears);
countryIdx += 1;
});
return dataCountries;
}
Insert cell
Insert cell
heatMapValuesStruct = {
const struct = [];
enhancedSortedEmissionsByCountry.forEach((countryData, key, map) => {
// year, i, improvementValue, diffValue, ghg
const countryArray = [];
countryData.forEach((yearData, index) => {
countryArray.push({
year: yearData.year,
yearly_change: yearData.yearly_change,
diff_from_base: yearData.difference_from_base,
total_ghg: yearData.total_ghg,
ghg_per_capita: yearData.ghg_per_capita
})
})
struct.push(countryArray);
});

return struct;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function getMinMaxValues(countryIdx) {
var minVal = 0;
var maxVal = 0;
if (countryIdx === undefined) { // A nivell global
maxVal = d3.max(heatMapValuesStruct, (d, i) => d3.max(heatMapValuesStruct[i], (d) => d[heatmapChosenData]));
minVal = d3.min(heatMapValuesStruct, (d, i) => d3.min(heatMapValuesStruct[i], (d) => d[heatmapChosenData]));
}
else { // A nivell de país
maxVal = d3.max(heatMapValuesStruct[countryIdx], (d) => d[heatmapChosenData]);
minVal = d3.min(heatMapValuesStruct[countryIdx], (d) => d[heatmapChosenData]);
}

return {min: minVal, max: maxVal};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function getLollipopRadius(year) {
if (year == 1998 || year == 2005 || year == 2008 || year == 2013) {
return 24;
}
else {
return 4;
}
}
Insert cell
function getLollipopColor(year) {
if (year == 1998 || year == 2005 || year == 2008 || year == 2013) {
return "rgb(243, 105, 163)";
}
else {
return "black";
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data1
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
data_UE_World = {
const countriesInData4 = data2.map(item => item.country);

const filteredData4 = emissionsDataset .filter(item => countriesInData4.includes(item.country));

return filteredData4;
}

Insert cell
data_UE_World
select country,year,sum(co2) from data_UE_World
group by country,year
Insert cell
data_UE = {
const countriesInData2 = data2.map(item => item.country);

const filteredData = emissions.filter(item => countriesInData2.includes(item.country));
console.log(filteredData);

return filteredData;
}
Insert cell
data_UE
SELECT
YEAR,
COUNTRY,
CO2,
CO2_1990::DOUBLE AS CO2_1990,
CO2_1990*0.95 AS REDUCTION_CO2_1990
FROM
(SELECT
year,
country,
co2::DOUBLE AS CO2,
(SELECT co2::double FROM data_UE t2 WHERE t2.country = t1.country AND t2.year = 1990) AS co2_1990
FROM
data_UE t1
where co2 <> '')

--WHERE country = 'Austria'
Insert cell
kioto_UE
Insert cell
CO2_1990 = data_UE.filter(d => d.year === "1990")
.map((d) => {
return {
country: d.country,
co2_1990: d.co2,
reduction_co2_1990: d.co2 * 0.95
}
});

Insert cell
kioto_UE_2 = {
const dataZ = [];
kioto_UE
.forEach((yearData) => {
const year = parseInt(yearData.year);
const quinquennium = year + (5 - year % 5);
dataZ.push({
country: yearData.country,
year: year,
quinquennium: quinquennium,
co2: yearData.CO2,
co2_1990: yearData.CO2_1990,
red_co2_1990: yearData.REDUCTION_CO2_1990
});
});
return dataZ;
}
Insert cell
countries_data = d3.group(kioto_UE_2, d => d.country)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more