Skip to content

Commit 053f0fd

Browse files
committed
Minor refactoring
1 parent 7d36016 commit 053f0fd

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

docs/GGanttChart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The main component of Vue Ganttastic. Represents an entire chart and is meant to
88
| `precision` | string? | `"hour"` | Display precision of the time-axis. Possible values: `hour`, `day` and `month`. |
99
| `bar-start` | string | | Name of the property in bar objects that represents the start date.
1010
| `bar-end` | string | | Name of the property in bar objects that represents the end date .
11-
| `date-format` | string \| false \| undefined | `"YYYY-MM-DD HH:mm"` | Datetime string format of `chart-start`, `chart-end` and the values of the `bar-start`, `bar-end` properties in bar objects. See [Day.js format tokens](https://day.js.org/docs/en/parse/string-format). If you want to use Javascript Date set to `false`.
11+
| `date-format` | string \| false | `"YYYY-MM-DD HH:mm"` | Datetime string format of `chart-start`, `chart-end` and the values of the `bar-start`, `bar-end` properties in bar objects. See [Day.js format tokens](https://day.js.org/docs/en/parse/string-format). If the aforementioned properties are native JavaScript [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) objects in your use case, pass `false`.
1212
| `width` | string? | `"100%"` | Width of the chart (e.g. `80%` or `800px`)
1313
| `hide-timeaxis` | boolean? | `false` | Toggle visibility of the time axis.
1414
| `color-scheme` | string \| ColorScheme | `"default"` | Color scheme (theme) of the chart. Either use the name of one of the predefined schemes or pass a color-scheme-object of your own. See [color schemes](#color-schemes).

src/components/GGanttChart.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { colorSchemes, type ColorScheme } from "../color-schemes.js"
4949
import type { ColorSchemeKey } from "../color-schemes.js"
5050
import { CHART_ROWS_KEY, CONFIG_KEY, EMIT_BAR_EVENT_KEY } from "../provider/symbols.js"
5151
import type { GanttBarObject } from "../types"
52+
import { DEFAULT_DATE_FORMAT } from "../composables/useDayjsHelper"
5253
import { useElementSize } from "@vueuse/core"
5354
5455
export interface GGanttChartProps {
@@ -57,7 +58,7 @@ export interface GGanttChartProps {
5758
precision?: "hour" | "day" | "month"
5859
barStart: string
5960
barEnd: string
60-
dateFormat: string | false | undefined
61+
dateFormat?: string | false
6162
width?: string
6263
hideTimeaxis?: boolean
6364
colorScheme?: ColorSchemeKey | ColorScheme
@@ -78,6 +79,7 @@ export type GGanttChartConfig = ToRefs<Required<GGanttChartProps>> & {
7879
}
7980
8081
const props = withDefaults(defineProps<GGanttChartProps>(), {
82+
dateFormat: DEFAULT_DATE_FORMAT,
8183
precision: "day",
8284
width: "100%",
8385
hideTimeaxis: false,

src/composables/useDayjsHelper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ export default function useDayjsHelper(config: GGanttChartConfig = provideConfig
2727
return dayjs(value, format, true)
2828
}
2929

30-
const format = (input: string | Date | Dayjs, template?: string | false | undefined) => {
31-
if (template === false) {
30+
const format = (input: string | Date | Dayjs, pattern?: string | false) => {
31+
if (pattern === false) {
3232
return input instanceof Date ? input : dayjs(input).toDate()
3333
}
3434
const inputDayjs = typeof input === "string" || input instanceof Date ? toDayjs(input) : input
3535

36-
return inputDayjs.format(template)
36+
return inputDayjs.format(pattern)
3737
}
3838

3939
return {

0 commit comments

Comments
 (0)