-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap-view.ts
More file actions
65 lines (54 loc) · 1.78 KB
/
Copy pathmap-view.ts
File metadata and controls
65 lines (54 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { BasesView } from 'obsidian';
import { renderMapSVGFromEntries, MapOptions } from './map-visualization';
import type InputViewPlugin from './main';
export const MAP_VIEW_TYPE = 'relative-map-view';
export class MapBasesView extends BasesView {
readonly type = MAP_VIEW_TYPE;
private containerEl: HTMLElement;
private plugin: InputViewPlugin;
constructor(controller: any, parentEl: HTMLElement, plugin: InputViewPlugin) {
super(controller);
this.containerEl = parentEl.createDiv('map-view-container');
this.plugin = plugin;
}
public onOpen(): void {
this.containerEl.empty();
this.containerEl.createDiv({ text: 'Loading map…' });
}
public onClose(): void {
this.containerEl.empty();
}
public onDataUpdated(): void {
const data = this.data;
const app = this.app;
this.containerEl.empty();
if (!data) {
this.containerEl.createDiv({ text: 'No data available.' });
return;
}
const entries: any[] = (data as any)?.data;
if (!entries || !entries.length) {
this.containerEl.createDiv({ text: 'No files in this base.' });
return;
}
const s = this.plugin.settings;
const mapOptions: MapOptions = {
width: 1024,
height: 768,
defaultEdgeLengthRel: s.defaultEdgeLengthRel,
iterations: s.iterations,
stiffness: s.stiffness,
damping: s.damping,
distancesKeys: s.distancesKeys,
sizeKey: s.sizeKey,
colorKey: s.colorKey,
typeKey: s.typeKey,
nameKey: s.nameKey,
resolveLinks: s.resolveLinks,
normalizeAbsoluteLengths: s.normalizeAbsoluteLengths,
};
const svg = renderMapSVGFromEntries(app, entries, mapOptions);
const wrapper = this.containerEl.createDiv({ cls: 'map-view-svg-wrapper' });
wrapper.appendChild(svg);
}
}