Skip to content

Commit baf5b95

Browse files
authored
Merge pull request cylc#1706 from cylc/gantt-colour
Gantt view: colour code by cycle point
2 parents a3d4460 + 2cbf96c commit baf5b95

File tree

2 files changed

+55
-37
lines changed

2 files changed

+55
-37
lines changed

changes.d/1466.feat.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added gantt view: a new view showing job durations over time.

src/components/cylc/gantt/GanttChart.vue

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ import {
3838
mdiDownload,
3939
} from '@mdi/js'
4040
import { useReducedAnimation } from '@/composables/localStorage'
41+
import { Tokens } from '@/utils/uid'
42+
43+
const timingOptions = new Map([
44+
['total', { start: 'submittedTime', end: 'finishedTime' }],
45+
['run', { start: 'startedTime', end: 'finishedTime' }],
46+
['queue', { start: 'submittedTime', end: 'startedTime' }],
47+
])
48+
49+
const colours = [
50+
'#008FFB',
51+
'#00E396',
52+
'#775DD0',
53+
'#FEB019',
54+
'#FF4560',
55+
]
4156
4257
export default {
4358
name: 'GanttChart',
@@ -97,43 +112,40 @@ export default {
97112
},
98113
99114
computed: {
115+
displayedJobs () {
116+
const taskNameList = Object.keys(this.jobs)
117+
const firstIndex = Math.max(0, this.tasksPerPage * (this.page - 1))
118+
const numTasks = Math.min(taskNameList.length, firstIndex + this.tasksPerPage)
119+
120+
return Object.values(this.jobs).slice(firstIndex, numTasks).flatMap(
121+
(jobs) => jobs
122+
)
123+
},
100124
series () {
101-
const data = []
125+
let data = []
102126
if (this.jobs.length !== 0) {
103-
const taskNameList = Object.keys(this.jobs)
104-
const startTask = Math.max(0, this.tasksPerPage * (this.page - 1))
105-
const endTask = Math.min(taskNameList.length, startTask + this.tasksPerPage)
106-
107-
const colours = [
108-
'#008FFB',
109-
'#00E396',
110-
'#775DD0',
111-
'#FEB019',
112-
'#FF4560',
113-
]
114-
const taskColours = {}
115-
116-
for (let i = 0; i < taskNameList.length; i++) {
117-
taskColours[taskNameList[i]] = colours[i % colours.length]
118-
}
119-
const timingOptions = {
120-
total: { start: 'submittedTime', end: 'finishedTime' },
121-
run: { start: 'startedTime', end: 'finishedTime' },
122-
queue: { start: 'submittedTime', end: 'startedTime' },
123-
}
124-
const { start, end } = timingOptions[this.timingOption]
125-
for (let i = startTask; i < endTask; i++) {
126-
for (let j = 0; j < this.jobs[taskNameList[i]].length; j++) {
127-
data.push({
128-
x: taskNameList[i],
127+
const { start, end } = timingOptions.get(this.timingOption)
128+
/** Mapping of cycle points to colours */
129+
const jobColours = new Map()
130+
let colourIndex = 0
131+
data = this.displayedJobs.map(
132+
(job) => {
133+
const { cycle } = new Tokens(job.id)
134+
let fillColor = jobColours.get(cycle)
135+
if (!fillColor) {
136+
fillColor = colours[colourIndex++ % colours.length]
137+
jobColours.set(cycle, fillColor)
138+
}
139+
return {
140+
x: job.name,
129141
y: [
130-
new Date(this.jobs[taskNameList[i]][j][start]).getTime(),
131-
new Date(this.jobs[taskNameList[i]][j][end]).getTime()
142+
new Date(job[start]).getTime(),
143+
new Date(job[end]).getTime()
132144
],
133-
fillColor: taskColours[taskNameList[i]],
134-
})
145+
fillColor,
146+
}
135147
}
136-
}
148+
)
137149
}
138150
return [{ data }]
139151
},
@@ -146,6 +158,8 @@ export default {
146158
},
147159
148160
chartOptions () {
161+
const { displayedJobs } = this
162+
const { start, end } = timingOptions.get(this.timingOption)
149163
return {
150164
chart: {
151165
animations: {
@@ -169,16 +183,19 @@ export default {
169183
},
170184
},
171185
tooltip: {
172-
custom: function ({ seriesIndex, dataPointIndex, w }) {
173-
const startTime = new Date(w.config.series[seriesIndex].data[dataPointIndex].y[0])
174-
const finishTime = new Date(w.config.series[seriesIndex].data[dataPointIndex].y[1])
186+
custom ({ dataPointIndex }) {
187+
const job = displayedJobs[dataPointIndex]
188+
const { relativeID } = new Tokens(job.id)
175189
return (
176190
'<div class="apexcharts-tooltip-candlestick">' +
191+
'<div>Job: <span class="value">' +
192+
relativeID +
193+
'</span></div>' +
177194
'<div>Start: <span class="value">' +
178-
startTime +
195+
job[start] +
179196
'</span></div>' +
180197
'<div>Finish: <span class="value">' +
181-
finishTime +
198+
job[end] +
182199
'</span></div>' +
183200
'</div>'
184201
)

0 commit comments

Comments
 (0)