yashmurty_obsidian-people-g.../src/graph/GraphView.ts
yashmurty 5c7c0bef20 Fix Obsidian review issues and ship fully free
- Bump minAppVersion to 1.7.2 (covers addAction/revealLeaf) + add versions.json
- Obsidian API hygiene: createEl/createDiv, typed d3 callbacks, drop builtin-modules
- Add release workflow with GitHub artifact attestation
- Remove node-count gate and all Pro/Locked/Upgrade wording
- Bump version to 0.1.2
2026-05-31 21:50:34 +09:00

67 lines
1.8 KiB
TypeScript

import { ItemView, Notice, WorkspaceLeaf } from "obsidian";
import type PeopleGraphPlugin from "../main";
import { indexPeople } from "../indexer";
import { renderGraph } from "./renderer";
import { exportGraphAsPng } from "./export";
export const VIEW_TYPE_PEOPLE_GRAPH = "people-graph-view";
export class PeopleGraphView extends ItemView {
plugin: PeopleGraphPlugin;
constructor(leaf: WorkspaceLeaf, plugin: PeopleGraphPlugin) {
super(leaf);
this.plugin = plugin;
}
getViewType(): string {
return VIEW_TYPE_PEOPLE_GRAPH;
}
getDisplayText(): string {
return "People graph";
}
getIcon(): string {
return "users";
}
async onOpen(): Promise<void> {
await this.render();
// Export button in view header
this.addAction("download", "Export as PNG", async () => {
const container = this.containerEl.children[1] as HTMLElement;
const blob = await exportGraphAsPng(container);
if (!blob) {
new Notice("Export failed — no graph to export.");
return;
}
const url = URL.createObjectURL(blob);
const a = createEl("a", { href: url });
a.download = "people-graph.png";
a.click();
URL.revokeObjectURL(url);
new Notice("Graph exported as PNG.");
});
// Re-render when a note's frontmatter changes
this.registerEvent(
this.app.metadataCache.on("changed", () => {
void this.render();
}),
);
}
async render(): Promise<void> {
const container = this.containerEl.children[1] as HTMLElement;
const people = await indexPeople(this.app, this.plugin.settings);
renderGraph(container, people, this.plugin.settings, this.app);
}
// eslint-disable-next-line @typescript-eslint/require-await -- Obsidian API requires async signature
async onClose(): Promise<void> {
const container = this.containerEl.children[1] as HTMLElement;
container.empty();
}
}