Feat:Add Grid highlight for current week, month, year

This commit is contained in:
Deepak Kyatham 2024-03-26 16:23:49 +05:30
parent 1d024dcb55
commit 6cb5c12fb7
2 changed files with 69 additions and 6 deletions

View File

@ -40,6 +40,21 @@ $handle-color: #ddd !default;
opacity: 0.5; opacity: 0.5;
} }
.week-highlight {
fill: $light-yellow;
opacity: 0.5;
}
.month-highlight {
fill: $light-yellow;
opacity: 0.5;
}
.year-highlight {
fill: $light-yellow;
opacity: 0.5;
}
.arrow { .arrow {
fill: none; fill: none;
stroke: $text-muted; stroke: $text-muted;

View File

@ -412,13 +412,46 @@ export default class Gantt {
} }
} }
make_grid_highlights() { computeGridHighlightDimensions(view_mode) {
// highlight today's date let xDist = 0;
if (this.view_is(VIEW_MODE.DAY)) { if (this.view_is(VIEW_MODE.DAY)) {
const x = return (date_utils.diff(date_utils.today(), this.gantt_start, 'hour') /
(date_utils.diff(date_utils.today(), this.gantt_start, 'hour') / this.options.step) *
this.options.step) *
this.options.column_width; this.options.column_width;
}
for (let date of this.dates) {
const todayDate = new Date();
const startDate = new Date(date);
let endDate = new Date(date);
switch (view_mode) {
case VIEW_MODE.WEEK:
endDate.setDate(date.getDate() + 7);
break;
case VIEW_MODE.MONTH:
endDate.setMonth(date.getMonth() + 1);
break;
case VIEW_MODE.YEAR:
endDate.setFullYear(date.getFullYear() + 1);
break;
}
if (todayDate >= startDate && todayDate <= endDate) {
break;
} else {
xDist += this.options.column_width;
}
}
return xDist;
}
make_grid_highlights() {
// highlight today's | week's date
if (this.view_is(VIEW_MODE.DAY) || this.view_is(VIEW_MODE.WEEK) || this.view_is(VIEW_MODE.MONTH) || this.view_is(VIEW_MODE.YEAR)) {
let x = this.computeGridHighlightDimensions(this.options.view_mode);
const y = 0; const y = 0;
const width = this.options.column_width; const width = this.options.column_width;
@ -428,12 +461,27 @@ export default class Gantt {
this.options.header_height + this.options.header_height +
this.options.padding / 2; this.options.padding / 2;
let className = '';
switch (this.options.view_mode) {
case VIEW_MODE.DAY:
className = 'today-highlight'
break;
case VIEW_MODE.WEEK:
className = 'week-highlight'
break;
case VIEW_MODE.MONTH:
className = 'month-highlight'
break;
case VIEW_MODE.YEAR:
className = 'year-highlight'
break;
}
createSVG('rect', { createSVG('rect', {
x, x,
y, y,
width, width,
height, height,
class: 'today-highlight', class: className,
append_to: this.layers.grid, append_to: this.layers.grid,
}); });
} }