Skip to content

Commit

Permalink
Support customization of gantt diagram xAxis format using diagram code
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerlong committed Mar 13, 2018
1 parent 7ef1b28 commit f62736c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
1 change: 1 addition & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<div class="mermaid">
gantt
dateFormat YYYY-MM-DD
axisFormat %d/%m
title Adding GANTT diagram to mermaid

section A section
Expand Down
11 changes: 11 additions & 0 deletions src/diagrams/gantt/ganttDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import moment from 'moment'
import { logger } from '../../logger'

let dateFormat = ''
let axisFormat = ''
let title = ''
let sections = []
let tasks = []
Expand All @@ -18,6 +19,14 @@ export const clear = function () {
rawTasks = []
}

export const setAxisFormat = function (txt) {
axisFormat = txt
}

export const getAxisFormat = function () {
return axisFormat
}

export const setDateFormat = function (txt) {
dateFormat = txt
}
Expand Down Expand Up @@ -342,6 +351,8 @@ const compileTasks = function () {
export default {
clear,
setDateFormat,
setAxisFormat,
getAxisFormat,
setTitle,
getTitle,
addSection,
Expand Down
2 changes: 1 addition & 1 deletion src/diagrams/gantt/ganttRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export const draw = function (text, id) {
function makeGrid (theSidePad, theTopPad, w, h) {
let xAxis = d3.axisBottom(timeScale)
.tickSize(-h + theTopPad + conf.gridLineStartPadding)
.tickFormat(d3.timeFormat(conf.axisFormat || '%Y-%m-%d'))
.tickFormat(d3.timeFormat(parser.yy.getAxisFormat() || conf.axisFormat || '%Y-%m-%d'))

svg.append('g')
.attr('class', 'grid')
Expand Down
2 changes: 2 additions & 0 deletions src/diagrams/gantt/parser/gantt.jison
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
\%%[^\n]* /* skip comments */
"gantt" return 'gantt';
"dateFormat"\s[^#\n;]+ return 'dateFormat';
"axisFormat"\s[^#\n;]+ return 'axisFormat';
\d\d\d\d"-"\d\d"-"\d\d return 'date';
"title"\s[^#\n;]+ return 'title';
"section"\s[^#:\n;]+ return 'section';
Expand Down Expand Up @@ -54,6 +55,7 @@ line

statement
: 'dateFormat' {yy.setDateFormat($1.substr(11));$$=$1.substr(11);}
| 'axisFormat' {yy.setAxisFormat($1.substr(11));$$=$1.substr(11);}
| title {yy.setTitle($1.substr(6));$$=$1.substr(6);}
| section {yy.addSection($1.substr(8));$$=$1.substr(8);}
| taskTxt taskData {yy.addTask($1,$2);$$='task';}
Expand Down
33 changes: 19 additions & 14 deletions src/diagrams/gantt/parser/gantt.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
- Create a desktop client
- Flowchart `interpolate` is useless because there is no rendering code using it
- Each type of diagram should have its own set of CSS.
- Support customization of gantt diagram xAxis format using diagram code
- Some one created a great PR: https://github.com/knsv/mermaid/pull/624

0 comments on commit f62736c

Please sign in to comment.