Published
Edited
Oct 22, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// splitgraph doesn't yet contain latest data
data = splitgraph`SELECT COALESCE(
CASE
WHEN biome = ANY('{"CHACO HUMEDO", "CHACO SECO"}') THEN 'CHACO'
WHEN biome = 'AMAZONIA' THEN 'AMAZON'
WHEN biome = 'MATA ATLANTICA' THEN 'ATLANTIC FOREST'
WHEN biome = ANY('{"DELTA E ISLAS DEL PARANA", "ESPINAL", "MONTE DE LLANURAS Y MESETAS", "YUNGAS"}') THEN 'OTHER'
WHEN biome = 'CAATINGA' THEN 'CERRADO'
ELSE biome END, country_of_production
) AS key1,
CASE
WHEN deforestation_commitments IS NULL THEN 'Not assessed'
WHEN deforestation_commitments && '{"NONE", "None", "No"}' THEN 'No ZDC'
ELSE 'ZDC' END AS key2,
SUM(${indicator}) AS value
FROM "trase/supply-chains"."supply-chains"
WHERE true
AND commodity = '${commodity.toUpperCase()}'
${commodity === "Palm oil" ? `AND country_of_production = 'INDONESIA'` : ``}
${
commodity === "Cocoa"
? `AND country_of_production = ANY('{"GHANA", "COTE D''IVOIRE"}')`
: ``
}
AND economic_bloc = 'EUROPEAN UNION'
AND country_of_production != 'GHANA'
AND year = ${year}
GROUP BY key1, key2`.then((res) =>
res
.map((d) => ({ ...d, key1: titleCase(d.key1), key2: d.key2 }))
.filter((d) =>
commodity === "Soy" && year === 2018 ? d.value > 200 : true
)
)
Insert cell
margin = ({top: 30, right: 20, bottom: 20, left: 140})
Insert cell
colour = d3.scaleOrdinal()
.domain(["Not assessed", "ZDC", "No ZDC"])
.range(["#e3ebe8", "#8ba194", "#ff6a5f"])
Insert cell
annotate = g => g.attr("transform", `translate(${margin.left}, 0)`).append(() => legend)
Insert cell
import { titleCase } from "@trase/visual-id@1375"
Insert cell
import { chart, legend } with { data, colour, margin, annotate } from "@trase/stacked-horizontal-bar-chart@921"
Insert cell
import { select, slider } from "@jashkenas/inputs"
Insert cell
// import { splitgraph } from "@trase/splitgraph"
Insert cell
// client = DatabaseClient("trase-master")
Insert cell
d3 = require("d3-scale@1")
Insert cell
import { splitgraph } from "@trase/splitgraph"
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