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

add axisFormat option to ganttConfig #624

Closed
wants to merge 3 commits into from
Closed
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 dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<div class="mermaid">
gantt
dateFormat YYYY-MM-DD
axisFormat %m/%d(%Y)
title Adding GANTT diagram to mermaid

section A section
Expand Down
12 changes: 12 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 @@ -25,6 +26,15 @@ export const setDateFormat = function (txt) {
export const getDateFormat = function () {
return dateFormat
}

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

export const getAxisFormat = function () {
return axisFormat
}

export const setTitle = function (txt) {
title = txt
}
Expand Down Expand Up @@ -349,6 +359,8 @@ export default {
clear,
setDateFormat,
getDateFormat,
setAxisFormat,
getAxisFormat,
setTitle,
getTitle,
addSection,
Expand Down
30 changes: 18 additions & 12 deletions src/diagrams/gantt/ganttRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,22 +289,28 @@ export const draw = function (text, id) {
}]
]
let formatter
if (typeof conf.axisFormatter !== 'undefined') {
mid = []
conf.axisFormatter.forEach(function (item) {
const n = []
n[0] = item[0]
n[1] = item[1]
mid.push(n)
})
}
formatter = pre.concat(mid).concat(post)

let xAxis = d3.svg.axis()
.scale(timeScale)
.orient('bottom')
.tickSize(-h + theTopPad + conf.gridLineStartPadding, 0, 0)
.tickFormat(d3.time.format.multi(formatter))
if (parser.yy.getAxisFormat() !== '') {
xAxis = xAxis.tickFormat(d3.time.format(parser.yy.getAxisFormat()))
} else if (typeof conf.axisFormatter === 'string') {
xAxis = xAxis.tickFormat(d3.time.format(conf.axisFormatter))
} else {
if (typeof conf.axisFormatter !== 'undefined') {
mid = []
conf.axisFormatter.forEach(function (item) {
const n = []
n[0] = item[0]
n[1] = item[1]
mid.push(n)
})
}
formatter = pre.concat(mid).concat(post)

xAxis = xAxis.tickFormat(d3.time.format.multi(formatter))
}

if (daysInChart > 7 && daysInChart < 230) {
xAxis = xAxis.ticks(d3.time.monday.range)
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
55 changes: 30 additions & 25 deletions src/diagrams/gantt/parser/gantt.js

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