Skip to content

feat: add the possibility to force the chart to start on a specific day of week #527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Each object can have the following properties:
- `upper_text` (date format string _or_ function) - the format for text in upper header. Blank string for none. The function takes in `currentDate`, `previousDate`, and `lang`, and should return a string.
- `upper_text_frequency` (number) - how often the upper text has a value. Utilized in internal calculation to improve performance.
- `thick_line` (function) - takes in `currentDate`, returns Boolean determining whether the line for that date should be thicker than the others.
- `dow_force_start` (number) - if you want the chart to start on a specific day of the week, add this property and the desired value (0 for Sunday, 1 for Monday, 2 for Tuesday, ..., 6 for Saturday). The start date will then be moved backward from 0 to 6 days depending on the initial calculated start date and your input value).

Three other options allow you to override general configuration for this view mode alone:
- `date_format`
Expand Down
1 change: 1 addition & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const DEFAULT_VIEW_MODES = [
: '',
thick_line: (d) => d.getDate() >= 1 && d.getDate() <= 7,
upper_text_frequency: 4,
dow_force_start:1,
},
{
name: 'Month',
Expand Down
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ export default class Gantt {
);
}
}
if (this.config.view_mode.dow_force_start) {
let dow_gantt_start = this.gantt_start.getDay();
let dow_wanted_start = this.config.view_mode.dow_force_start;
if (dow_gantt_start != dow_wanted_start) {
this.gantt_start = date_utils.add(
this.gantt_start,
((this.gantt_start.getDay() + 7 - (this.config.view_mode.dow_force_start % 7)) * (-1)) % 7,
'day',
);
}
}
this.config.date_format =
this.config.view_mode.date_format || this.options.date_format;
this.gantt_start.setHours(0, 0, 0, 0);
Expand Down