diff --git a/buildoz.css b/buildoz.css index fa4f854..b215a79 100644 --- a/buildoz.css +++ b/buildoz.css @@ -374,9 +374,11 @@ bz-grafloweditor .inner-console section .cols-2 input{ bz-gantt{ + display: block; position: relative; --row: 25px; --bar-gap: 4px; /* space above & below each bar inside its row */ + --chart-left: calc(var(--tasks-width, 7em) + 1em); /* where the chart area starts */ } bz-gantt ul.tasks{ list-style: none; @@ -394,6 +396,24 @@ bz-gantt ul.tasks li{ bz-gantt.gantt bz-graflow{ position: absolute; - left: calc(var(--tasks-width, 7em) + 1em); + left: var(--chart-left); + top: calc(var(--row) + var(--bar-gap)); /* one header row (days grid) + bar centering gap */ + right: 0; + bottom: 0; + width: auto; /* cancel the global bz-graflow 100vw/100vh defaults, */ + height: auto; /* so the box stretches between its anchored edges */ +} +bz-gantt li.header div.day:first-of-type{ border-left: 1px dotted #555; } +bz-gantt li.header div.day{ + position: absolute; + /* anchored to bz-gantt (nearest positioned ancestor): spans all rows */ top: var(--bar-gap); + bottom: 0; + border-right: 1px dotted #555; + font-size: .8em; +} +bz-gantt li.header div.day.today{ + background: #AD8; + z-index: 999; + opacity: .3; } \ No newline at end of file diff --git a/bzGantt.js b/bzGantt.js index f873e97..396f72c 100644 --- a/bzGantt.js +++ b/bzGantt.js @@ -142,9 +142,10 @@ class BZgantt extends Buildoz { const flow = { "nodes": [], "links": [] } let curY = 0 + let endIdx = 0 for(const task of this.tasks){ const startIdx = this.getDayIndex(firstDate, new Date(task.start)) - const endIdx = this.getDayIndex(firstDate, new Date(task.end)) + endIdx = this.getDayIndex(firstDate, new Date(task.end)) flow.nodes.push({ "nodeType": "bar", "id": task.id, @@ -163,11 +164,15 @@ class BZgantt extends Buildoz { } curY += this.rowHeight } - return flow + return([flow, endIdx]) } refresh(){ this.ul.innerHTML = '' + this.headerLi = document.createElement('li') + this.headerLi.classList.add('header') + this.ul.appendChild(this.headerLi) + for(const task of this.tasks){ const li = document.createElement('li') li.textContent = task.name @@ -183,7 +188,26 @@ class BZgantt extends Buildoz { } this.style.setProperty('--tasks-width', Math.ceil(maxWidth) + 'px') - const flow = this.buildFlow() + const [flow, endIdx] = this.buildFlow() + + let dayDate = new Date(this.tasks[0].start) + for(let idx=0; idx<=endIdx; idx++){ + const dayDiv = document.createElement('div') + dayDiv.classList.add('day') + dayDiv.style.left = `calc(var(--chart-left) + ${idx * this.dayWidth}px)` + dayDiv.style.width = this.dayWidth + 'px' + dayDiv.innerHTML = ' ' + dayDate.getDate() + if(dayDate.toISOString().substring(0,10) == (new Date()).toISOString().substring(0,10)) dayDiv.classList.add('today') + dayDiv.setAttribute('title', new Intl.DateTimeFormat('fr-FR', { + timeZone: 'Europe/Paris', + day: '2-digit', + month: '2-digit', + year: '2-digit' + }).format(dayDate)) + dayDate.setDate(dayDate.getDate() + 1) + this.headerLi.appendChild(dayDiv) + } + this.graflow.loadFlow({ "nodesFile": this.nodesfile, "flow": flow diff --git a/graflow_examples/test8.html b/graflow_examples/test8.html index 2216b9e..2de4fc3 100644 --- a/graflow_examples/test8.html +++ b/graflow_examples/test8.html @@ -29,15 +29,15 @@