Skip to content

Commit 56bea1d

Browse files
committed
[feat] Optionally add title and subtitle to bar tooltip
Adds props: - showTitleInTooltip, boolean?, false - tooltipSubtitle, string?, "" Dee updated docs.
1 parent 1b647fa commit 56bea1d

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

docs/GGanttChart.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ The main component of Vue Ganttastic. Represents an entire chart and is meant to
1919
| `no-overlap` | boolean? | `false` | If `push-on-overlap` is `false`, toggle this to prevent overlaps after drag by snapping the dragged bar back to its original position.
2020
| `row-height` | number? | `40` | Height of each row in pixels.
2121
| `highlighted-units` | number[]? | `[]` | The time units specified here will be visually highlighted in the chart with a mild opaque color. Make sure to also use the `grid` prop on the chart.
22-
| `highlighted-days-of-week` | number[]? | When using `precision = day` or `date`, set this array to the days of the week that should be highlighted. Sunday = 0. So to highlight weekends, use `[0, 6]`. Can be combined with `highlighted-dates`. Make sure to also use the `grid` prop on the chart.
23-
| `highlighted-dates` | number[]? | When using `precision = day` or `date`, set this array to the dates that should be highlighted. e.g. `[1, 15, 23]` to highlight the 1st, 15th and 23rd. Can be combined with `highlighted-days-of-week`. Make sure to also use the `grid` prop on the chart.
24-
| `highlighted-hours` | number[]? | When using `precision = hour` set this array to the hours that should be highlighted. Make sure to also use the `grid` prop on the chart.
22+
| `highlighted-days-of-week` | number[]? | `[]` | When using `precision = day` or `date`, set this array to the days of the week that should be highlighted. Sunday = 0. So to highlight weekends, use `[0, 6]`. Can be combined with `highlighted-dates`. Make sure to also use the `grid` prop on the chart.
23+
| `highlighted-dates` | number[]? | `[]` | When using `precision = day` or `date`, set this array to the dates that should be highlighted. e.g. `[1, 15, 23]` to highlight the 1st, 15th and 23rd. Can be combined with `highlighted-days-of-week`. Make sure to also use the `grid` prop on the chart.
24+
| `highlighted-hours` | number[]? | `[]` | When using `precision = hour` set this array to the hours that should be highlighted. Make sure to also use the `grid` prop on the chart.
2525
| `font` | string | `"Helvetica"`| Font family of the chart.
2626
| `label-column-title` | string? | `''` | If specified, a dedicated column for the row labels will be rendered on the left side of the graph. The specified title is displayed in the upper left corner, as the column's header.
2727
| `label-column-width` | string? | `150px` | Width of the column containing the row labels (if `label-column-title` specified)
@@ -30,6 +30,8 @@ The main component of Vue Ganttastic. Represents an entire chart and is meant to
3030
| `locale` | string? | `en-GB` | Used when getting the day name only.
3131
| `allowRightClickDragging` | boolean? | `false` | Enable or disable the ability to drag bars when right-clicking a bar. Useful if you want to use the context menu and prevent accidental bar movements.
3232
| `disableDragging` | boolean? | `false` | Disable dragging for all bars in the chart.
33+
| `showTitleInTooltip` | boolean? | `true` | When true, adds the title followed by a line break at the start of the tooltip. Make sure to sanitize the value.
34+
| `tooltipSubtitle` | string? | `''` | If provided, adds a line break and the content to the end of the tooltip. Make sure to sanitize the value.
3335

3436

3537
## Custom Events

src/components/GGanttBarTooltip.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
>
1313
<div class="g-gantt-tooltip-color-dot" :style="{ background: dotColor }" />
1414
<slot :bar="bar" :bar-start="barStartRaw" :bar-end="barEndRaw">
15-
{{ tooltipContent }}
15+
<span v-html="tooltipContent"> </span>
1616
</slot>
1717
</div>
1818
</transition>
@@ -43,7 +43,8 @@ const props = defineProps<{
4343
}>()
4444
4545
const { bar } = toRefs(props)
46-
const { precision, font, barStart, barEnd, rowHeight } = provideConfig()
46+
const { precision, font, barStart, barEnd, rowHeight, showLabelInBarTooltip, tooltipSubtitle } =
47+
provideConfig()
4748
4849
const barContainerEl = inject(CHART_CONTAINER_KEY)
4950
@@ -85,7 +86,9 @@ const tooltipContent = computed(() => {
8586
const format = TOOLTIP_FORMATS[precision.value]
8687
const barStartFormatted = toDayjs(barStartRaw.value).format(format)
8788
const barEndFormatted = toDayjs(barEndRaw.value).format(format)
88-
return `${barStartFormatted} \u2013 ${barEndFormatted}`
89+
const title = showLabelInBarTooltip ? `${bar.value.ganttBarConfig.label} <br /> ` : ""
90+
const subtitle = tooltipSubtitle ? `<br />${tooltipSubtitle.value}` : ""
91+
return `${title}${barStartFormatted} \u2013 ${barEndFormatted}${subtitle}`
8992
})
9093
</script>
9194

src/components/GGanttChart.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ export interface GGanttChartProps {
109109
locale?: string
110110
allowRightClickDragging?: boolean
111111
disableDragging?: boolean
112+
showLabelInBarTooltip?: boolean
113+
tooltipSubtitle?: string
112114
}
113115
114116
export type GGanttChartConfig = ToRefs<Required<GGanttChartProps>> & {
@@ -141,7 +143,9 @@ const props = withDefaults(defineProps<GGanttChartProps>(), {
141143
dayNameLength: "short",
142144
locale: "en-GB",
143145
allowRightClickDragging: false,
144-
disableDragging: false
146+
disableDragging: false,
147+
showLabelInBarTooltip: true,
148+
tooltipSubtitle: ""
145149
})
146150
147151
const emit = defineEmits<{

0 commit comments

Comments
 (0)