47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
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 });
|
|
}
|
|
|
|
*search(q) {
|
|
const re = new RegExp(q, "i");
|
|
for (let n of this.nodes) {
|
|
if (re.test(n.name)) {
|
|
yield n;
|
|
}
|
|
}
|
|
}
|
|
}
|