experiments-d3/ideaweb/graph.mjs

47 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2024-10-14 06:10:17 +00:00
export default class Graph {
constructor() {
this.Default = 0x01;
this.KindCategory = 0x02;
this.KindProject = 0x04;
this.InboxId = 1;
this.nodes = [
{ id: this.InboxId, name: "INBOX", kind: this.KindCategory },
{ id: 2000, name: "UChicago", kind: this.KindCategory },
{ id: 2100, name: "51042", kind: this.KindProject },
{ id: 2400, name: "30239", kind: this.KindProject },
{ id: 2410, name: "D3", kind: this.Default },
{ id: 2420, name: "Altair", kind: this.Default },
];
this.links = [
{ source: 2000, target: 2100 },
{ source: 2000, target: 2400 },
{ source: 2400, target: 2410 },
{ source: 2400, target: 2420 },
];
}
insert(name, kind = "default") {
// todo: fix id
let id = Math.floor(Math.random() * 20000000000);
this.nodes.push({
id: id,
name,
kind: "default",
});
return id;
}
addLink(source, target) {
this.links.push({ source, target });
}
2024-10-14 06:47:07 +00:00
*search(q) {
const re = new RegExp(q, "i");
for (let n of this.nodes) {
if (re.test(n.name)) {
yield n;
}
}
}
2024-10-14 06:10:17 +00:00
}