Skip to content

Commit 2a077ba

Browse files
committed
Colour code by cycle point
1 parent dd5b909 commit 2a077ba

File tree

1 file changed

+54
-37
lines changed

1 file changed

+54
-37
lines changed

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',
@@ -98,43 +113,40 @@ export default {
98113
},
99114
100115
computed: {
116+
displayedJobs () {
117+
const taskNameList = Object.keys(this.jobs)
118+
const firstIndex = Math.max(0, this.tasksPerPage * (this.page - 1))
119+
const numTasks = Math.min(taskNameList.length, firstIndex + this.tasksPerPage)
120+
121+
return Object.values(this.jobs).slice(firstIndex, numTasks).flatMap(
122+
(jobs) => jobs
123+
)
124+
},
101125
series () {
102-
const data = []
126+
let data = []
103127
if (this.jobs.length !== 0) {
104-
const taskNameList = Object.keys(this.jobs)
105-
const startTask = Math.max(0, this.tasksPerPage * (this.page - 1))
106-
const endTask = Math.min(taskNameList.length, startTask + this.tasksPerPage)
107-
108-
const colours = [
109-
'#008FFB',
110-
'#00E396',
111-
'#775DD0',
112-
'#FEB019',
113-
'#FF4560',
114-
]
115-
const taskColours = {}
116-
117-
for (let i = 0; i < taskNameList.length; i++) {
118-
taskColours[taskNameList[i]] = colours[i % colours.length]
119-
}
120-
const timingOptions = {
121-
total: { start: 'submittedTime', end: 'finishedTime' },
122-
run: { start: 'startedTime', end: 'finishedTime' },
123-
queue: { start: 'submittedTime', end: 'startedTime' },
124-
}
125-
const { start, end } = timingOptions[this.timingOption]
126-
for (let i = startTask; i < endTask; i++) {
127-
for (let j = 0; j < this.jobs[taskNameList[i]].length; j++) {
128-
data.push({
129-
x: taskNameList[i],
128+
const { start, end } = timingOptions.get(this.timingOption)
129+
/** Mapping of cycle points to colours */
130+
const jobColours = new Map()
131+
let colourIndex = 0
132+
data = this.displayedJobs.map(
133+
(job) => {
134+
const { cycle } = new Tokens(job.id)
135+
let fillColor = jobColours.get(cycle)
136+
if (!fillColor) {
137+
fillColor = colours[colourIndex++ % colours.length]
138+
jobColours.set(cycle, fillColor)
139+
}
140+
return {
141+
x: job.name,
130142
y: [
131-
new Date(this.jobs[taskNameList[i]][j][start]).getTime(),
132-
new Date(this.jobs[taskNameList[i]][j][end]).getTime()
143+
new Date(job[start]).getTime(),
144+
new Date(job[end]).getTime()
133145
],
134-
fillColor: taskColours[taskNameList[i]],
135-
})
146+
fillColor,
147+
}
136148
}
137-
}
149+
)
138150
}
139151
return [{ data }]
140152
},
@@ -147,6 +159,8 @@ export default {
147159
},
148160
149161
chartOptions () {
162+
const { displayedJobs } = this
163+
const { start, end } = timingOptions.get(this.timingOption)
150164
return {
151165
chart: {
152166
animations: {
@@ -170,16 +184,19 @@ export default {
170184
},
171185
},
172186
tooltip: {
173-
custom: function ({ seriesIndex, dataPointIndex, w }) {
174-
const startTime = new Date(w.config.series[seriesIndex].data[dataPointIndex].y[0])
175-
const finishTime = new Date(w.config.series[seriesIndex].data[dataPointIndex].y[1])
187+
custom ({ dataPointIndex }) {
188+
const job = displayedJobs[dataPointIndex]
189+
const { relativeID } = new Tokens(job.id)
176190
return (
177191
'<div class="apexcharts-tooltip-candlestick">' +
192+
'<div>Job: <span class="value">' +
193+
relativeID +
194+
'</span></div>' +
178195
'<div>Start: <span class="value">' +
179-
startTime +
196+
job[start] +
180197
'</span></div>' +
181198
'<div>Finish: <span class="value">' +
182-
finishTime +
199+
job[end] +
183200
'</span></div>' +
184201
'</div>'
185202
)

0 commit comments

Comments
 (0)