Ganttchart with dataview and mermaid, stop showing tasks after 4 months

What I’m trying to do

I have a 7 month project with about 30 tasks, going from Januari until the end of June.

The chart is created following this post:

Code used: https://github.com/anantshri/Obsidian_stuff/blob/main/dataviewjs/ganttchart-from-tasks.md
Styling thanks to [mnvwvnm] this post How to style GANTT chart (mermaid)? - #2 by ZKE

With the help of chatGTP and all above I was able to color the tasks (done/active/critical) and also see the done tasks also.

But for some reason the chart stops showing tasks after 4 months.
Everything after the first of May does not show up.
Changing the start dates to a date before First of May show the tasks …

Is this a ‘normal’ behavior, and as time (months) goes by the ‘missing’ tasks will show up in the Gantt chart ?


The code used, could be of use to someone.

// Priority mapping based on emojis
const priorityMap = {
    "🔺": "Highest",
    "⏫": "High",
    "⏺️": "Medium",
    "🔽": "Low",
    "⏬": "Lowest"
};

// Function to determine priority based on emoji in task text
const getPriority = (text) => {
    for (let emoji in priorityMap) {
        if (text.includes(emoji)) {
            return priorityMap[emoji];
        }
    }
    return "Medium"; // Default to Medium if no emoji is found
};

const today = new Date(); // Get the current date
const todayStr = today.toISOString().split("T")[0]; // YYYY-MM-DD format
const tomorrow = new Date(today); // Clone the today date 
tomorrow.setDate(today.getDate() + 1); // Add 1 day 
const future_date_max = new Date(today); future_date_max.setDate(today.getDate() + 90);
const tomorrowStr = tomorrow.toISOString().split("T")[0]; // Format as YYYY-MM-DD
const tasks = dv.pages("").file.tasks.where(t => t.text.includes("#fotoexpo") && t.start && t.due && t.status != "-") .sort(t=>t.start);

let endme="";

if (tasks.length > 0) {
    let ganttData = `
\`\`\`mermaid

gantt
    title Alle taken
    dateFormat YYYY-MM-DD
    axisFormat %d-%b
	tickInterval 1week
    `;
    
    // Group tasks by priority and create a critical group
    const priorityGroups = {"Critical": [], "Highest": [], "High": [], "Medium": [], "Low": [], "Lowest": [] };
    
    tasks.forEach(task => {
    const dueDate = new Date(task.due.toString().split("T")[0]); // Vervaldatum als Date-object
    const startD = new Date(task.start.toString().split("T")[0]); // Startdatum als Date-object
    const startDate = task.start.toString().split("T")[0]; // Startdatum in YYYY-MM-DD-formaat
    const endDate = task.due.toString().split("T")[0]; // Einddatum in YYYY-MM-DD-formaat
    const endD = new Date(task.due.toString().split("T")[0]); // Einddatum als Date-object
    const isCritical = !task.completed && dueDate < today; // Alleen onvoltooide en over tijd taken zijn "Critical"

    if (startD <= future_date_max) {
        const priority = isCritical ? "Critical" : getPriority(task.text); // Bepaal prioriteit
        if (endD > future_date_max) {
            endme = future_date_max.toString().split("T")[0];
        } else {
            endme = endDate;
        }

        let sanitizedTaskText = task.text
            .replace(/#[\w-]+/g, "") // Verwijder hashtags
            .replace(/(?:\p{Emoji_Presentation}|[\u2600-\u27BF])\s*\d{4}-\d{2}-\d{2}/gu, "") // Verwijder data met emoji's
            .replace(/[\n\r]+/g, " ") // Verwijder nieuwe regels
            .trim(); // Verwijder spaties aan het begin/einde

        for (let emoji in priorityMap) { 
            sanitizedTaskText = sanitizedTaskText.replace(emoji, "").trim(); 
        }

        if (sanitizedTaskText) {
            if (task.completed) {
                // Markeer voltooide taken
                priorityGroups[priority].push(`    ${sanitizedTaskText} :done, ${startDate}, ${endDate}`);
            } else if (isCritical) {
                // Markeer kritieke taken
                priorityGroups[priority].push(`    ${sanitizedTaskText} :crit, ${startDate}, ${tomorrowStr}`);
            } else { 
                // Voeg actieve taken toe
                priorityGroups[priority].push(`    ${sanitizedTaskText} :active, ${startDate}, ${endDate}`);
            }
        }
    }
});


    // Add tasks to Gantt chart by priority
    for (const priority in priorityGroups) {
        if (priorityGroups[priority].length > 0) {
            ganttData += `\nsection ${priority}\n`;
            ganttData += priorityGroups[priority].join("\n");
        }
    }

    ganttData += `\n\`\`\``;

    // Debug mode: Show raw text
    dv.el("pre", ganttData); 
} else {
    dv.paragraph("No tasks found with Gantt chart marker and with start and due dates.");
}

To answer my own question, I have turned off internet. changed the date to the first of April.
Yes the chart moves and showed all the data.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.