mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
feat: allow specifying on which weekday a tickInterval should start
This commit is contained in:
parent
5631a218d1
commit
03ce2810b5
@ -257,6 +257,12 @@ The pattern is:
|
||||
|
||||
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
|
||||
|
||||
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.
|
||||
|
@ -50,6 +50,7 @@ const config: Partial<MermaidConfig> = {
|
||||
...defaultConfigJson.gantt,
|
||||
tickInterval: undefined,
|
||||
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: {
|
||||
...defaultConfigJson.c4,
|
||||
|
@ -37,6 +37,7 @@ const tags = ['active', 'done', 'crit', 'milestone'];
|
||||
let funs = [];
|
||||
let inclusiveEndDates = false;
|
||||
let topAxis = false;
|
||||
let weekday = undefined;
|
||||
|
||||
// The serial order of the task in the script
|
||||
let lastOrder = 0;
|
||||
@ -66,6 +67,7 @@ export const clear = function () {
|
||||
lastOrder = 0;
|
||||
links = {};
|
||||
commonClear();
|
||||
weekday = undefined;
|
||||
};
|
||||
|
||||
export const setAxisFormat = function (txt) {
|
||||
@ -179,6 +181,14 @@ export const isInvalidDate = function (date, dateFormat, excludes, includes) {
|
||||
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
|
||||
*
|
||||
@ -759,6 +769,8 @@ export default {
|
||||
bindFunctions,
|
||||
parseDuration,
|
||||
isInvalidDate,
|
||||
setWeekday,
|
||||
getWeekday,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -14,6 +14,12 @@ import {
|
||||
timeHour,
|
||||
timeDay,
|
||||
timeMonday,
|
||||
timeTuesday,
|
||||
timeWednesday,
|
||||
timeThursday,
|
||||
timeFriday,
|
||||
timeSaturday,
|
||||
timeSunday,
|
||||
timeMonth,
|
||||
} from 'd3';
|
||||
import common from '../common/common.js';
|
||||
@ -561,6 +567,8 @@ export const draw = function (text, id, version, diagObj) {
|
||||
if (resultTickInterval !== null) {
|
||||
const every = resultTickInterval[1];
|
||||
const interval = resultTickInterval[2];
|
||||
const weekday = diagObj.db.getWeekday() || conf.weekday;
|
||||
|
||||
switch (interval) {
|
||||
case 'minute':
|
||||
bottomXAxis.ticks(timeMinute.every(every));
|
||||
@ -572,7 +580,30 @@ export const draw = function (text, id, version, diagObj) {
|
||||
bottomXAxis.ticks(timeDay.every(every));
|
||||
break;
|
||||
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;
|
||||
case 'month':
|
||||
bottomXAxis.ticks(timeMonth.every(every));
|
||||
|
@ -86,6 +86,7 @@ that id.
|
||||
"includes"\s[^#\n;]+ return 'includes';
|
||||
"excludes"\s[^#\n;]+ return 'excludes';
|
||||
"todayMarker"\s[^\n;]+ return 'todayMarker';
|
||||
"weekday"\s[^#\n;]+ return 'weekday';
|
||||
\d\d\d\d"-"\d\d"-"\d\d return 'date';
|
||||
"title"\s[^#\n;]+ return 'title';
|
||||
"accDescription"\s[^#\n;]+ return 'accDescription'
|
||||
@ -130,6 +131,7 @@ statement
|
||||
| excludes {yy.setExcludes($1.substr(9));$$=$1.substr(9);}
|
||||
| includes {yy.setIncludes($1.substr(9));$$=$1.substr(9);}
|
||||
| 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);}
|
||||
| acc_title acc_title_value { $$=$2.trim();yy.setAccTitle($$); }
|
||||
| acc_descr acc_descr_value { $$=$2.trim();yy.setAccDescription($$); }
|
||||
|
@ -180,4 +180,9 @@ row2`;
|
||||
expect(ganttDb.getAccTitle()).toBe(expectedTitle);
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user