habit tracker in Obsidian
const startOfWeek = moment().startOf("isoWeek").format("YYYY-MM-DD");
const endOfWeek = moment().endOf("isoWeek").format("YYYY-MM-DD");
// Enhanced color palette with harmonious colors
"#9C27B0", // Deep Purple for early wake-up and sleep
"#4CAF50", // Green for meals and smoothie
"#2196F3", // Blue for university and gym
"#FF5722", // Deep Orange for studying/coding
// Habit definitions remain the same, but with updated color indices
filter: (task) => task.text.includes("Levantarme temprano"),
filter: (task) => task.text.includes("Bañarme"),
filter: (task) => task.text.includes("Desayunar"),
filter: (task) => task.text.includes("Ir a la u"),
filter: (task) => task.text.includes("Almorzar"),
name: "Estudiar/codear/hacer tareas",
task.text.includes("Estudiar") ||
task.text.includes("codear") ||
task.text.includes("hacer tareas"),
filter: (task) => task.text.includes("Ir al gym"),
filter: (task) => task.text.includes("Batido"),
filter: (task) => task.text.includes("Dormir"),
// Initialize weekData if not already defined
for (let page of dv.pages('"ZZZ Journal"')
.where((p) => p.file.name >= startOfWeek && p.file.name <= endOfWeek)) {
const tasks = page.file.tasks.filter((t) => habit.filter(t) && t.checked);
value: tasks.length > 0 // Simplified entry creation
color: colorPalette[habit.colorIndex],
// Enhanced Habit Tracker Rendering Function
function renderHabitTracker(container, weekData) {
// Create main container with modern styling
const trackerContainer = dv.el("div");
trackerContainer.style.cssText = `
font-family: 'Arial', sans-serif;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
const header = table.createTHead();
const headerRow = header.insertRow();
headerRow.style.backgroundColor = "#3f51b5";
headerRow.style.color = "white";
const habitHeaderCell = headerRow.insertCell();
habitHeaderCell.textContent = "Hábitos";
habitHeaderCell.style.cssText = `
border-right: 1px solid rgba(255,255,255,0.2);
"Lunes", "Martes", "Miércoles", "Jueves",
"Viernes", "Sábado", "Domingo"
const headerCell = headerRow.insertCell();
border-left: 1px solid rgba(255,255,255,0.2);
const body = table.createTBody();
weekData.habits.forEach(habit => {
row.style.backgroundColor = "#ffffff";
const habitCell = row.insertCell();
habitCell.textContent = habit.name;
border-right: 1px solid #e0e0e0;
const dayDate = moment(startOfWeek).add(i, "days").format("YYYY-MM-DD");
const entry = habit.entries.find((e) => e.date === dayDate);
const cell = row.insertCell();
transition: background-color 0.3s ease;
cell.style.backgroundColor = habit.color;
cell.style.fontWeight = "bold";
cell.style.backgroundColor = "white";
trackerContainer.appendChild(table);