Public
Edited
Sep 13, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chartData = {
let inputVars = [inputClassification, filterVariable].sort((a, b) =>
a.localeCompare(b)
);
const url = URL_PATTERN.replace(
"DIMENSIONS",
inputVars.join("-") + "-" + outputClassification
);
let rawData = await d3.json(url);

let result = [];
for (let obs of rawData.observations) {
if (obs.dims[filterVariable] != filterCategory) {
continue;
}
if (Object.values(obs.dims).includes("-8")) {
continue;
}
result.push({
cat1Name: allClassifications[inputClassification].categoryMap.get(
obs.dims[inputClassification]
),
cat2Name: allClassifications[outputClassification].categoryMap.get(
obs.dims[outputClassification]
),
value: obs.count
});
}
return result;
}
Insert cell
URL_PATTERN = "https://raw.githubusercontent.com/jtrim-ons/key-pop-data-for-marimekko/main/results/DIMENSIONS.json"
Insert cell
inputClassifications = FileAttachment("input-classifications.json").json()
Insert cell
outputClassifications = FileAttachment("output-classifications.json").json()
Insert cell
allClassifications = {
let result = await FileAttachment("all-classifications.json").json();
for (let v in result) {
result[v].categoryMap = new Map(
result[v].categories.map((d) => [d.id, d.label])
);
}
return result;
}
Insert cell
censusData = FileAttachment("census-data.json").json()
Insert cell
outputClassificationsDetails = FileAttachment(
"output-classification-details-dict.json"
).json()
Insert cell
import { Legend, Swatches } from "@d3/color-legend"
Insert cell
import { wrap } from "@jtrim-ons/svg-text-wrapping"
Insert cell
labelplacer = import("labelplacer@0.0.0")
Insert cell
leaderlines = import("leaderlines@0.0.1")
Insert cell
rectOpacity = 0.5
Insert cell
htl.html`
<style>
.legend-swatch {
width: 15px;
height: 15px;
margin-right: 0.5em;
flex-shrink: 0;
opacity: ${rectOpacity};
}
.legend-item {
font: 12px sans-serif;
display: flex;
align-items: center;
}
.legend {
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-column-gap: 5px;
grid-row-gap: 5px;
}
</style>
`
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