Skip to content

Commit d220a7f

Browse files
author
Roberto Bicchierai
committed
gantt: slow scroll on ff
1 parent b13e4a5 commit d220a7f

5 files changed

Lines changed: 60 additions & 39 deletions

File tree

ganttDrawer.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ function Ganttalendar(zoom, startmillis, endMillis, master, minGanttSize) {
2828
this.minGanttSize = minGanttSize;
2929
this.includeToday=true; //when true today is always visible. If false boundaries comes from tasks periods
3030

31-
//this.zoomLevels = ["d","w","m","q","s","y"];
32-
this.zoomLevels = ["w","m","q","s","y"];
31+
this.zoomLevels = ["d","w", "m", "q", "s", "y"];
3332

3433
this.element = this.create(zoom, startmillis, endMillis);
3534

@@ -68,6 +67,10 @@ Ganttalendar.prototype.create = function(zoom, originalStartmillis, originalEndM
6867
start.setHours(0, 0, 0, 0);
6968
end.setHours(23, 59, 59, 999);
7069

70+
start.setFirstDayOfThisWeek();
71+
end.setFirstDayOfThisWeek();
72+
end.setDate(end.getDate() + 6);
73+
7174
//reset day of week
7275
} else if (zoomLevel == "w") {
7376
start.setHours(0, 0, 0, 0);
@@ -226,28 +229,30 @@ Ganttalendar.prototype.create = function(zoom, originalStartmillis, originalEndM
226229

227230
//week
228231
} else if (zoom == "w") {
229-
computedTableWidth = Math.floor(((endPeriod - startPeriod) / (3600000 * 24)) * 30); //1 day= 30px
232+
computedTableWidth = Math.floor(((endPeriod - startPeriod) / (3600000 * 24)) * 40); //1 day= 40px
230233
iterate(function(date) {
231234
var end = new Date(date.getTime());
232235
end.setDate(end.getDate() + 6);
233236
tr1.append(createHeadCell(date.format("MMM d") + " - " + end.format("MMM d'yy"), 7));
234237
date.setDate(date.getDate() + 7);
235238
}, function(date) {
236-
tr2.append(createHeadCell(date.format("EEEE").substr(0, 1), 1, isHoliday(date) ? "holyH" : null,30));
239+
tr2.append(createHeadCell(date.format("EEEE").substr(0, 1), 1, isHoliday(date) ? "holyH" : null, 40));
237240
trBody.append(createBodyCell(1, date.getDay() % 7 == (self.master.firstDayOfWeek + 6) % 7, isHoliday(date) ? "holy" : null));
238241
date.setDate(date.getDate() + 1);
239242
});
240243

241244
//days
242245
} else if (zoom == "d") {
243-
computedTableWidth = Math.floor(((endPeriod - startPeriod) / (3600000 * 24)) * 200); //1 day= 200px
246+
computedTableWidth = Math.floor(((endPeriod - startPeriod) / (3600000 * 24)) * 100); //1 day= 100px
244247
iterate(function(date) {
245-
tr1.append(createHeadCell(date.format("EEEE d MMMM yyyy"), 4, isHoliday(date) ? "holyH" : null));
248+
var end = new Date(date.getTime());
249+
end.setDate(end.getDate() + 6);
250+
tr1.append(createHeadCell(date.format("MMMM d") + " - " + end.format("MMMM d yyyy"), 7));
251+
date.setDate(date.getDate() + 7);
252+
}, function (date) {
253+
tr2.append(createHeadCell(date.format("EEE d"), 1, isHoliday(date) ? "holyH" : null, 100));
254+
trBody.append(createBodyCell(1, date.getDay() % 7 == (self.master.firstDayOfWeek + 6) % 7, isHoliday(date) ? "holy" : null));
246255
date.setDate(date.getDate() + 1);
247-
}, function(date) {
248-
tr2.append(createHeadCell(date.format("HH"), 1, isHoliday(date) ? "holyH" : null),200);
249-
trBody.append(createBodyCell(1, date.getHours() > 17, isHoliday(date) ? "holy" : null));
250-
date.setHours(date.getHours() + 6);
251256
});
252257

253258
} else {

ganttDrawerSVG.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ function Ganttalendar(zoom, startmillis, endMillis, master, minGanttSize) {
3333
this.minGanttSize = minGanttSize;
3434
this.includeToday = true; //when true today is always visible. If false boundaries comes from tasks periods
3535

36-
//this.zoomLevels = ["d","w","m","q","s","y"];
37-
this.zoomLevels = ["w", "m", "q", "s", "y"];
36+
this.zoomLevels = ["d","w", "m", "q", "s", "y"];
3837

3938
this.element = this.create(zoom, startmillis, endMillis);
4039

@@ -75,6 +74,11 @@ Ganttalendar.prototype.create = function (zoom, originalStartmillis, originalEnd
7574
start.setHours(0, 0, 0, 0);
7675
end.setHours(23, 59, 59, 999);
7776

77+
start.setFirstDayOfThisWeek();
78+
end.setFirstDayOfThisWeek();
79+
end.setDate(end.getDate() + 6);
80+
81+
7882
//reset day of week
7983
} else if (zoomLevel == "w") {
8084
start.setHours(0, 0, 0, 0);
@@ -233,28 +237,30 @@ Ganttalendar.prototype.create = function (zoom, originalStartmillis, originalEnd
233237

234238
//week
235239
} else if (zoom == "w") {
236-
computedTableWidth = Math.floor(((endPeriod - startPeriod) / (3600000 * 24)) * 30); //1 day= 30px
240+
computedTableWidth = Math.floor(((endPeriod - startPeriod) / (3600000 * 24)) * 40); //1 day= 40px
237241
iterate(function (date) {
238242
var end = new Date(date.getTime());
239243
end.setDate(end.getDate() + 6);
240244
tr1.append(createHeadCell(date.format("MMM d") + " - " + end.format("MMM d'yy"), 7));
241245
date.setDate(date.getDate() + 7);
242246
}, function (date) {
243-
tr2.append(createHeadCell(date.format("EEEE").substr(0, 1), 1, isHoliday(date) ? "holyH" : null, 30));
247+
tr2.append(createHeadCell(date.format("EEEE").substr(0, 1), 1, isHoliday(date) ? "holyH" : null, 40));
244248
trBody.append(createBodyCell(1, date.getDay() % 7 == (self.master.firstDayOfWeek + 6) % 7, isHoliday(date) ? "holy" : null));
245249
date.setDate(date.getDate() + 1);
246250
});
247251

248252
//days
249253
} else if (zoom == "d") {
250-
computedTableWidth = Math.floor(((endPeriod - startPeriod) / (3600000 * 24)) * 200); //1 day= 200px
254+
computedTableWidth = Math.floor(((endPeriod - startPeriod) / (3600000 * 24)) * 100); //1 day= 100px
251255
iterate(function (date) {
252-
tr1.append(createHeadCell(date.format("EEEE d MMMM yyyy"), 4, isHoliday(date) ? "holyH" : null));
253-
date.setDate(date.getDate() + 1);
256+
var end = new Date(date.getTime());
257+
end.setDate(end.getDate() + 6);
258+
tr1.append(createHeadCell(date.format("MMMM d") + " - " + end.format("MMMM d yyyy"), 7));
259+
date.setDate(date.getDate() + 7);
254260
}, function (date) {
255-
tr2.append(createHeadCell(date.format("HH"), 1, isHoliday(date) ? "holyH" : null), 200);
256-
trBody.append(createBodyCell(1, date.getHours() > 17, isHoliday(date) ? "holy" : null));
257-
date.setHours(date.getHours() + 6);
261+
tr2.append(createHeadCell(date.format("EEE d"), 1, isHoliday(date) ? "holyH" : null, 100));
262+
trBody.append(createBodyCell(1, date.getDay() % 7 == (self.master.firstDayOfWeek + 6) % 7, isHoliday(date) ? "holy" : null));
263+
date.setDate(date.getDate() + 1);
258264
});
259265

260266
} else {
@@ -418,7 +424,6 @@ Ganttalendar.prototype.drawTask = function (task) {
418424
self.resDrop=true; //hack to avoid select
419425
var taskbox = $(this);
420426
var task = self.master.getTask(taskbox.attr("taskid"));
421-
422427
var s = Math.round((parseFloat(taskbox.attr("x")) / self.fx) + self.startMillis);
423428
self.master.beginTransaction();
424429
self.master.moveTask(task, new Date(s));
@@ -429,7 +434,6 @@ Ganttalendar.prototype.drawTask = function (task) {
429434
$(".ganttSVGBox .focused").removeClass("focused");
430435
var taskbox = $(this);
431436
var text=$(self.svg.text(parseInt(taskbox.attr("x"))+parseInt(taskbox.attr("width")+5), parseInt(taskbox.attr("y")),"", {stroke:"#888", "font-size":"12px"}));
432-
433437
taskBox.data("textDur",text);
434438
},
435439
resize: function (e) {
@@ -470,14 +474,12 @@ Ganttalendar.prototype.drawTask = function (task) {
470474
self.linkFromEnd=$(this).is(".taskLinkEndSVG");
471475
svg.addClass("linkOnProgress");
472476

473-
474477
// create the line
475478
var startX = parseFloat(taskBox.attr("x")) + (self.linkFromEnd? parseFloat(taskBox.attr("width")) :0);
476479
var startY = parseFloat(taskBox.attr("y")) + parseFloat(taskBox.attr("height")) / 2;
477480
var line = self.svg.line(startX, startY, e.pageX - offs.left - 5, e.pageY - offs.top - 5, {class:"linkLineSVG"});
478481
var circle = self.svg.circle(startX, startY, 5, {class:"linkLineSVG"});
479482

480-
481483
//bind mousemove to draw a line
482484
svg.bind("mousemove.linkSVG", function (e) {
483485
var offs = svg.offset();

ganttMaster.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,14 @@ GanttMaster.prototype.init = function (place) {
118118
});
119119

120120
//keyboard management bindings
121-
$("body").bind("keyup.body", function (e) {
121+
$("body").bind("keydown.body", function (e) {
122122
//console.debug(e.keyCode+ " "+e.target.nodeName)
123123

124124
//manage only events for body -> not from inputs
125125
if (e.target.nodeName.toLowerCase() == "body" || e.target.nodeName.toLowerCase() == "svg") { // chrome,ff receive "body" ie "svg"
126-
e.preventDefault();
127-
e.stopPropagation();
128126
//something focused?
129127
//console.debug(e.keyCode, e.ctrlKey)
128+
var eventManaged=true;
130129
switch (e.keyCode) {
131130
case 46: //del
132131
case 8: //backspace
@@ -184,11 +183,22 @@ GanttMaster.prototype.init = function (place) {
184183
if (e.ctrlKey) {
185184
self.redo();
186185
}
186+
break;
187187

188188
case 90: //Z
189189
if (e.ctrlKey) {
190190
self.undo();
191191
}
192+
break;
193+
194+
default :{
195+
eventManaged=false;
196+
}
197+
198+
}
199+
if (eventManaged){
200+
e.preventDefault();
201+
e.stopPropagation();
192202
}
193203
}
194204
});

ganttTask.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,8 @@ Task.prototype.indent = function() {
756756
}
757757

758758
var parent = this.getParent();
759-
if(parent && this.start < parent.start && parent.depends && !this.depends){
759+
// set start date to parent' start if no deps
760+
if(parent && !this.depends){
760761
var new_end = computeEndByDuration(parent.start, this.duration);
761762
this.master.changeTaskDates(this, parent.start, new_end);
762763
}

ganttUtilities.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,24 @@ $.splittify = {
176176
// keep both side in synch when scroll
177177
var stopScroll=false;
178178
var fs=firstBox.add(secondBox);
179-
fs.scroll(function() {
180-
if (!stopScroll){
181-
var top = $(this).scrollTop();
182-
stopScroll=true;
183-
if ($(this).is(".splitBox1"))
184-
secondBox.scrollTop(top);
185-
else
186-
firstBox.scrollTop(top);
187-
firstBox.find(".fixHead").css('top',top);
188-
secondBox.find(".fixHead").css('top',top);
179+
fs.scroll(function(e) {
180+
var el = $(this);
181+
var top = el.scrollTop();
182+
if (el.is(".splitBox1") && stopScroll!="splitBox2"){
183+
stopScroll="splitBox1";
184+
secondBox.scrollTop(top);
185+
}else if (el.is(".splitBox2") && stopScroll!="splitBox1"){
186+
stopScroll="splitBox2";
187+
firstBox.scrollTop(top);
189188
}
190-
stopScroll=false;
189+
secondBox.find(".fixHead").css('top', top);
190+
firstBox.find(".fixHead").css('top', top);
191+
192+
where.stopTime("reset").oneTime(100,"reset",function(){stopScroll="";})
191193
});
192194

193195

196+
194197
function Splitter(element,firstBox, secondBox, splitterBar) {
195198
this.element=element;
196199
this.firstBox = firstBox;

0 commit comments

Comments
 (0)