Published
Edited
Jul 5, 2020
1 fork
2 stars
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
data = {
let goodies = {};
const rowConversionFunction = ({
"Name": name,
"Top Goodie 1": goodie1,
"Top Goodie 2": goodie2,
"Top Goodie 3": goodie3
}) => {
goodies[goodie1] = true;
goodies[goodie2] = true;
goodies[goodie3] = true;
return {
name,
goodies: [goodie1, goodie2, goodie3]
}};
let dataObjectTarget = await d3.tsvParse(tsv, rowConversionFunction);
delete goodies[''];
const goodiesList = Object.keys(goodies);
dataObjectTarget.map(d => {
for (let i = 0; i < goodiesList.length; i++) {
const goodie = goodiesList[i];
let goodieRank = d.goodies.indexOf(goodie) + 1;
// Invert 1 & 3 position for ascending color scale 0–3
// if (goodieRank === 1) { goodieRank = 3; }
// else if (goodieRank === 3) { goodieRank = 1; }
d[goodie] = goodieRank;
}
return d;
});
const extraPropertiesSource = {
xAxisLabel: "Goodies",
yAxisLabel: "Cats",
goodies: goodiesList,
observation: "",
title: "The number of times cats have used each goodie. ",
};
return Object.assign(dataObjectTarget, extraPropertiesSource);
}
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