Skip to content
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

Added exclude weekdays to definition #792

Merged
merged 14 commits into from
May 28, 2019
Merged

Added exclude weekdays to definition #792

merged 14 commits into from
May 28, 2019

Conversation

jopapo
Copy link

@jopapo jopapo commented Feb 6, 2019

Added: exclude weekdays [and a list of specific dates] on Gantt.

As mentioned on issue #314

It is open to discussion how to render this:

  1. Keep this way. Extending the weekends or excluded days;
  2. Hide the ignored dates;
  3. Indicate the ignored dates on the task rectangle in some way.

But I think it can be handled on another issue if anyone needs it.

@coveralls
Copy link

coveralls commented Feb 6, 2019

Pull Request Test Coverage Report for Build 738

  • 46 of 60 (76.67%) changed or added relevant lines in 3 files are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.3%) to 54.568%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/diagrams/gantt/ganttRenderer.js 0 2 0.0%
src/diagrams/gantt/parser/gantt.js 10 14 71.43%
src/diagrams/gantt/ganttDb.js 36 44 81.82%
Files with Coverage Reduction New Missed Lines %
src/diagrams/gantt/parser/gantt.js 1 50.4%
src/diagrams/gantt/ganttDb.js 2 71.94%
Totals Coverage Status
Change from base Build 716: 0.3%
Covered Lines: 2086
Relevant Lines: 3795

💛 - Coveralls

Copy link
Contributor

@gijswijs gijswijs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great that you took it on you to tackle this. I still see some points of discussion though.

  1. It's debatable what days are considered weekend throughout the world. Big parts of the world consider Friday and Saturday to be the weekend. So I propose to just explicitly state the weekdays you want to have excluded. So either "Saturday, Sunday" or "Friday, Saturday". This also leaves open the option for having a parttime working week where one would work 3 or 4 days a week.

  2. This code currently seems to not take into account excluded days or dates that fall in the middle of durations. If I have a duration of 20d's I expect the Gantt chart to adjust for every excluded day within that period. Now it only seems to look at the exact end date of that duration.

  3. If explicit end dates are given in the task definition, I don't think we should change that date if it's an excluded day or date. We should assume that the author had a valid reason for having that specific date. This is debatable, but that's what I'd would expect as behavior of the Gantt chart.

}
// Default date - now
return d.toDate()
return getNextValidDate(d, dateFormat, excludes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this correctly, this only checks whether an end date should be excluded, and if so, it returns the next Valid Date. But excluded dates can also fall in the duration of the task itself, and the duration should be adjusted accordingly. E.g. when you are excluding weekends, and the startdate is on a Friday, this function will return Tuesday as the enddate. But that's incorrect, it should return Thursday as the enddate.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It was incorrect. My fix was to target the task after the start and end computation. See below.

return moment(str, dateFormat.trim(), true).toDate()
let mDate = moment(str, dateFormat.trim(), true)
if (mDate.isValid()) {
return getNextValidDate(mDate, dateFormat, excludes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an explicit enddate is set, I'm not sure whether we should change the enddate based on exclusion of weekends or other dates. You could have an explicit enddate in the weekend, because of particular reasons for that task.
The bigger question is, should enddates only be adjusted based on exclusions, when the tasks defines a duration instead of a specific enddate? I would think so.

Copy link
Author

@jopapo jopapo Feb 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that, when the user wants an endTime, it is not necessary to skip weekend. So, my fix is to prevent this from happening.
But, I do not know if it was the best way to check if the endTime was manually inputted.

@@ -58,7 +63,22 @@ export const getTasks = function () {
return tasks
}

const getStartDate = function (prevTime, dateFormat, str) {
const isInvalidDate = function (date, dateFormat, excludes) {
if (date.isoWeekday() >= 6 && excludes.indexOf('weekends') >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everywhere it says weekdays, (even in the PR title) but the code only checks for the word 'weekends'. The latter seems more logical, because people are more likely to wanting to exclude weekends. Although that has problems attached to it as well, which I will address in the general review comment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I kept weekend as the "default" but if the user chooses to put the weekday name (friday, saturday, monday), it will work too.

ganttDb.setDateFormat('YYYY-MM-DD')
ganttDb.setExcludes('weekends 2019-02-06')
ganttDb.addSection('testa1')
ganttDb.addTask('test1', 'id1,2019-02-01,1d')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this would be:

ganttDb.addTask('test1', 'id1,2019-02-01,8d')

You'd expect

 expect(tasks[1].startTime).toEqual(moment('2019-02-13', 'YYYY-MM-DD').toDate())

And your code would return 2019-01-11

Some more fringe test cases are needed here.

Copy link
Author

@jopapo jopapo Feb 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more tests.

@jopapo
Copy link
Author

jopapo commented Feb 7, 2019

The main reasoning now is:

  • if endtime is specified, there is no skipped dates;
  • excludes can be: dates (in the configured format), weekend (sunday and saturday), and weekdays (monday, friday). Separated by space or comma;
  • starttime is never computed because, or it is manually specified or is from another endtime;
  • each skipped date between starttime and endtime add 1 day to endtime.

I think it might be enough.

Thank you for your observations and feedback. It is long due for me to give back to the community. Im eager to learn more about it.

@gijswijs
Copy link
Contributor

Shouldn't you check if the starttime itself isn't an excluded day or date? If a task ends on Friday, the following task should start on Monday, right? The end date should remain the same, since you already correct the enddate for the Saturday and the Sunday (if the weekend is excluded) but it just seems weird to have a task starting on a day that is excluded.

@jopapo
Copy link
Author

jopapo commented Feb 11, 2019

Hum... true. It works this way, but its weird. I'll take a look on this.

@jopapo
Copy link
Author

jopapo commented Feb 12, 2019

Created and renderEndDate to achieve those skipped weekends on chart.
Took the liberty to attach a the test print to easy visualization.

gantt4

@pgebheim
Copy link

What are the chances this can be merged?

Would love to get this feature upstream into all the VSCode plugins and such.

@knsv
Copy link
Collaborator

knsv commented May 28, 2019

If it works the chances are good!

@knsv knsv merged commit 9191663 into mermaid-js:master May 28, 2019
@pgebheim
Copy link

Amazing!

mgenereu pushed a commit to mgenereu/mermaid that referenced this pull request Jun 25, 2022
…yarn/develop/mermaid-9.1.1

chore(deps): bump mermaid from 9.0.1 to 9.1.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants