Skip to content

Commit 0c5a50e

Browse files
author
Olivier Druais
committed
feat(bar): tooltip always visible
If the bar is going out of bounds, make the tooltip visible. Take into account the position of the chart in the page.
1 parent 1f1dc8c commit 0c5a50e

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@infectoone/vue-ganttastic",
3-
"version": "2.3.2",
3+
"version": "2.3.3",
44
"description": "A simple and customizable Gantt chart component for Vue.js",
55
"author": "Marko Zunic (@zunnzunn)",
66
"scripts": {

src/components/GGanttBarTooltip.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
</template>
2121

2222
<script setup lang="ts">
23-
import { computed, toRefs, ref, watch, nextTick } from "vue"
23+
import { computed, toRefs, ref, watch, nextTick, inject } from "vue"
2424
2525
import type { GanttBarObject } from "../types"
2626
import useDayjsHelper from "../composables/useDayjsHelper.js"
2727
import provideConfig from "../provider/provideConfig.js"
28+
import { CHART_CONTAINER_KEY } from "../provider/symbols"
2829
2930
const TOOLTIP_FORMATS = {
3031
hour: "HH:mm",
@@ -44,6 +45,8 @@ const props = defineProps<{
4445
const { bar } = toRefs(props)
4546
const { precision, font, barStart, barEnd, rowHeight } = provideConfig()
4647
48+
const barContainerEl = inject(CHART_CONTAINER_KEY)
49+
4750
const tooltipTop = ref("0px")
4851
const tooltipLeft = ref("0px")
4952
watch(
@@ -52,7 +55,7 @@ watch(
5255
await nextTick()
5356
5457
const barId = bar?.value?.ganttBarConfig.id || ""
55-
if (!barId) {
58+
if (!barId || !barContainerEl?.value) {
5659
return
5760
}
5861
@@ -61,7 +64,7 @@ watch(
6164
top: 0,
6265
left: 0
6366
}
64-
const leftValue = Math.max(left, 10)
67+
const leftValue = Math.max(left, barContainerEl?.value.getBoundingClientRect().left)
6568
tooltipTop.value = `${top + rowHeight.value - 10}px`
6669
tooltipLeft.value = `${leftValue}px`
6770
},

src/components/GGanttChart.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import {
7777
CHART_ROWS_KEY,
7878
CONFIG_KEY,
7979
EMIT_BAR_EVENT_KEY,
80+
CHART_CONTAINER_KEY,
8081
type ChartRow
8182
} from "../provider/symbols.js"
8283
@@ -254,6 +255,7 @@ const emitBarEvent = (
254255
const ganttChart = ref<HTMLElement | null>(null)
255256
const chartSize = useElementSize(ganttChart)
256257
258+
provide(CHART_CONTAINER_KEY, ganttChart)
257259
provide(CHART_ROWS_KEY, getChartRows)
258260
provide(CONFIG_KEY, {
259261
...toRefs(props),

src/provider/symbols.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ export const EMIT_BAR_EVENT_KEY = Symbol("EMIT_BAR_EVENT_KEY") as InjectionKey<E
1818
export const BAR_CONTAINER_KEY = Symbol("BAR_CONTAINER_KEY") as InjectionKey<
1919
Ref<HTMLElement | null>
2020
>
21+
export const CHART_CONTAINER_KEY = Symbol("CHART_CONTAINER_KEY") as InjectionKey<
22+
Ref<HTMLElement | null>
23+
>

0 commit comments

Comments
 (0)