Skip to content

Commit d359c46

Browse files
committed
Increase visibility of hovered task and its info
1 parent 757a35e commit d359c46

File tree

1 file changed

+104
-17
lines changed

1 file changed

+104
-17
lines changed

app.js

Lines changed: 104 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ var app = {
3636
u: 150, // Tasks/Machines top line
3737
wmax: 0,
3838
scale: 1,
39+
iHovered: null,
40+
tHoverDelay: null,
3941

4042
// config
4143
displayLog: true,
@@ -50,6 +52,7 @@ var app = {
5052

5153
init: function(){
5254
app.cnv = $("cnvsChart");
55+
app.cnv.r = app.cnv.getBoundingClientRect();
5356
app.w = parseInt(app.cnv.width);
5457
app.h = parseInt(app.cnv.height);
5558
app.ctx = app.cnv.getContext("2d");
@@ -106,7 +109,14 @@ var app = {
106109
}
107110
}
108111
}
109-
}
112+
};
113+
114+
app.cnv.addEventListener('mousemove', function(ev){
115+
clearTimeout(app.tHoverDelay);
116+
app.tHoverDelay = setTimeout(function(){
117+
app.mouseMove(ev);
118+
}, app.iHovered === null? 15 : 10);
119+
}, false);
110120

111121
app.setAlgorithm("P|pj=1,in-tree|Lmax");
112122
app.start();
@@ -641,6 +651,7 @@ var app = {
641651
var bSplitted,aRGB;
642652
var iMax = [];
643653
for(var i=0,ii=app.T.length;i<ii;i++){
654+
app.T[i].coords = [];
644655
iMax[i] = true;
645656
for(var j=0;j<ii;j++)
646657
if((app.T[i].i == app.T[j].i) && (app.T[i].c < app.T[j].c)){
@@ -649,8 +660,17 @@ var app = {
649660
}
650661
for(var i=0,ii=app.T.length;i<ii;i++){
651662
aRGB = app.getColor(i);
652-
app.T[i].drawDeadlineLine(aRGB[0],aRGB[1],aRGB[2]);
653-
app.T[i].drawDeadlineMark(aRGB[0],aRGB[1],aRGB[2]);
663+
if(app.iHovered === null || app.iHovered !== app.T[i].i) {
664+
app.T[i].drawDeadlineLine(aRGB[0],aRGB[1],aRGB[2]);
665+
app.T[i].drawDeadlineMark(aRGB[0],aRGB[1],aRGB[2]);
666+
}
667+
}
668+
for(var i=0,ii=app.T.length;i<ii;i++){
669+
aRGB = app.getColor(i);
670+
if(app.iHovered && app.iHovered === app.T[i].i) {
671+
app.T[i].drawDeadlineLine(aRGB[0],aRGB[1],aRGB[2]);
672+
app.T[i].drawDeadlineMark(aRGB[0],aRGB[1],aRGB[2]);
673+
}
654674
}
655675
for(var i=0,ii=app.T.length;i<ii;i++){
656676
aRGB = app.getColor(i);
@@ -930,6 +950,57 @@ var app = {
930950
if(sValidChars.indexOf(sChar) == -1) bResult = false;
931951
}
932952
return bResult;
953+
},
954+
955+
setHoveredTask: function(x,y){
956+
var H = null;
957+
free: for(var i=0,ii=app.T.length;i<ii;i++){
958+
var T = app.T[i];
959+
for(var j=0,jj=T.coords.length;j<jj;j++){
960+
var c = T.coords[j];
961+
if(y>=c[1] && y<=c[3] && x<=c[2] && x>=c[0]) {
962+
H = T;
963+
break free;
964+
}
965+
}
966+
}
967+
var hi = H ? H.i : null;
968+
for(var i=0,ii=app.T.length;i<ii;i++){
969+
app.T[i].hovered = app.T[i].i === hi;
970+
}
971+
return H;
972+
},
973+
974+
mouseMove: function(ev) {
975+
var c = app.cnv;
976+
var r = app.cnv.r;
977+
var x = parseInt((ev.clientX - r.left) / (r.right - r.left) * c.width);
978+
var y = parseInt((ev.clientY - r.top) / (r.bottom - r.top) * c.height);
979+
var T = app.setHoveredTask(x,y);
980+
var draw = false;
981+
if(T){
982+
if(T.i !== app.iHovered){
983+
app.iHovered = T.i;
984+
draw = true;
985+
}
986+
if(!app.bCursorPoiner) {
987+
app.bCursorPoiner = true;
988+
app.cnv.style.cursor = "pointer";
989+
}
990+
} else {
991+
if(app.iHovered) {
992+
app.iHovered = null;
993+
draw = true;
994+
}
995+
if(app.bCursorPoiner) {
996+
app.bCursorPoiner = false;
997+
app.cnv.style.cursor = "default";
998+
}
999+
}
1000+
1001+
if(draw) {
1002+
app.drawChart();
1003+
}
9331004
}
9341005
};
9351006

@@ -993,25 +1064,36 @@ Task.prototype.drawTask = function(r,g,b){
9931064
}
9941065

9951066
// write ri
996-
if(["1||Lmax", "P|pj=1,in-tree|Lmax"].inArray(app.sAlgorithm)){
997-
this.drawInfo("rj",scale*this.r+f+5, f+20,true);
998-
} else {
999-
this.drawInfo("r",scale*this.r+f+5, f+20,false);
1067+
if(app.iHovered === null || app.iHovered === this.i) {
1068+
if(["1||Lmax", "P|pj=1,in-tree|Lmax"].inArray(app.sAlgorithm)){
1069+
this.drawInfo("rj",scale*this.r+f+5, f+20,true);
1070+
} else {
1071+
this.drawInfo("r",scale*this.r+f+5, f+20,false);
1072+
}
10001073
}
10011074

1075+
// store Task part coords
1076+
var x1 = parseInt(scale*this.s+f);
1077+
var y1 = parseInt(ti*20+f+u);
1078+
var w = parseInt(scale*this.p);
1079+
var h = 20;
1080+
this.coords.push([x1,y1,x1+w,y1+h]);
1081+
10021082
// draw Task rectangle
10031083
ctx.beginPath();
1004-
ctx.fillStyle = "rgb("+r+","+g+","+b+")";
1005-
ctx.fillRect(scale*this.s+f, ti*20+f+u, scale*this.p, 20);
1084+
ctx.fillStyle = this.hovered ? "rgb(255,255,255)" : "rgb("+r+","+g+","+b+")";
1085+
ctx.fillRect(x1,y1,w,h);
10061086

10071087
// draw Lateness mark, write Lj
10081088
if(app.displayLateness && this.L > 0){
10091089
ctx.fillStyle = "rgb(204,255,204)";
10101090
ctx.fillRect(scale*this.s+f+2, ti*20+f+u+2,7,16);
1011-
if(!app.bOneLine) {
1012-
this.drawInfo("L",scale*this.s+f+20, (1+ti)*20+f+u+10,true);
1013-
} else {
1014-
this.drawInfo("L",scale*this.s+f+20, (app.iM+1)*20+f+u+10,true);
1091+
if(app.iHovered === null || app.iHovered === this.i) {
1092+
if(!app.bOneLine) {
1093+
this.drawInfo("L",scale*this.s+f+20, (1+ti)*20+f+u+10,true);
1094+
} else {
1095+
this.drawInfo("L",scale*this.s+f+20, (app.iM+1)*20+f+u+10,true);
1096+
}
10151097
}
10161098
}
10171099

@@ -1052,26 +1134,31 @@ Task.prototype.drawDeadlineLine = function(r,g,b,sStyle){
10521134
case"d:n": // none
10531135
break;
10541136
}
1055-
ctx.strokeStyle = "rgb("+r+","+g+","+b+")";
1137+
ctx.strokeStyle = /* this.hovered ? "rgb(255,255,255)" : */ "rgb("+r+","+g+","+b+")";
10561138
ctx.stroke();
10571139
ctx.strokeStyle = "rgb(0,0,0)";
10581140
ctx.globalAlpha = 1;
10591141
};
10601142

10611143
Task.prototype.drawDeadlineMark = function(r,g,b){
10621144
var ctx = app.ctx, f = app.f, scale = app.scale;
1063-
ctx.globalAlpha = 0.6;
1145+
ctx.globalAlpha = this.hovered ? 1 : 0.5;
10641146
ctx.beginPath();
10651147
ctx.arc(scale*this.d+f,f,4,0,Math.PI*2,true);
1066-
ctx.fillStyle = "rgb("+r+","+g+","+b+")";
1148+
ctx.fillStyle = this.hovered ? "rgb(255,255,255)" : "rgb("+r+","+g+","+b+")";
10671149
ctx.fill();
10681150
ctx.globalAlpha = 1;
1069-
this.drawInfo("d",scale*this.d+f,f+20,false,false);
1151+
if(app.iHovered === null || app.iHovered === this.i) {
1152+
this.drawInfo("d",scale*this.d+f,f+20,false,false);
1153+
}
10701154
};
10711155

10721156
Task.prototype.drawInfo = function(sInfo,x,y,bConst,bForceWrite,sColor){
10731157
sColor = sColor || "rgb(0,0,0)";
10741158
bForceWrite = bForceWrite || false;
1159+
if(app.iHovered === this.i){
1160+
bConst = true;
1161+
}
10751162
var info;
10761163
var sParam = sInfo;
10771164
var sIndex = ""+this.i;

0 commit comments

Comments
 (0)