Skip to content

Commit 030d2bf

Browse files
committed
[fix][feat] Highlighted dates/hours
Fix zunnzunn#125 [feat] re-working of zunnzunn#95 Adds new props to handle different methods of highlighting dates and hours. - `highlighted-days-of-week` to handle highlighting the same day or days every week without having to calculate their dates. Useful for highlighting weekends. Set to [0, 6]. - `highlighted-dates` for when you want to highlight specific dates. - `highlighted-hours` for when you are using hour precision. `highlighted-units` probably depreciated now.
1 parent e7cfe40 commit 030d2bf

4 files changed

Lines changed: 35 additions & 5 deletions

File tree

docs/GGanttChart.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +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.
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`
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`.
24+
| `highlighted-hours` | number[]? | When using `precision = hour` set this array to the hours that should be highlighted.
2225
| `font` | string | `"Helvetica"`| Font family of the chart.
2326
| `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.
2427
| `label-column-width` | string? | `150px` | Width of the column containing the row labels (if `label-column-title` specified)

src/GanttPlayground.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
<g-gantt-chart
33
:chart-start="chartStart"
44
:chart-end="chartEnd"
5-
precision="week"
5+
precision="day"
66
:row-height="40"
7+
:highlighted-hours="[0, 1, 8, 22, 23]"
8+
:highlighted-days-of-week="[0, 6]"
9+
:highlighted-dates="[4, 6]"
710
grid
811
current-time
912
width="100%"

src/components/GGanttChart.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ export interface GGanttChartProps {
9797
noOverlap?: boolean
9898
rowHeight?: number
9999
highlightedUnits?: number[]
100+
highlightedDates?: number[]
101+
highlightedDaysOfWeek?: number[]
102+
highlightedHours?: number[]
100103
font?: string
101104
labelColumnTitle?: string
102105
labelColumnWidth?: string
@@ -126,6 +129,9 @@ const props = withDefaults(defineProps<GGanttChartProps>(), {
126129
noOverlap: false,
127130
rowHeight: 40,
128131
highlightedUnits: () => [],
132+
highlightedDates: () => [],
133+
highlightedDaysOfWeek: () => [],
134+
highlightedHours: () => [],
129135
font: "inherit",
130136
labelColumnTitle: "",
131137
labelColumnWidth: "150px",

src/components/GGanttGrid.vue

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<template>
22
<div class="g-grid-container">
33
<div
4-
v-for="({ label, value, width }, index) in timeaxisUnits.lowerUnits"
4+
v-for="({ label, date, width }, index) in timeaxisUnits.lowerUnits"
55
:key="`${label}_${index}`"
66
class="g-grid-line"
77
:style="{
88
width,
9-
background: highlightedUnits?.includes(Number(value)) ? colors.hoverHighlight : undefined
9+
background: shouldHighlight(date) ? colors.hoverHighlight : undefined
1010
}"
1111
/>
1212
</div>
@@ -16,12 +16,30 @@
1616
import provideConfig from "../provider/provideConfig.js"
1717
import useTimeaxisUnits from "../composables/useTimeaxisUnits.js"
1818
19-
defineProps<{
19+
const props = defineProps<{
2020
highlightedUnits?: number[]
2121
}>()
2222
23-
const { colors } = provideConfig()
23+
const { colors, precision, highlightedDaysOfWeek, highlightedDates, highlightedHours } = provideConfig()
2424
const { timeaxisUnits } = useTimeaxisUnits()
25+
26+
function shouldHighlight(date: Date): boolean {
27+
if (precision.value === "hour") {
28+
return highlightedHours?.value.includes(date.getHours())
29+
} else if (precision.value !== "week" && precision.value !== "month") {
30+
if (highlightedDaysOfWeek?.value.includes(date.getDay())) {
31+
return true
32+
}
33+
if (highlightedDates?.value.includes(date.getDate())) {
34+
return true
35+
}
36+
if (props.highlightedUnits?.includes(date.getHours())) {
37+
return true
38+
}
39+
}
40+
41+
return false
42+
}
2543
</script>
2644

2745
<style>

0 commit comments

Comments
 (0)