async function elementsFromDataset(ds) {
const raw = await fetch(ds.file).then(r => r.text());
const csv = d3.dsvFormat(ds.separator).parseRows(raw);
const set = { start: ds.sets[0].start, end: ds.sets[0].end };
const idColumnIndex = ds.meta.find(d => d.type === 'id')
? ds.meta.find(d => d.type === 'id').index
: 0;
const [header, ...data] = csv;
const setNames = header.slice(set.start, set.end);
return data.map(row => {
const sets = row
.slice(set.start, set.end)
.map((v, i) => [v, setNames[i]])
.filter(([v, _]) => v === "1")
.map(([_, s]) => s);
return {
name: row[idColumnIndex],
sets
};
});
}