Skip to content

Commit bf4477e

Browse files
committed
0.1.0
1 parent d4ceafa commit bf4477e

19 files changed

+110
-144
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "time-tree",
33
"name": "Time Tree",
4-
"version": "0.0.3",
4+
"version": "0.1.0",
55
"minAppVersion": "0.15.0",
66
"description": "Track accumulated time spent on unlimited hierarchical tasks",
77
"author": "Lucas Lopes",

src/front-matter-manager.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,20 @@ export class FrontMatterManager {
88
this.app = app;
99
}
1010

11-
async getProperty(
12-
file: TFile,
13-
property: string
14-
): Promise<number | undefined> {
11+
async getProperty(file: TFile, property: string): Promise<number> {
12+
let propertyValue = 0;
1513
try {
1614
const content = await this.app.vault.read(file);
1715
const yamlRegex = /^---\n([\s\S]*?)\n---/;
1816
const yamlMatch = content.match(yamlRegex);
1917
if (yamlMatch) {
2018
const frontmatter = YAML.parse(yamlMatch[1]) || {};
21-
return frontmatter[property];
22-
} else {
23-
return undefined;
19+
propertyValue = (frontmatter[property] || 0) as number;
2420
}
2521
} catch (err) {
2622
console.error("Error reading file:", file.path, err);
27-
return undefined;
2823
}
24+
return propertyValue;
2925
}
3026

3127
async updateProperty(

src/main.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,22 @@ export default class TimeTreePlugin extends Plugin {
8080
async computeTimeTree(): Promise<void> {
8181
const rootPath = this.settings.rootNotePath;
8282
if (!rootPath) {
83-
new Notice("Root note path is not configured in settings.");
83+
new Notice(
84+
"Root note path is not configured in Time Tree settings."
85+
);
8486
return;
8587
}
8688
const rootFile = this.app.vault.getAbstractFileByPath(rootPath);
8789
if (!rootFile || !(rootFile instanceof TFile)) {
88-
new Notice("Root note file not found.");
90+
new Notice(`Root note ${rootPath} not found.`);
8991
return;
9092
}
91-
const localElapsed =
92-
await this.calculator.calculateRecursiveElapsedTime(rootFile);
93-
new Notice(`Updated recursive elapsed time: ${localElapsed}`);
94-
const totalElapsedChild =
95-
await this.calculator.calculateRecursiveElapsedChild(rootFile);
96-
const ownElapsed =
97-
(await this.frontMatterManager.getProperty(rootFile, "elapsed")) ||
98-
0;
93+
await this.calculator.calculateRecursiveElapsedTime(rootFile);
94+
await this.calculator.calculateRecursiveElapsedChild(rootFile);
95+
await this.calculator.updateNodeSizeFromFile(rootFile);
9996
new Notice(
100-
`Updated elapsed_child for root note: ${
101-
totalElapsedChild - ownElapsed
102-
}`
97+
`Time Tree computed recursively from root note: ${rootPath}`
10398
);
104-
await this.calculator.updateNodeSizeFromFile(rootFile);
10599
}
106100

107101
async insertNewTask(editor: Editor): Promise<void> {

src/time-tree-calculator.ts

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ export class TimeTreeCalculator {
6161

6262
async calculateRecursiveElapsedChild(
6363
file: TFile,
64-
recursive: boolean = true,
65-
includeOwn: boolean = true
64+
recursive: boolean = true
6665
): Promise<number> {
67-
const content = await this.app.vault.read(file);
68-
const yamlRegex = /^---\n([\s\S]*?)\n---/;
69-
const yamlMatch = content.match(yamlRegex);
70-
let frontmatter = yamlMatch ? YAML.parse(yamlMatch[1]) || {} : {};
71-
const ownElapsed = frontmatter.elapsed || 0;
66+
const ownElapsed = await this.frontMatterManager.getProperty(
67+
file,
68+
"elapsed"
69+
);
7270
const fileCache = this.app.metadataCache.getFileCache(file);
73-
if (!fileCache || !fileCache.links || fileCache.links.length === 0) {
71+
const childNotes = (fileCache as any).links;
72+
const leafNote = !fileCache || !childNotes || childNotes.length === 0;
73+
if (leafNote) {
7474
const properties =
7575
ownElapsed === 0
7676
? ["elapsed", "elapsed_child"]
@@ -84,7 +84,7 @@ export class TimeTreeCalculator {
8484
return ownElapsed;
8585
}
8686
let totalDescendantElapsed = 0;
87-
for (const link of fileCache.links) {
87+
for (const link of childNotes) {
8888
const childFile = this.app.metadataCache.getFirstLinkpathDest(
8989
link.link,
9090
file.path
@@ -97,15 +97,15 @@ export class TimeTreeCalculator {
9797
);
9898
} else {
9999
const childElapsed =
100-
(await this.frontMatterManager.getProperty(
100+
await this.frontMatterManager.getProperty(
101101
childFile,
102102
"elapsed"
103-
)) || 0;
103+
);
104104
const childElapsedChilds =
105-
(await this.frontMatterManager.getProperty(
105+
await this.frontMatterManager.getProperty(
106106
childFile,
107107
"elapsed_child"
108-
)) || 0;
108+
);
109109
childTotal = childElapsed + childElapsedChilds;
110110
}
111111
totalDescendantElapsed += childTotal;
@@ -115,21 +115,13 @@ export class TimeTreeCalculator {
115115
fm.elapsed_child = totalDescendantElapsed;
116116
return fm;
117117
});
118-
const total = includeOwn
119-
? ownElapsed + totalDescendantElapsed
120-
: totalDescendantElapsed;
121-
return total;
118+
return ownElapsed + totalDescendantElapsed;
122119
}
123120

124121
async communicateAscendants(file: TFile): Promise<void> {
125122
const parent = await this.getParentFile(file);
126123
if (parent) {
127-
const parentElapsedChild =
128-
await this.calculateRecursiveElapsedChild(parent, false, false);
129-
await this.frontMatterManager.updateProperty(parent, (fm) => {
130-
fm.elapsed_child = parentElapsedChild;
131-
return fm;
132-
});
124+
await this.calculateRecursiveElapsedChild(parent, false);
133125
await this.communicateAscendants(parent);
134126
}
135127
return;
@@ -226,14 +218,14 @@ export class TimeTreeCalculator {
226218
const files = [file, ...descendantFiles];
227219
const accValues: { file: TFile; acc: number }[] = [];
228220
for (const file of files) {
229-
const elapsed =
230-
(await this.frontMatterManager.getProperty(file, "elapsed")) ||
231-
0;
232-
const elapsedChild =
233-
(await this.frontMatterManager.getProperty(
234-
file,
235-
"elapsed_child"
236-
)) || 0;
221+
const elapsed = await this.frontMatterManager.getProperty(
222+
file,
223+
"elapsed"
224+
);
225+
const elapsedChild = await this.frontMatterManager.getProperty(
226+
file,
227+
"elapsed_child"
228+
);
237229
const acc = elapsed + elapsedChild;
238230
accValues.push({ file, acc });
239231
}
@@ -257,7 +249,8 @@ export class TimeTreeCalculator {
257249
await this.frontMatterManager.updateProperty(
258250
file,
259251
(frontmatter) => {
260-
frontmatter.node_size = node_size;
252+
frontmatter.node_size =
253+
typeof node_size === "number" ? node_size : min_d;
261254
return frontmatter;
262255
}
263256
);

test-vault/.obsidian/graph.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"repelStrength": 20,
1818
"linkStrength": 1,
1919
"linkDistance": 30,
20-
"scale": 1.1370046269920902,
20+
"scale": 0.8914715268792589,
2121
"close": true
2222
}

test-vault/.obsidian/plugins/time-tree/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "time-tree",
33
"name": "Time Tree",
4-
"version": "0.0.3",
4+
"version": "0.1.0",
55
"minAppVersion": "0.15.0",
66
"description": "Track accumulated time spent on unlimited hierarchical tasks",
77
"author": "Lucas Lopes",

test-vault/.obsidian/types.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"types": {
3+
"aliases": "aliases",
4+
"cssclasses": "multitext",
5+
"tags": "tags",
6+
"node_size": "number"
7+
}
8+
}

test-vault/.obsidian/workspace.json

Lines changed: 13 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4,77 +4,17 @@
44
"type": "split",
55
"children": [
66
{
7-
"id": "887876fb0dd51f6d",
7+
"id": "fc8e044642d6de25",
88
"type": "tabs",
99
"children": [
1010
{
11-
"id": "98225c0495a73a21",
11+
"id": "77b1a0575995a7eb",
1212
"type": "leaf",
1313
"state": {
14-
"type": "markdown",
15-
"state": {
16-
"file": "Tasks/level-2b-b.md",
17-
"mode": "source",
18-
"source": false
19-
},
20-
"icon": "lucide-file",
21-
"title": "level-2b-b"
22-
}
23-
},
24-
{
25-
"id": "02df6f495f450d89",
26-
"type": "leaf",
27-
"state": {
28-
"type": "markdown",
29-
"state": {
30-
"file": "Tasks/level-1-a.md",
31-
"mode": "source",
32-
"source": false
33-
},
34-
"icon": "lucide-file",
35-
"title": "level-1-a"
36-
}
37-
},
38-
{
39-
"id": "de8fc0ab48970012",
40-
"type": "leaf",
41-
"state": {
42-
"type": "markdown",
43-
"state": {
44-
"file": "Tasks/level-2a-c.md",
45-
"mode": "source",
46-
"source": false
47-
},
48-
"icon": "lucide-file",
49-
"title": "level-2a-c"
50-
}
51-
},
52-
{
53-
"id": "ff2267fa21c84338",
54-
"type": "leaf",
55-
"state": {
56-
"type": "markdown",
57-
"state": {
58-
"file": "Tasks/level-2c-b.md",
59-
"mode": "source",
60-
"source": false
61-
},
62-
"icon": "lucide-file",
63-
"title": "level-2c-b"
64-
}
65-
},
66-
{
67-
"id": "de41113eb066ad63",
68-
"type": "leaf",
69-
"state": {
70-
"type": "markdown",
71-
"state": {
72-
"file": "Tasks/level-2b-b.md",
73-
"mode": "source",
74-
"source": false
75-
},
76-
"icon": "lucide-file",
77-
"title": "level-2b-b"
14+
"type": "graph",
15+
"state": {},
16+
"icon": "lucide-git-fork",
17+
"title": "Graph view"
7818
}
7919
}
8020
]
@@ -221,24 +161,25 @@
221161
"command-palette:Open command palette": false
222162
}
223163
},
224-
"active": "98225c0495a73a21",
164+
"active": "77b1a0575995a7eb",
225165
"lastOpenFiles": [
166+
"Tasks/level-2b-b.md",
167+
"Tasks/sub/newer-task.md",
168+
"Tasks/level-2c-b.md",
226169
"Tasks/level-1-b.md",
170+
"Tasks/level-2b-c.md",
171+
"Tasks/level-1-c.md",
172+
"Tasks/level-2a-b.md",
227173
"Tasks/level-2a-c.md",
228174
"Tasks/level-1-a.md",
229-
"Tasks/level-1-c.md",
230-
"Tasks/level-2c-b.md",
231-
"Tasks/level-2b-b.md",
232175
"Tasks/level-2b-a.md",
233-
"Tasks/level-2b-c.md",
234176
"ref.md",
235177
"Tasks/root.md",
236178
"Tasks/level-2c-c.md",
237179
"Root/sub",
238180
"Root",
239181
"Tasks/level-2c-a.md",
240182
"Tasks/level-2a-a.md",
241-
"Tasks/level-2a-b.md",
242183
"level-1-b-1.md",
243184
"level-1-c-1.md",
244185
"level-1-a-1.md"

test-vault/Tasks/level-1-a.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
elapsed_child: 27136
2+
elapsed_child: 31269
33
elapsed: 0
4-
node_size: 38.59456913683125
4+
node_size: 24.631335951869662
55
---
66
# [[level-2a-a]]
77
# [[level-2a-b]]

test-vault/Tasks/level-1-b.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
elapsed_child: 58709
2+
elapsed_child: 351374
33
elapsed: 0
4-
node_size: 60.46422964306069
4+
node_size: 88.44544546060624
55
---
66
# [[level-2b-a]]
77
# [[level-2b-b]]

0 commit comments

Comments
 (0)