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;
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);
}