2.7 KiB
2.7 KiB
// This entire block is now DataviewJS. It will build its own HTML.
// --- 1. Create the main Flexbox Container ---
// We get the current container for this code block and turn it into a flex container.
const container = dv.container;
container.style.display = "flex";
container.style.alignItems = "flex-start";
container.style.gap = "20px";
// --- 2. Create the Left and Right Columns ---
const leftColumn = container.createEl("div");
leftColumn.style.flex = "1"; // Let the column grow and shrink
const rightColumn = container.createEl("div");
rightColumn.style.flex = "1";
rightColumn.style.maxWidth = "450px"; // Constrain the chart size
// --- 3. Gather Data (once for both columns) ---
const pages = dv.pages("#project");
// --- 4. Populate the Left Column (Stats) ---
leftColumn.createEl("h3", { text: "Operational Summary" });
leftColumn.createEl("hr");
const activeProjects = pages.where(p => p.status === "In Progress").length;
const completedMissions = pages.where(p => p.status === "Completed").length;
const onHoldProjects = pages.where(p => p.status === "On Hold").length;
const planningProjects = pages.where(p => p.status === "In Planning").length;
leftColumn.createEl("p", { text: `Active Projects: ${activeProjects}` });
leftColumn.createEl("p", { text: `Completed Missions: ${completedMissions}` });
leftColumn.createEl("p", { text: `On Hold: ${onHoldProjects}` });
leftColumn.createEl("p", { text: `In Planning: ${planningProjects}` });
// --- 5. Populate the Right Column (Chart) ---
const groupedByStatus = pages.groupBy(p => p.status);
const chartLabels = groupedByStatus.map(group => group.key).array();
const chartData = groupedByStatus.map(group => group.rows.length).array();
const chartConfig = {
type: 'pie',
data: {
labels: chartLabels,
datasets: [{
data: chartData,
backgroundColor: [
"rgba(75, 192, 192, 0.7)",
"rgba(54, 162, 235, 0.7)",
"rgba(255, 206, 86, 0.7)",
"rgba(255, 99, 132, 0.7)"
]
}]
},
options: {
title: {
display: true,
text: 'Project Status Overview'
}
}
};
// Create a new canvas element inside the right column and render the chart into it.
const chartContainer = rightColumn.createEl("div");
window.renderChart(chartConfig, chartContainer);
name New Project
type command
action Templater: Create templates/tpl_project.md
^button-2za5
TABLE
project_name as "Project",
status as "status",
("<progress value='" + progress + "' max='100'></progress>") as "Progress",
creation_date as "Date Created"
FROM #project
SORT creation_date DESC