feat: allow specifying on which weekday a tickInterval should start

This commit is contained in:
Lei Nelissen 2023-07-12 17:23:21 +02:00
parent 5631a218d1
commit 03ce2810b5
6 changed files with 58 additions and 1 deletions

View File

@ -257,6 +257,12 @@ The pattern is:
More info in: <https://github.com/d3/d3-time#interval_every> More info in: <https://github.com/d3/d3-time#interval_every>
Week-based `tickInterval`s start the week on sunday by default. If you wish to specify another weekday on which the `tickInterval` should start, use the `weekday` option:
```markdown
weekday monday
```
## Output in compact mode ## Output in compact mode
The compact mode allows you to display multiple tasks in the same row. Compact mode can be enabled for a gantt chart by setting the display mode of the graph via preceeding YAML settings. The compact mode allows you to display multiple tasks in the same row. Compact mode can be enabled for a gantt chart by setting the display mode of the graph via preceeding YAML settings.

View File

@ -50,6 +50,7 @@ const config: Partial<MermaidConfig> = {
...defaultConfigJson.gantt, ...defaultConfigJson.gantt,
tickInterval: undefined, tickInterval: undefined,
useWidth: undefined, // can probably be removed since `configKeys` already includes this useWidth: undefined, // can probably be removed since `configKeys` already includes this
weekday: 'sunday', // the sane default is a monday, but it's set to sunday for legacy reasons
}, },
c4: { c4: {
...defaultConfigJson.c4, ...defaultConfigJson.c4,

View File

@ -37,6 +37,7 @@ const tags = ['active', 'done', 'crit', 'milestone'];
let funs = []; let funs = [];
let inclusiveEndDates = false; let inclusiveEndDates = false;
let topAxis = false; let topAxis = false;
let weekday = undefined;
// The serial order of the task in the script // The serial order of the task in the script
let lastOrder = 0; let lastOrder = 0;
@ -66,6 +67,7 @@ export const clear = function () {
lastOrder = 0; lastOrder = 0;
links = {}; links = {};
commonClear(); commonClear();
weekday = undefined;
}; };
export const setAxisFormat = function (txt) { export const setAxisFormat = function (txt) {
@ -179,6 +181,14 @@ export const isInvalidDate = function (date, dateFormat, excludes, includes) {
return excludes.includes(date.format(dateFormat.trim())); return excludes.includes(date.format(dateFormat.trim()));
}; };
export const setWeekday = function (txt) {
weekday = txt;
};
export const getWeekday = function () {
return weekday;
};
/** /**
* TODO: fully document what this function does and what types it accepts * TODO: fully document what this function does and what types it accepts
* *
@ -759,6 +769,8 @@ export default {
bindFunctions, bindFunctions,
parseDuration, parseDuration,
isInvalidDate, isInvalidDate,
setWeekday,
getWeekday,
}; };
/** /**

View File

@ -14,6 +14,12 @@ import {
timeHour, timeHour,
timeDay, timeDay,
timeMonday, timeMonday,
timeTuesday,
timeWednesday,
timeThursday,
timeFriday,
timeSaturday,
timeSunday,
timeMonth, timeMonth,
} from 'd3'; } from 'd3';
import common from '../common/common.js'; import common from '../common/common.js';
@ -561,6 +567,8 @@ export const draw = function (text, id, version, diagObj) {
if (resultTickInterval !== null) { if (resultTickInterval !== null) {
const every = resultTickInterval[1]; const every = resultTickInterval[1];
const interval = resultTickInterval[2]; const interval = resultTickInterval[2];
const weekday = diagObj.db.getWeekday() || conf.weekday;
switch (interval) { switch (interval) {
case 'minute': case 'minute':
bottomXAxis.ticks(timeMinute.every(every)); bottomXAxis.ticks(timeMinute.every(every));
@ -572,7 +580,30 @@ export const draw = function (text, id, version, diagObj) {
bottomXAxis.ticks(timeDay.every(every)); bottomXAxis.ticks(timeDay.every(every));
break; break;
case 'week': case 'week':
bottomXAxis.ticks(timeMonday.every(every)); switch (weekday) {
case 'monday':
bottomXAxis.ticks(timeMonday.every(every));
break;
case 'tuesday':
bottomXAxis.ticks(timeTuesday.every(every));
break;
case 'wednesday':
bottomXAxis.ticks(timeWednesday.every(every));
break;
case 'thursday':
bottomXAxis.ticks(timeThursday.every(every));
break;
case 'friday':
bottomXAxis.ticks(timeFriday.every(every));
break;
case 'saturday':
bottomXAxis.ticks(timeSaturday.every(every));
break;
case 'sunday':
default:
bottomXAxis.ticks(timeSunday.every(every));
break;
}
break; break;
case 'month': case 'month':
bottomXAxis.ticks(timeMonth.every(every)); bottomXAxis.ticks(timeMonth.every(every));

View File

@ -86,6 +86,7 @@ that id.
"includes"\s[^#\n;]+ return 'includes'; "includes"\s[^#\n;]+ return 'includes';
"excludes"\s[^#\n;]+ return 'excludes'; "excludes"\s[^#\n;]+ return 'excludes';
"todayMarker"\s[^\n;]+ return 'todayMarker'; "todayMarker"\s[^\n;]+ return 'todayMarker';
"weekday"\s[^#\n;]+ return 'weekday';
\d\d\d\d"-"\d\d"-"\d\d return 'date'; \d\d\d\d"-"\d\d"-"\d\d return 'date';
"title"\s[^#\n;]+ return 'title'; "title"\s[^#\n;]+ return 'title';
"accDescription"\s[^#\n;]+ return 'accDescription' "accDescription"\s[^#\n;]+ return 'accDescription'
@ -130,6 +131,7 @@ statement
| excludes {yy.setExcludes($1.substr(9));$$=$1.substr(9);} | excludes {yy.setExcludes($1.substr(9));$$=$1.substr(9);}
| includes {yy.setIncludes($1.substr(9));$$=$1.substr(9);} | includes {yy.setIncludes($1.substr(9));$$=$1.substr(9);}
| todayMarker {yy.setTodayMarker($1.substr(12));$$=$1.substr(12);} | todayMarker {yy.setTodayMarker($1.substr(12));$$=$1.substr(12);}
| weekday { yy.setWeekday($1.substr(8));$$=$1.substr(8);}
| title {yy.setDiagramTitle($1.substr(6));$$=$1.substr(6);} | title {yy.setDiagramTitle($1.substr(6));$$=$1.substr(6);}
| acc_title acc_title_value { $$=$2.trim();yy.setAccTitle($$); } | acc_title acc_title_value { $$=$2.trim();yy.setAccTitle($$); }
| acc_descr acc_descr_value { $$=$2.trim();yy.setAccDescription($$); } | acc_descr acc_descr_value { $$=$2.trim();yy.setAccDescription($$); }

View File

@ -180,4 +180,9 @@ row2`;
expect(ganttDb.getAccTitle()).toBe(expectedTitle); expect(ganttDb.getAccTitle()).toBe(expectedTitle);
expect(ganttDb.getAccDescription()).toBe(expectedAccDescription); expect(ganttDb.getAccDescription()).toBe(expectedAccDescription);
}); });
it('should allow for customising the weekday for tick intervals', function () {
parser.parse('gantt\nweekday wednesday');
expect(ganttDb.getWeekday()).toBe('wednesday');
});
}); });