mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-20 15:59:51 +02:00
Fix gantt diagram xAxis format
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
|
|
||||||
import { parser } from './parser/gantt'
|
import { parser } from './parser/gantt'
|
||||||
import ganttDb from './ganttDb'
|
import ganttDb from './ganttDb'
|
||||||
import d3 from '../../d3'
|
import d3 from '../../d3'
|
||||||
|
import { logger } from '../../logger'
|
||||||
|
|
||||||
parser.yy = ganttDb
|
parser.yy = ganttDb
|
||||||
|
|
||||||
@@ -254,59 +254,32 @@ export const draw = function (text, id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function makeGrid (theSidePad, theTopPad, w, h) {
|
function makeGrid (theSidePad, theTopPad, w, h) {
|
||||||
const pre = [
|
const formatMillisecond = d3.timeFormat('.%L')
|
||||||
['.%L', function (d) {
|
const formatSecond = d3.timeFormat(':%S')
|
||||||
return d.getMilliseconds()
|
const formatMinute = d3.timeFormat('%I:%M')
|
||||||
}],
|
const formatHour = d3.timeFormat('%I %p')
|
||||||
[':%S', function (d) {
|
const formatDay = d3.timeFormat('%Y-%m-%d')
|
||||||
return d.getSeconds()
|
const formatWeek = d3.timeFormat('%Y-%m-%d')
|
||||||
}],
|
const formatMonth = d3.timeFormat('%b-%Y')
|
||||||
// Within a hour
|
const formatYear = d3.timeFormat('%Y')
|
||||||
['h1 %I:%M', function (d) {
|
|
||||||
return d.getMinutes()
|
|
||||||
}]]
|
|
||||||
const post = [
|
|
||||||
['%Y', function () {
|
|
||||||
return true
|
|
||||||
}]]
|
|
||||||
|
|
||||||
let mid = [
|
const multiFormat = date => {
|
||||||
// Within a day
|
return (d3.timeSecond(date) < date ? formatMillisecond
|
||||||
['%I:%M', function (d) {
|
: d3.timeMinute(date) < date ? formatSecond
|
||||||
return d.getHours()
|
: d3.timeHour(date) < date ? formatMinute
|
||||||
}],
|
: d3.timeDay(date) < date ? formatHour
|
||||||
// Day within a week (not monday)
|
: d3.timeMonth(date) < date ? (d3.timeWeek(date) < date ? formatDay : formatWeek)
|
||||||
['%a %d', function (d) {
|
: d3.timeYear(date) < date ? formatMonth
|
||||||
return d.getDay() && d.getDate() !== 1
|
: formatYear)(date)
|
||||||
}],
|
|
||||||
// within a month
|
|
||||||
['%b %d', function (d) {
|
|
||||||
return d.getDate() !== 1
|
|
||||||
}],
|
|
||||||
// Month
|
|
||||||
['%B', function (d) {
|
|
||||||
return d.getMonth()
|
|
||||||
}]
|
|
||||||
]
|
|
||||||
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)
|
|
||||||
|
// todo: if (typeof conf.axisFormatter !== 'undefined')
|
||||||
|
|
||||||
let xAxis = d3.axisBottom(timeScale)
|
let xAxis = d3.axisBottom(timeScale)
|
||||||
.tickSize(-h + theTopPad + conf.gridLineStartPadding, 0, 0)
|
.tickSize(-h + theTopPad + conf.gridLineStartPadding)
|
||||||
// .tickFormat(d3.time.format.multi(formatter))
|
.tickFormat(multiFormat)
|
||||||
|
|
||||||
// if (daysInChart > 7 && daysInChart < 230) {
|
logger.debug(daysInChart) // just to pass lint
|
||||||
// xAxis = xAxis.ticks(d3.timeMonday.range)
|
|
||||||
// }
|
|
||||||
|
|
||||||
svg.append('g')
|
svg.append('g')
|
||||||
.attr('class', 'grid')
|
.attr('class', 'grid')
|
||||||
|
8
todo.md
8
todo.md
@@ -1,4 +1,3 @@
|
|||||||
- Fix d3-textwrap code
|
|
||||||
- Replace CodeClimate with coveralls ?
|
- Replace CodeClimate with coveralls ?
|
||||||
- Get familar with jison
|
- Get familar with jison
|
||||||
- git graph requires a blank line at the end. why?
|
- git graph requires a blank line at the end. why?
|
||||||
@@ -7,6 +6,11 @@
|
|||||||
- rewrite less code
|
- rewrite less code
|
||||||
- Setup code coverage
|
- Setup code coverage
|
||||||
- Create a desktop client
|
- Create a desktop client
|
||||||
- fix gantt diagram xAxis issue
|
|
||||||
- Fix sequence diagram node label position issue
|
- Fix sequence diagram node label position issue
|
||||||
|
- caused by d3-textwrap?
|
||||||
|
- remove textwrap feature?
|
||||||
- Fix flowchart interpolate/curve issue
|
- Fix flowchart interpolate/curve issue
|
||||||
|
- not a common feature so dist/index.html cannot reproduce this issue
|
||||||
|
- Support customization of gantt diagram xAxis format
|
||||||
|
- https://github.com/d3/d3-time-format#api-reference
|
||||||
|
- https://bl.ocks.org/wboykinm/34627426d84f3242e0e6ecb2339e9065
|
||||||
|
Reference in New Issue
Block a user