Skip to content

Commit 14d2341

Browse files
authored
Merge pull request #2 from jsGanttImproved/master
Update from jsGanttImproved
2 parents e8f3fb4 + 9cc17e6 commit 14d2341

File tree

12 files changed

+517
-407
lines changed

12 files changed

+517
-407
lines changed

Documentation.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ The following options take a single numeric parameter; a value of 1 will enable
299299
|_setShowEndWeekDate():_|Controls whether the major heading in "Day" view displays the week end-date in the appropriate format (see [below](#user-content-display-date-formats)), defaults to 1 (show date)|
300300
|_setShowWeekends():_|Controls whether shows the weekend days in the Day view Format, defaults to 1 (show weekends)|
301301
|_setShowDeps():_ |Controls display of dependancy lines, defaults to 1 (show dependencies)|
302-
|_setEvents():_ |Controls events when a task is click in table data. You have to pass an object with the column and function. ex.: ` vEvents: { taskname: console.log, res: console.log }`|
302+
|_setEvents():_ |Controls events when a task is click in table data. You have to pass an object with the column and function. If the user click in the header, the event willbe triggered btu instead of the task will be a object about the header. ex.: ` vEvents: { taskname: console.log, res: console.log }`|
303303
|_setEventClickRow():_ |Controls events when a task row is clicked. Pass a function to execute ex.: `vEventClickRow: function(e){console.log(e)}`|
304304
|setEventClickCollapse():_ |Controls events when a group task is collapsed (open or close events). Pass a function to execute ex.: `vEventClickCollapse: function(e){console.log(e)}`|
305305
|_setEventsChange():_ |Controls events when a task row is cliked. Pass a function to execute ex.: `vEventsChange: { taskname: function(task, event, cell, column){ console.log(task, event, cell, column); } }`|
@@ -505,6 +505,7 @@ g.setOptions({
505505
planstart: console.log,
506506
planend: console.log,
507507
cost: console.log,
508+
additional_category: console.log, // for additional fields
508509
beforeDraw: ()=>console.log('before draw listener'),
509510
afterDraw: ()=>console.log('before after listener')
510511
},

dist/jsgantt.css

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ div.gantt {
2525
.gminorheading,
2626
.gminorheadingwkend,
2727
.gtaskcell,
28+
.gtaskcellcurrent,
2829
.gtaskcellwkend {
2930
height: 19px;
3031
font-size: 12px;
@@ -43,6 +44,9 @@ div.gantt {
4344
border-right: none;
4445
}
4546

47+
.gtasknolist-label{
48+
padding: 10px 50px;
49+
}
4650
/* all three width values set just to make sure - helps resizing code */
4751

4852
/* Additional values for some cell elements */
@@ -57,13 +61,18 @@ div.gantt {
5761
}
5862

5963
.gtaskcellwkend,
64+
.gtaskcellcurrent,
6065
.gminorheadingwkend {
6166
background-color: #f7f7f7;
6267
font-weight: bold;
6368
font-size: 9px;
6469
white-space: nowrap;
6570
}
6671

72+
.gtaskcellcurrent {
73+
background-color: #e1e0f7;
74+
}
75+
6776
td.gtaskcell {
6877
text-align: left;
6978
}
@@ -82,9 +91,9 @@ td.gspanning {
8291
.gtaskheading,
8392
.gname,
8493
.gtaskname,
85-
.gresource,
86-
.gduration,
87-
.gpccomplete,
94+
.gres,
95+
.gdur,
96+
.gcomp,
8897
.gstartdate,
8998
.gplanstartdate,
9099
.gplanenddate,
@@ -98,9 +107,9 @@ td.gspanning {
98107
.gtaskheading div,
99108
.gname div,
100109
.gtaskname div,
101-
.gresource div,
102-
.gduration div,
103-
.gpccomplete div,
110+
.gres div,
111+
.gdur div,
112+
.gcomp div,
104113
.gstartdate div,
105114
.gplanstartdate div,
106115
.gplanenddate div,
@@ -756,9 +765,9 @@ td.gspanning div {
756765
}
757766

758767
.gadditional,
759-
.gresource,
760-
.gduration,
761-
.gpccomplete,
768+
.gres,
769+
.gdur,
770+
.gcomp,
762771
.gcost {
763772
text-align: center;
764773
width: 70px;

dist/jsgantt.js

Lines changed: 159 additions & 128 deletions
Large diffs are not rendered by default.

docs/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function start(e) {
8686
planstart: console.log,
8787
planend: console.log,
8888
cost: console.log,
89+
additional_category: console.log,
8990
beforeDraw: () => console.log('before draw listener'),
9091
afterDraw: () => {
9192
console.log('after draw listener');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsgantt-improved",
3-
"version": "2.6.4",
3+
"version": "2.7.2",
44
"description": "jsgantt-improved",
55
"main": "dist/index.js",
66
"scripts": {

src/draw.ts

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ import {
1515
removeListener
1616
} from './events';
1717
import {
18+
calculateCurrentDateOffset,
1819
getOffset, getScrollbarWidth
1920
} from './utils/general_utils';
2021
import { createTaskInfo, AddTaskItem, AddTaskItemObject, RemoveTaskItem, processRows, ClearTasks } from './task';
2122

2223
import { getXMLProject, getXMLTask } from './xml';
23-
import { COLUMN_ORDER, draw_list_headings, draw_header, draw_bottom, draw_task_headings } from './draw_columns';
24+
import { COLUMN_ORDER, draw_header, draw_bottom, draw_task_headings } from './draw_columns';
2425
import { newNode, makeInput, getArrayLocationByID, CalcTaskXY, sLine, drawSelector } from './utils/draw_utils';
2526
import { drawDependency, DrawDependencies } from './draw_dependencies';
2627
import { includeGetSet } from './options';
@@ -208,7 +209,7 @@ export const GanttChart = function (pDiv, pFormat) {
208209

209210
this.getColumnOrder().forEach(column => {
210211
if (this[column] == 1 || column === 'vAdditionalHeaders') {
211-
draw_task_headings(column, vTmpRow, this.vLangs, this.vLang, this.vAdditionalHeaders);
212+
draw_task_headings(column, vTmpRow, this.vLangs, this.vLang, this.vAdditionalHeaders, this.vEvents);
212213
}
213214
});
214215
return gListLbl;
@@ -291,6 +292,19 @@ export const GanttChart = function (pDiv, pFormat) {
291292
}
292293
}
293294

295+
// Render no daa in the chart
296+
if (this.vTaskList.length == 0) {
297+
298+
let totalColumns = this.getColumnOrder()
299+
.filter(column => this[column] == 1 || column === 'vAdditionalHeaders')
300+
.length
301+
let vTmpRow = newNode(vTmpContentTBody, 'tr', this.vDivId + 'child_', 'gname ');
302+
// this.vTaskList[i].setListChildRow(vTmpRow);
303+
let vTmpCell = newNode(vTmpRow, 'td', null, 'gtasknolist', '', null, null, null, totalColumns);
304+
let vOutput = document.createDocumentFragment();
305+
newNode(vOutput, 'div', null, 'gtasknolist-label', this.vLangs[this.vLang]['nodata'] + '.');
306+
vTmpCell.appendChild(vOutput);
307+
}
294308
// DRAW the date format selector at bottom left.
295309
let vTmpRow = newNode(vTmpContentTBody, 'tr');
296310
newNode(vTmpRow, 'td', null, 'gtasklist', '\u00A0');
@@ -490,7 +504,7 @@ export const GanttChart = function (pDiv, pFormat) {
490504
*
491505
*/
492506
this.drawCharBody = function (vTaskLeftPx, vTmpContentTabWrapper, gChartLbl, gListLbl,
493-
vMinDate, vSingleCell, vNumCols, vColWidth, vDateRow) {
507+
vMinDate, vMaxDate, vSingleCell, vNumCols, vColWidth, vDateRow) {
494508
let vRightTable = document.createDocumentFragment();
495509
const vTmpDiv = newNode(vRightTable, 'div', this.vDivId + 'gchartbody', 'gchartgrid gcontainercol');
496510
this.setChartBody(vTmpDiv);
@@ -564,7 +578,7 @@ export const GanttChart = function (pDiv, pFormat) {
564578

565579
vCaptClass = 'gmilecaption';
566580
if (!vSingleCell && !vComb) {
567-
this.drawColsChart(vNumCols, vTmpRow, taskCellWidth)
581+
this.drawColsChart(vNumCols, vTmpRow, taskCellWidth, vMinDate, vMaxDate)
568582
}
569583
}
570584
else {
@@ -599,7 +613,7 @@ export const GanttChart = function (pDiv, pFormat) {
599613
}
600614

601615
if (!vSingleCell && !vComb) {
602-
this.drawColsChart(vNumCols, vTmpRow, taskCellWidth);
616+
this.drawColsChart(vNumCols, vTmpRow, taskCellWidth, vMinDate, vMaxDate);
603617
}
604618
}
605619
else {
@@ -656,8 +670,8 @@ export const GanttChart = function (pDiv, pFormat) {
656670
if (!vComb || (vComb && this.vTaskList[i].getParItem().getEnd() == this.vTaskList[i].getEnd())) vCaptClass = 'gcaption';
657671

658672
// Background cells
659-
if (!vSingleCell && !vComb) {
660-
if(vTmpRow) this.drawColsChart(vNumCols, vTmpRow, taskCellWidth);
673+
if (!vSingleCell && !vComb && vTmpRow) {
674+
this.drawColsChart(vNumCols, vTmpRow, taskCellWidth, vMinDate, vMaxDate);
661675
}
662676
}
663677
}
@@ -677,24 +691,28 @@ export const GanttChart = function (pDiv, pFormat) {
677691
if (this.vTaskList[i].getTaskDiv() && vTmpDiv) {
678692
const vTmpDiv2 = newNode(vTmpDiv, 'div', this.vDivId + 'tt' + vID, null, null, null, null, 'none');
679693
const { component, callback } = this.createTaskInfo(this.vTaskList[i], this.vTooltipTemplate);
680-
vTmpDiv2.appendChild(component);
694+
const el = document.createElement('div');
695+
el.appendChild(component);
696+
vTmpDiv2.setAttribute('data-tooltip', el.innerHTML)
681697
addTooltipListeners(this, this.vTaskList[i].getTaskDiv(), vTmpDiv2, callback);
682698
}
683699
// Add Plan Task Info div for tooltip
684700
if (this.vTaskList[i].getPlanTaskDiv() && vTmpDiv) {
685701
const vTmpDiv2 = newNode(vTmpDiv, 'div', this.vDivId + 'tt' + vID, null, null, null, null, 'none');
686702
const { component, callback } = this.createTaskInfo(this.vTaskList[i], this.vTooltipTemplate);
687-
vTmpDiv2.appendChild(component);
703+
const el = document.createElement('div');
704+
el.appendChild(component);
705+
vTmpDiv2.setAttribute('data-tooltip', el.innerHTML)
688706
addTooltipListeners(this, this.vTaskList[i].getPlanTaskDiv(), vTmpDiv2, callback);
689707
}
690708
}
691709

692710
// Include the footer with the days/week/month...
693711
if (vSingleCell) {
694-
const vTmpTFootTRow = newNode(vTmpTFoot, 'tr');
695-
const vTmpTFootTCell = newNode(vTmpTFootTRow, 'td', null, null, null, '100%');
696-
const vTmpTFootTCellTable = newNode(vTmpTFootTCell, 'table', null, 'gcharttableh', null, '100%');
697-
const vTmpTFootTCellTableTBody = newNode(vTmpTFootTCellTable, 'tbody');
712+
const vTmpTFootTRow = newNode(vTmpTFoot, 'tr');
713+
const vTmpTFootTCell = newNode(vTmpTFootTRow, 'td', null, null, null, '100%');
714+
const vTmpTFootTCellTable = newNode(vTmpTFootTCell, 'table', null, 'gcharttableh', null, '100%');
715+
const vTmpTFootTCellTableTBody = newNode(vTmpTFootTCellTable, 'tbody');
698716
vTmpTFootTCellTableTBody.appendChild(vDateRow.cloneNode(true));
699717
} else {
700718
vTmpTFoot.appendChild(vDateRow.cloneNode(true));
@@ -703,15 +721,34 @@ export const GanttChart = function (pDiv, pFormat) {
703721
return { vRightTable }
704722
}
705723

706-
this.drawColsChart = function(vNumCols, vTmpRow, taskCellWidth){
707-
let vCellFormat = '';
724+
this.drawColsChart = function (vNumCols, vTmpRow, taskCellWidth, pStartDate = null, pEndDate = null) {
725+
let columnCurrentDay = null;
726+
// Find the Current day cell to put a different class
727+
if (this.vShowWeekends !== false && pStartDate && pEndDate && (
728+
this.vFormat == 'day' || this.vFormat == 'week'
729+
)) {
730+
let curTaskStart = new Date(pStartDate.getTime());
731+
let curTaskEnd = new Date();
732+
let onePeriod = 3600000;
733+
if (this.vFormat == 'day') {
734+
onePeriod *= 24;
735+
} else if (this.vFormat == 'week') {
736+
onePeriod *= 24 * 7;
737+
}
738+
columnCurrentDay = Math.floor(calculateCurrentDateOffset(curTaskStart, curTaskEnd) / onePeriod) - 1;
739+
}
740+
708741
for (let j = 0; j < vNumCols - 1; j++) {
709-
if (this.vShowWeekends !== false && this.vFormat == 'day' && ((j % 7 == 4) || (j % 7 == 5))) vCellFormat = 'gtaskcellwkend';
710-
else vCellFormat = 'gtaskcell gtaskcellcols';
742+
let vCellFormat = 'gtaskcell gtaskcellcols';
743+
if (this.vShowWeekends !== false && this.vFormat == 'day' && ((j % 7 == 4) || (j % 7 == 5))) {
744+
vCellFormat = 'gtaskcellwkend';
745+
}
746+
//When is the column is the current day/week,give a different class
747+
else if ((this.vFormat == 'week' || this.vFormat == 'day') && j === columnCurrentDay) {
748+
vCellFormat = 'gtaskcellcurrent';
749+
}
711750
newNode(vTmpRow, 'td', null, vCellFormat, '\u00A0\u00A0', taskCellWidth);
712751
}
713-
714-
715752
}
716753

717754
/**
@@ -736,11 +773,6 @@ export const GanttChart = function (pDiv, pFormat) {
736773
console.info('before draw', bd);
737774
}
738775

739-
if (this.vTaskList.length === 0) {
740-
this.drawComplete(vMinDate, vColWidth, bd);
741-
return;
742-
}
743-
744776
// Process all tasks, reset parent date and completion % if task list has altered
745777
if (this.vProcessNeeded) processRows(this.vTaskList, 0, -1, 1, 1, this.getUseSort(), this.vDebug);
746778
this.vProcessNeeded = false;
@@ -784,7 +816,7 @@ export const GanttChart = function (pDiv, pFormat) {
784816
* CHART GRID
785817
*/
786818
const { vRightTable } = this.drawCharBody(vTaskLeftPx, vTmpContentTabWrapper, gChartLbl, gListLbl,
787-
vMinDate, vSingleCell, vNumCols, vColWidth, vDateRow)
819+
vMinDate, vMaxDate, vSingleCell, vNumCols, vColWidth, vDateRow)
788820

789821
if (this.vDebug) {
790822
const ad = new Date();
@@ -850,8 +882,9 @@ export const GanttChart = function (pDiv, pFormat) {
850882
this.getChartBody().scrollLeft = vScrollPx;
851883
}
852884

853-
if (vMinDate.getTime() <= (new Date()).getTime() && vMaxDate.getTime() >= (new Date()).getTime()) this.vTodayPx = getOffset(vMinDate, new Date(), vColWidth, this.vFormat, this.vShowWeekends);
854-
else this.vTodayPx = -1;
885+
if (vMinDate.getTime() <= (new Date()).getTime() && vMaxDate.getTime() >= (new Date()).getTime()) {
886+
this.vTodayPx = getOffset(vMinDate, new Date(), vColWidth, this.vFormat, this.vShowWeekends);
887+
} else this.vTodayPx = -1;
855888

856889
// DEPENDENCIES: Draw lines of Dependencies
857890
let bdd;

0 commit comments

Comments
 (0)