diff --git a/src/gantt.scss b/src/gantt.scss index 9c91dad..75100d9 100644 --- a/src/gantt.scss +++ b/src/gantt.scss @@ -40,6 +40,21 @@ $handle-color: #ddd !default; 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 { fill: none; stroke: $text-muted; diff --git a/src/index.js b/src/index.js index 9cd505f..e383481 100644 --- a/src/index.js +++ b/src/index.js @@ -412,13 +412,46 @@ export default class Gantt { } } - make_grid_highlights() { - // highlight today's date + computeGridHighlightDimensions(view_mode) { + let xDist = 0; + if (this.view_is(VIEW_MODE.DAY)) { - const x = - (date_utils.diff(date_utils.today(), this.gantt_start, 'hour') / - this.options.step) * + return (date_utils.diff(date_utils.today(), this.gantt_start, 'hour') / + this.options.step) * 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 width = this.options.column_width; @@ -428,12 +461,27 @@ export default class Gantt { this.options.header_height + 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', { x, y, width, height, - class: 'today-highlight', + class: className, append_to: this.layers.grid, }); }