Skip to content

Commit

Permalink
Refactored headerRows usage
Browse files Browse the repository at this point in the history
  • Loading branch information
francisbesset committed Mar 16, 2015
1 parent 3a0028d commit c2e990a
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions js/jquery.fn.gantt.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,10 @@
// **Render the grid**
render: function (element) {
var content = $('<div class="fn-content"/>');

var $leftPanel = core.leftPanel(element);
content.append($leftPanel);

var $rightPanel = core.rightPanel(element, $leftPanel);
var mLeft, hPos;

Expand Down Expand Up @@ -320,7 +322,6 @@
/* Left panel */
var ganttLeftPanel = $('<div class="leftPanel"/>')
.append($('<div class="row spacer"/>')
.css("height", tools.getCellSize() * element.headerRows + "px")
.css("width", "100%"));

var entries = [];
Expand Down Expand Up @@ -409,7 +410,7 @@

// Creates and return the right panel containing the year/week/day
// header
rightPanel: function (element, leftPanel /* <- never used? */) {
rightPanel: function (element, $leftPanel) {

var range = null;
// Days of the week have a class of one of
Expand Down Expand Up @@ -552,6 +553,8 @@
dataPanel.append($('<div class="row"/>').html(dowArr.join("")));
dataPanel.append($('<div class="row"/>').html(horArr.join("")));

element.headerRows = 5;

break;

// **Weeks**
Expand Down Expand Up @@ -617,6 +620,8 @@

dataPanel.append(yearArr.join("") + monthArr.join("") + dayArr.join("") + (dowArr.join("")));

element.headerRows = 3;

break;

// **Months**
Expand Down Expand Up @@ -668,6 +673,8 @@
dataPanel.append($('<div class="row"/>').html(dayArr.join("")));
dataPanel.append($('<div class="row"/>').html(dowArr.join("")));

element.headerRows = 2;

break;

// **Days (default)**
Expand Down Expand Up @@ -746,9 +753,14 @@
dataPanel.append($('<div class="row" style="margin-left: 0;" />').html(dayArr.join("")));
dataPanel.append($('<div class="row" style="margin-left: 0;" />').html(dowArr.join("")));

element.headerRows = 4;

break;
}

// update height of spacer element
$leftPanel.find('.spacer').css("height", tools.getCellSize() * element.headerRows + "px")

return $('<div class="rightPanel"></div>').append(dataPanel);
},

Expand Down Expand Up @@ -1029,7 +1041,7 @@
// find row
var topEl = $(element).find("#rowheader" + i);

var top = tools.getCellSize() * 5 + 2 + parseInt(topEl.attr("offset"), 10);
var top = tools.getCellSize() * element.headerRows + 2 + parseInt(topEl.attr("offset"), 10);
_bar.css({ 'top': top, 'left': Math.floor(cFrom) });

datapanel.append(_bar);
Expand Down Expand Up @@ -1072,7 +1084,7 @@
// find row
var topEl = $(element).find("#rowheader" + i);

var top = tools.getCellSize() * 3 + 2 + parseInt(topEl.attr("offset"), 10);
var top = tools.getCellSize() * element.headerRows + 2 + parseInt(topEl.attr("offset"), 10);
_bar.css({ 'top': top, 'left': Math.floor(cFrom) });

datapanel.append(_bar);
Expand Down Expand Up @@ -1112,7 +1124,7 @@
// find row
var topEl = $(element).find("#rowheader" + i);

var top = tools.getCellSize() * 2 + 2 + parseInt(topEl.attr("offset"), 10);
var top = tools.getCellSize() * element.headerRows + 2 + parseInt(topEl.attr("offset"), 10);
_bar.css({ 'top': top, 'left': Math.floor(cFrom) });

datapanel.append(_bar);
Expand All @@ -1138,7 +1150,7 @@
// find row
var topEl = $(element).find("#rowheader" + i);

var top = tools.getCellSize() * 4 + 2 + parseInt(topEl.attr("offset"), 10);
var top = tools.getCellSize() * element.headerRows + 2 + parseInt(topEl.attr("offset"), 10);
_bar.css({ 'top': top, 'left': Math.floor(cFrom) });

datapanel.append(_bar);
Expand Down Expand Up @@ -1226,30 +1238,23 @@
var scaleSt = element.scaleStep + val * 3;
scaleSt = scaleSt <= 1 ? 1 : scaleSt === 4 ? 3 : scaleSt;
var scale = settings.scale;
var headerRows = element.headerRows;
if (settings.scale === "hours" && scaleSt >= 13) {
scale = "days";
headerRows = 4;
scaleSt = 13;
} else if (settings.scale === "days" && zoomIn) {
scale = "hours";
headerRows = 5;
scaleSt = 12;
} else if (settings.scale === "days" && !zoomIn) {
scale = "weeks";
headerRows = 3;
scaleSt = 13;
} else if (settings.scale === "weeks" && !zoomIn) {
scale = "months";
headerRows = 2;
scaleSt = 14;
} else if (settings.scale === "weeks" && zoomIn) {
scale = "days";
headerRows = 4;
scaleSt = 13;
} else if (settings.scale === "months" && zoomIn) {
scale = "weeks";
headerRows = 3;
scaleSt = 13;
}

Expand All @@ -1260,7 +1265,6 @@
}
element.scaleStep = scaleSt;
settings.scale = scale;
element.headerRows = headerRows;
var $rightPanel = $(element).find(".fn-gantt .rightPanel");
var $dataPanel = $rightPanel.find(".dataPanel");
element.hPosition = $dataPanel.css("margin-left").replace("px", "");
Expand Down Expand Up @@ -1730,11 +1734,11 @@
}

switch (settings.scale) {
//case "hours": this.headerRows = 5; this.scaleStep = 8; break;
case "hours": this.headerRows = 5; this.scaleStep = 1; break;
case "weeks": this.headerRows = 3; this.scaleStep = 13; break;
case "months": this.headerRows = 2; this.scaleStep = 14; break;
default: this.headerRows = 4; this.scaleStep = 13; break;
//case "hours": this.scaleStep = 8; break;
case "hours": this.scaleStep = 1; break;
case "weeks": this.scaleStep = 13; break;
case "months": this.scaleStep = 14; break;
default: this.scaleStep = 13; break;
}

this.scrollNavigation = {
Expand Down

0 comments on commit c2e990a

Please sign in to comment.