Public
Edited
Jun 6, 2023
Insert cell
Insert cell
csv = FileAttachment("heart_dataset@2.csv")
.csv()
Insert cell
data = csv.map((d, i) => ({ ...d, id: i }))
Insert cell
Insert cell
Insert cell
group_data = data.reduce((groups, obj) => {
const algo = obj.algo;
const line_step = parseInt(obj.line_step);

if (!groups[algo]) { // group by algo first
groups[algo] = {};
}

//then group the first point of every line, 2nd group of every line, ...
if (!groups[algo][line_step]) { // use line_step as array accessor
groups[algo][line_step] = [];
}

groups[algo][line_step].push(obj.id);

return groups;
}, {});
Insert cell
label_grouped_data = Object.values(group_data).map((g, i) => {
const algoLabel = "" + i + "-";
const prefixed = Object.entries(g).reduce((result, [key, value]) => {
const prefixedKey = algoLabel + key;
result[prefixedKey] = value;
return result;
}, {});
return prefixed;
})
Insert cell
flat_group_data = label_grouped_data
.flatMap(obj => Object.entries(obj))
.map((g,i) => [i, g[1], g[0]])
Insert cell
pse = ({
samples: [{ // the data
columns: ['line', 'x', 'y', 'algo'], // attributes of the items
index: data.map((d) => d.id), //ids of the items
data: data.map((d) => ([ // remaining data of the items
parseInt(d.line),
parseFloat(d.x),
parseFloat(d.y),
parseInt(d.algo)
]))
}],
preselection: [ // ??
{
columns: [
"preselect"
],
index: [],
data: []
}
],
clusters: [{ // predefined groups
columns: ['id', 'items', 'name'], // attributes of the groups
index: flat_group_data.map(g => g[0]), // index for each created group
data: flat_group_data
}],
edges: [{
columns: [
"id",
"source",
"destination",
"name"
],
index: [],
data: []
}
]
})
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more