1+ <script setup lang="ts">
2+ import { ref } from ' vue'
3+ import { GGanttChart , GGanttRow , type ChartRow , type LabelColumnConfig } from ' hy-vue-gantt'
4+
5+ const chartStart = ref (' 2024-01-01' )
6+ const chartEnd = ref (' 2024-03-31' )
7+ const precision = ref (' day' )
8+ const barStart = ref (' start' )
9+ const barEnd = ref (' end' )
10+
11+ const getN = (row : ChartRow ) => {
12+ return row .bars .length
13+ }
14+
15+ const sortN = (a : ChartRow , b : ChartRow ) => {
16+ const aId = a .bars .length ?? 0
17+ const bId = b .bars .length ?? 0
18+ return aId < bId ? - 1 : aId > bId ? 1 : 0
19+ }
20+
21+
22+ const multiColumnLabel = ref <LabelColumnConfig []>([
23+ {
24+ field: ' Id' ,
25+ sortable: false ,
26+ },
27+ {
28+ field: ' Label' ,
29+ },
30+ {
31+ field: ' StartDate' ,
32+ },
33+ {
34+ field: ' Duration' ,
35+ },
36+ {
37+ field: ' Bars N°' ,
38+ valueGetter: getN ,
39+ sortFn: sortN ,
40+ },
41+ ])
42+
43+ const rows = ref ([
44+ {
45+ id: 1 ,
46+ label: ' Design Phase' ,
47+ bars: [
48+ {
49+ start: ' 2024-01-05' ,
50+ end: ' 2024-01-20' ,
51+ ganttBarConfig: {
52+ id: ' 1' ,
53+ label: ' UI/UX Design' ,
54+ style: { background: ' #42b883' }
55+ }
56+ }
57+ ]
58+ },
59+ {
60+ id: 2 ,
61+ label: ' Development' ,
62+ bars: [
63+ {
64+ start: ' 2024-01-21' ,
65+ end: ' 2024-02-15' ,
66+ ganttBarConfig: {
67+ id: ' 2' ,
68+ label: ' Frontend Implementation' ,
69+ style: { background: ' #35495e' }
70+ }
71+ }
72+ ]
73+ },
74+ {
75+ id: 3 ,
76+ label: ' Testing' ,
77+ bars: [
78+ {
79+ start: ' 2024-02-10' ,
80+ end: ' 2024-02-28' ,
81+ ganttBarConfig: {
82+ id: ' 3' ,
83+ label: ' QA and Testing' ,
84+ style: { background: ' #ff7e67' }
85+ }
86+ }
87+ ]
88+ }
89+ ])
90+ </script >
91+
92+ <template >
93+ <div class =" demo-container" >
94+ <g-gantt-chart
95+ :chart-start =" chartStart"
96+ :chart-end =" chartEnd"
97+ :precision =" precision"
98+ :bar-start =" barStart"
99+ :bar-end =" barEnd"
100+ :row-height =" 40"
101+ grid
102+ label-column-title =" Project Details"
103+ :multi-column-label =" multiColumnLabel"
104+ sortable
105+ color-scheme =" slumber"
106+ >
107+ <g-gantt-row
108+ v-for =" row in rows"
109+ :key =" row.label"
110+ :label =" row.label"
111+ :bars =" row.bars"
112+ />
113+ </g-gantt-chart >
114+ </div >
115+ </template >
116+
117+ <style scoped>
118+ .demo-container {
119+ padding : 20px ;
120+ border : 1px solid #eaeaea ;
121+ border-radius : 8px ;
122+ margin : 20px 0 ;
123+ }
124+
125+ h3 {
126+ margin-bottom : 20px ;
127+ color : #42b883 ;
128+ }
129+ </style >
0 commit comments