-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueRender.js
More file actions
70 lines (65 loc) · 2.78 KB
/
QueueRender.js
File metadata and controls
70 lines (65 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class QueueRender {
constructor(){
this.actualColor = -1
this.colors = ['#2ecc71', '#e67e22','#3498db', '#34495e','#9b59b6','#1abc9c', '#f1c40f', '#e74c3c', '#7f8c8d']
this.colWidth = 150
this.colHeight = 30
}
getNextColor(){
this.actualColor = (this.actualColor+1)%this.colors.length
return this.colors[this.actualColor]
}
invertColor(hexTripletColor) {
var color = hexTripletColor;
color = color.substring(1); // remove #
color = parseInt(color, 16); // convert to integer
color = 0xFFFFFF ^ color; // invert three bytes
color = color.toString(16); // convert to hex
color = ("000000" + color).slice(-6); // pad with leading zeros
color = "#" + color; // prepend #
return color;
}
render (id, queue) {
this.canvas = document.getElementById(id)
this.canvasContext = this.canvas.getContext('2d')
this.canvasContext.clearRect(0, 0, this.canvas.width, this.canvas.height);
// this.canvasContext.fillStyle = '#333'
// this.canvasContext.fillRect(0, 0, this.canvas.width, this.canvas.height)
this.colWidth = this.canvas.width / ((queue.length * 2 - 1) + 2)
var maior = 0
var menor = queue[0].tarefasAlocadas[0]
for(var i = 0 ; i < queue.length ; i++){
var totalTilHere = 0
for(var j = 0 ; j < queue[i].tarefasAlocadas.length ; j++){
totalTilHere += queue[i].tarefasAlocadas[j]
if(queue[i].tarefasAlocadas[j] < menor){
menor = queue[i].tarefasAlocadas[j]
}
}
if(totalTilHere > maior){
maior = totalTilHere
}
}
this.colHeight = (this.canvas.height-60) / maior
var font = this.colHeight*menor
if(this.colWidth < this.colHeight){
font = this.colWidth
}
if(font > 30){
font = 30
}
this.canvasContext.font= font+'px Arial'
for(var i = 0 ; i < queue.length ; i++){
var totalTilHere = 0
for(var j = 0 ; j < queue[i].tarefasAlocadas.length ; j++){
this.canvasContext.fillStyle = this.getNextColor()
this.canvasContext.fillRect((1+(i*2))*this.colWidth, this.canvas.height - (totalTilHere*this.colHeight) - (queue[i].tarefasAlocadas[j]*this.colHeight), this.colWidth, queue[i].tarefasAlocadas[j]*this.colHeight)
this.canvasContext.fillStyle = "#ddd"
this.canvasContext.fillText(queue[i].tarefasAlocadas[j], ((1+(i*2))*this.colWidth)+(this.colWidth/2)-10, this.canvas.height - (totalTilHere*this.colHeight) - ((queue[i].tarefasAlocadas[j]*this.colHeight)/2)+10)
totalTilHere += queue[i].tarefasAlocadas[j]
}
this.canvasContext.fillStyle = '#333'
this.canvasContext.fillText(queue[i].makespan, (1+(i*2))*this.colWidth, this.canvas.height - (totalTilHere*this.colHeight) - this.colHeight/2)
}
}
}