MCPcopy Create free account
hub / github.com/callumalpass/tasknotes / renderProgressCircle

Method renderProgressCircle

src/views/StatsView.ts:1338–1392  ·  view source on GitHub ↗
(
		container: HTMLElement,
		percentage: number,
		completed: number,
		total: number
	)

Source from the content-addressed store, hash-verified

1336 }
1337
1338 private renderProgressCircle(
1339 container: HTMLElement,
1340 percentage: number,
1341 completed: number,
1342 total: number
1343 ) {
1344 const size = 60;
1345 const strokeWidth = 5;
1346 const radius = (size - strokeWidth) / 2;
1347 const circumference = 2 * Math.PI * radius;
1348 const offset = circumference - (percentage / 100) * circumference;
1349
1350 const svg = activeDocument.createElementNS("http://www.w3.org/2000/svg", "svg");
1351 svg.setAttribute("width", size.toString());
1352 svg.setAttribute("height", size.toString());
1353 svg.setAttribute("viewBox", `0 0 ${size} ${size}`);
1354 svg.classList.add("stats-view__progress-circle-svg");
1355
1356 const backgroundCircle = activeDocument.createElementNS(
1357 "http://www.w3.org/2000/svg",
1358 "circle"
1359 );
1360 backgroundCircle.setAttribute("cx", (size / 2).toString());
1361 backgroundCircle.setAttribute("cy", (size / 2).toString());
1362 backgroundCircle.setAttribute("r", radius.toString());
1363 backgroundCircle.classList.add("stats-view__progress-circle-bg");
1364
1365 const foregroundCircle = activeDocument.createElementNS(
1366 "http://www.w3.org/2000/svg",
1367 "circle"
1368 );
1369 foregroundCircle.setAttribute("cx", (size / 2).toString());
1370 foregroundCircle.setAttribute("cy", (size / 2).toString());
1371 foregroundCircle.setAttribute("r", radius.toString());
1372 foregroundCircle.setAttribute("stroke-dasharray", `${circumference} ${circumference}`);
1373 foregroundCircle.setAttribute("stroke-dashoffset", offset.toString());
1374 foregroundCircle.classList.add("stats-view__progress-circle-fg");
1375
1376 const text = activeDocument.createElementNS("http://www.w3.org/2000/svg", "text");
1377 text.setAttribute("x", "50%");
1378 text.setAttribute("y", "50%");
1379 text.setAttribute("dy", "0.3em");
1380 text.setAttribute("text-anchor", "middle");
1381 text.classList.add("stats-view__progress-circle-text");
1382 text.textContent = `${Math.round(percentage)}%`;
1383
1384 svg.appendChild(backgroundCircle);
1385 svg.appendChild(foregroundCircle);
1386 svg.appendChild(text);
1387
1388 container.appendChild(svg);
1389
1390 const label = container.createDiv({ cls: "stats-view__progress-label" });
1391 label.textContent = `${completed}/${total} tasks`;
1392 }
1393
1394 /**
1395 * Calculate trend data for a project over the last 30 days

Callers 1

renderProjectStatsMethod · 0.95

Calls 1

toStringMethod · 0.65

Tested by

no test coverage detected