Skip to content

Commit

Permalink
some defensive coding for badly formed or erroneous data
Browse files Browse the repository at this point in the history
  • Loading branch information
thegrubbsian committed Jun 19, 2010
1 parent ba44ca5 commit 101796a
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions jquery.ganttView.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,27 +162,30 @@ slideWidth: number
for (var j = 0; j < data[i].series.length; j++) {
var series = data[i].series[j];
var size = DateUtils.daysBetween(series.start, series.end);
var offset = DateUtils.daysBetween(start, series.start);
var blockDiv = jQuery("<div>", {
"class": "ganttview-block",
"title": series.name + ", " + size + " days",
"css": {
"width": ((size * cellWidth) - 9) + "px",
"margin-left": ((offset * cellWidth) + 3) + "px"
}
}).data("block-data", {
id: data[i].id,
itemName: data[i].name,
seriesName: series.name,
start: Date.parse(series.start),
end: Date.parse(series.end),
color: series.color
});
if (data[i].series[j].color) {
blockDiv.css("background-color", data[i].series[j].color);
}
blockDiv.append($("<div>", { "class": "ganttview-block-text" }).text(size));
jQuery(rows[rowIdx]).append(blockDiv);
if (size && size > 0) {
if (size > 365) { size = 365; } // Keep blocks from overflowing a year
var offset = DateUtils.daysBetween(start, series.start);
var blockDiv = jQuery("<div>", {
"class": "ganttview-block",
"title": series.name + ", " + size + " days",
"css": {
"width": ((size * cellWidth) - 9) + "px",
"margin-left": ((offset * cellWidth) + 3) + "px"
}
}).data("block-data", {
id: data[i].id,
itemName: data[i].name,
seriesName: series.name,
start: Date.parse(series.start),
end: Date.parse(series.end),
color: series.color
});
if (data[i].series[j].color) {
blockDiv.css("background-color", data[i].series[j].color);
}
blockDiv.append($("<div>", { "class": "ganttview-block-text" }).text(size));
jQuery(rows[rowIdx]).append(blockDiv);
}
rowIdx = rowIdx + 1;
}
}
Expand Down Expand Up @@ -215,6 +218,7 @@ slideWidth: number

var DateUtils = {
daysBetween: function (start, end) {
if (!start || !end) return 0;
start = Date.parse(start); end = Date.parse(end);
var count = 0, date = start.clone();
while (date.compareTo(end) == -1) { count = count + 1; date.addDays(1); }
Expand Down

0 comments on commit 101796a

Please sign in to comment.