-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathjsgantt.js
2307 lines (1926 loc) · 85 KB
/
jsgantt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2009, Shlomy Gantz BlueBrick Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Shlomy Gantz or BlueBrick Inc. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY SHLOMY GANTZ/BLUEBRICK INC. ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL SHLOMY GANTZ/BLUEBRICK INC. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* JSGantt component is a UI control that displays gantt charts based by using CSS and HTML
* @module jsgantt
* @title JSGantt
*/
var JSGantt; if (!JSGantt) JSGantt = {};
var vTimeout = 0;
var vBenchTime = new Date().getTime();
/**
* Creates a task (one row) in gantt object
* @class TaskItem
* @namespace JSGantt
* @constructor
* @for JSGantt
* @param pID {Number} Task unique numeric ID
* @param pName {String} Task Name
* @param pStart {Date} Task start date/time (not required for pGroup=1 )
* @param pEnd {Date} Task end date/time, you can set the end time to 12:00 to indicate half-day (not required for pGroup=1 )
* @param pColor {String} Task bar RGB value
* @param pLink {String} Task URL, clicking on the task will redirect to this url. Leave empty if you do not with the Task also serve as a link
* @param pMile {Boolean} Determines whether task is a milestone (1=Yes,0=No)
* @param pRes {String} Resource to perform the task
* @param pComp {Number} Percent complete (Number between 0 and 100)
* @param pGroup {Boolean}
* @param pParent {Number} ID of the parent task
* @param pOpen {Boolean}
* @param pDepend {String} Comma seperated list of IDs this task depends on
* @param pCaption {String} Caption to be used instead of default caption (Resource).
* note : you should use setCaption("Caption") in order to display the caption
* @return void
*/
JSGantt.TaskItem = function(pID, pName, pStart, pEnd, pColor, pLink, pMile, pRes, pComp, pGroup, pParent, pOpen, pDepend, pCaption)
{
/**
* The name of the attribute.
* @property vID
* @type String
* @default pID
* @private
*/
var vID = pID;
/**
* @property vName
* @type String
* @default pName
* @private
*/
var vName = pName;
/**
* @property vStart
* @type Datetime
* @default new Date()
* @private
*/
var vStart = new Date();
/**
* @property vEnd
* @type Datetime
* @default new Date()
* @private
*/
var vEnd = new Date();
/**
* @property vColor
* @type String
* @default pColor
* @private
*/
var vColor = pColor;
/**
* @property vLink
* @type String
* @default pLink
* @private
*/
var vLink = pLink;
/**
* @property vMile
* @type Boolean
* @default pMile
* @private
*/
var vMile = pMile;
/**
* @property vRes
* @type String
* @default pRes
* @private
*/
var vRes = pRes;
/**
* @property vComp
* @type Number
* @default pComp
* @private
*/
var vComp = pComp;
/**
* @property vGroup
* @type Boolean
* @default pGroup
* @private
*/
var vGroup = pGroup;
/**
* @property vParent
* @type Number
* @default pParent
* @private
*/
var vParent = pParent;
/**
* @property vOpen
* @type Boolean
* @default pOpen
* @private
*/
var vOpen = pOpen;
/**
* @property vDepend
* @type String
* @default pDepend
* @private
*/
var vDepend = pDepend;
/**
* @property vCaption
* @type String
* @default pCaption
* @private
*/
var vCaption = pCaption;
/**
* @property vDuration
* @type Number
* @default ''
* @private
*/
var vDuration = '';
/**
* @property vLevel
* @type Number
* @default 0
* @private
*/
var vLevel = 0;
/**
* @property vNumKid
* @type Number
* @default 0
* @private
*/
var vNumKid = 0;
/**
* @property vVisible
* @type Boolean
* @default 0
* @private
*/
var vVisible = 1;
var x1, y1, x2, y2;
if (vGroup != 1)
{
vStart = JSGantt.parseDateStr(pStart,g.getDateInputFormat());
vEnd = JSGantt.parseDateStr(pEnd,g.getDateInputFormat());
}
/**
* Returns task ID
* @method getID
* @return {Number}
*/
this.getID = function(){ return vID };
/**
* Returns task name
* @method getName
* @return {String}
*/
this.getName = function(){ return vName };
/**
* Returns task start date
* @method getStart
* @return {Datetime}
*/
this.getStart = function(){ return vStart};
/**
* Returns task end date
* @method getEnd
* @return {Datetime}
*/ this.getEnd = function(){ return vEnd };
/**
* Returns task bar color (i.e. 00FF00)
* @method getColor
* @return {String}
*/ this.getColor = function(){ return vColor};
/**
* Returns task URL (i.e. http://www.jsgantt.com)
* @method getLink
* @return {String}
*/ this.getLink = function(){ return vLink };
/**
* Returns whether task is a milestone (1=Yes,0=No)
* @method getMile
* @return {Boolean}
*/ this.getMile = function(){ return vMile };
/**
* Returns task dependencies as list of values (i.e. 123,122)
* @method getDepend
* @return {String}
*/ this.getDepend = function(){ if(vDepend) return vDepend; else return null };
/**
* Returns task caption (if it exists)
* @method getCaption
* @return {String}
*/ this.getCaption = function(){ if(vCaption) return vCaption; else return ''; };
/**
* Returns task resource name as string
* @method getResource
* @return {String}
*/ this.getResource = function(){ if(vRes) return vRes; else return ' '; };
/**
* Returns task completion percent as numeric value
* @method getCompVal
* @return {Boolean}
*/ this.getCompVal = function(){ if(vComp) return vComp; else return 0; };
/**
* Returns task completion percent as formatted string (##%)
* @method getCompStr
* @return {String}
*/ this.getCompStr = function(){ if(vComp) return vComp+'%'; else return ''; };
/**
* Returns task duration as a fortmatted string based on the current selected format
* @method getDuration
* @param vFormat {String} selected format (minute,hour,day,week,month)
* @return {String}
*/ this.getDuration = function(vFormat){
if (vMile)
vDuration = '-';
else if (vFormat=='hour')
{
tmpPer = Math.ceil((this.getEnd() - this.getStart()) / ( 60 * 60 * 1000) );
if(tmpPer == 1)
vDuration = '1 Hour';
else
vDuration = tmpPer + ' Hours';
}
else if (vFormat=='minute')
{
tmpPer = Math.ceil((this.getEnd() - this.getStart()) / ( 60 * 1000) );
if(tmpPer == 1)
vDuration = '1 Minute';
else
vDuration = tmpPer + ' Minutes';
}
else { //if(vFormat == 'day') {
tmpPer = Math.ceil((this.getEnd() - this.getStart()) / (24 * 60 * 60 * 1000) + 1);
if(tmpPer == 1) vDuration = '1 Day';
else vDuration = tmpPer + ' Days';
}
//else if(vFormat == 'week') {
// tmpPer = ((this.getEnd() - this.getStart()) / (24 * 60 * 60 * 1000) + 1)/7;
// if(tmpPer == 1) vDuration = '1 Week';
// else vDuration = tmpPer + ' Weeks';
//}
//else if(vFormat == 'month') {
// tmpPer = ((this.getEnd() - this.getStart()) / (24 * 60 * 60 * 1000) + 1)/30;
// if(tmpPer == 1) vDuration = '1 Month';
// else vDuration = tmpPer + ' Months';
//}
//else if(vFormat == 'quater') {
// tmpPer = ((this.getEnd() - this.getStart()) / (24 * 60 * 60 * 1000) + 1)/120;
// if(tmpPer == 1) vDuration = '1 Qtr';
// else vDuration = tmpPer + ' Qtrs';
//}
return( vDuration )
};
/**
* Returns task parent ID
* @method getParent
* @return {Number}
*/ this.getParent = function(){ return vParent };
/**
* Returns whether task is a group (1=Yes,0=No)
* @method getGroup
* @return {Number}
*/ this.getGroup = function(){ return vGroup };
/**
* Returns whether task is open (1=Yes,0=No)
* @method getOpen
* @return {Boolean}
*/ this.getOpen = function(){ return vOpen };
/**
* Returns task tree level (0,1,2,3...)
* @method getLevel
* @return {Boolean}
*/ this.getLevel = function(){ return vLevel };
/**
* Returns the number of child tasks
* @method getNumKids
* @return {Number}
*/ this.getNumKids = function(){ return vNumKid };
/**
* Returns the X position of the left side of the task bar on the graph (right side)
* @method getStartX
* @return {Number}
*/ this.getStartX = function(){ return x1 };
/**
* Returns the Y position of the top of the task bar on the graph (right side)
* @method getStartY
* @return {Number}
*/ this.getStartY = function(){ return y1 };
/**
* Returns the X position of the right of the task bar on the graph (right side)
* @method getEndX
* @return {Int}
*/ this.getEndX = function(){ return x2 };
/**
* Returns the Y position of the bottom of the task bar on the graph (right side)
* @method getEndY
* @return {Number}
*/ this.getEndY = function(){ return y2 };
/**
* Returns whether task is visible (1=Yes,0=No)
* @method getVisible
* @return {Boolean}
*/ this.getVisible = function(){ return vVisible };
/**
* Set task dependencies
* @method setDepend
* @param pDepend {String} A comma delimited list of task IDs the current task depends on.
* @return {void}
*/ this.setDepend = function(pDepend){ vDepend = pDepend;};
/**
* Set task start date/time
* @method setStart
* @param pStart {Datetime}
* @return {void}
*/ this.setStart = function(pStart){ vStart = pStart;};
/**
* Set task end date/time
* @method setEnd
* @param pEnd {Datetime}
* @return {void}
*/ this.setEnd = function(pEnd) { vEnd = pEnd; };
/**
* Set task tree level (0,1,2,3...)
* @method setLevel
* @param pLevel {Number}
* @return {void}
*/ this.setLevel = function(pLevel){ vLevel = pLevel;};
/**
* Set Number of children for the task
* @method setNumKid
* @param pNumKid {Number}
* @return {void}
*/ this.setNumKid = function(pNumKid){ vNumKid = pNumKid;};
/**
* Set task completion percentage
* @method setCompVal
* @param pCompVal {Number}
* @return {void}
*/ this.setCompVal = function(pCompVal){ vComp = pCompVal;};
/**
* Set a task bar starting position (left)
* @method setStartX
* @param pX {Number}
* @return {void}
*/ this.setStartX = function(pX) {x1 = pX; };
/**
* Set a task bar starting position (top)
* @method setStartY
* @param pY {Number}
* @return {String}
*/ this.setStartY = function(pY) {y1 = pY; };
/**
* Set a task bar starting position (right)
* @method setEndX
* @param pX {Number}
* @return {String}
*/ this.setEndX = function(pX) {x2 = pX; };
/**
* Set a task bar starting position (bottom)
* @method setEndY
* @param pY {Number}
* @return {String}
*/ this.setEndY = function(pY) {y2 = pY; };
/**
* Set task open/closed
* @method setOpen
* @param pOpen {Boolean}
* @return {void}
*/ this.setOpen = function(pOpen) {vOpen = pOpen; };
/**
* Set task visibility
* @method setVisible
* @param pVisible {Boolean}
* @return {void}
*/ this.setVisible = function(pVisible) {vVisible = pVisible; };
};
/**
* Creates the gant chart. for example:
<p>var g = new JSGantt.GanttChart('g',document.getElementById('GanttChartDIV'), 'day');</p>
var g = new JSGantt.GanttChart( - assign the gantt chart to a javascript variable called 'g'
'g' - the name of the variable that was just assigned (will be used later so that gantt object can reference itself)
document.getElementById('GanttChartDIV') - reference to the DIV that will hold the gantt chart
'day' - default format will be by day
*
* @class GanttChart
* @param pGanttVar {String} the name of the gantt chart variable
* @param pDiv {String} reference to the DIV that will hold the gantt chart
* @param pFormat {String} default format (minute,hour,day,week,month,quarter)
* @return void
*/
JSGantt.GanttChart = function(pGanttVar, pDiv, pFormat)
{
/**
* The name of the gantt chart variable
* @property vGanttVar
* @type String
* @default pGanttVar
* @private
*/ var vGanttVar = pGanttVar;
/**
* The name of the gantt chart DIV
* @property vDiv
* @type String
* @default pDiv
* @private
*/ var vDiv = pDiv;
/**
* Selected format (minute,hour,day,week,month)
* @property vFormat
* @type String
* @default pFormat
* @private
*/ var vFormat = pFormat;
/**
* Show resource column
* @property vShowRes
* @type Number
* @default 1
* @private
*/ var vShowRes = 1;
/**
* Show duration column
* @property vShowDur
* @type Number
* @default 1
* @private
*/ var vShowDur = 1;
/**
* Show percent complete column
* @property vShowComp
* @type Number
* @default 1
* @private
*/ var vShowComp = 1;
/**
* Show start date column
* @property vShowStartDate
* @type Number
* @default 1
* @private
*/ var vShowStartDate = 1;
/**
* Show end date column
* @property vShowEndDate
* @type Number
* @default 1
* @private
*/ var vShowEndDate = 1;
/**
* Date input format
* @property vDateInputFormat
* @type String
* @default "mm/dd/yyyy"
* @private
*/var vDateInputFormat = "mm/dd/yyyy";
/**
* Date display format
* @property vDateDisplayFormat
* @type String
* @default "mm/dd/yy"
* @private
*/var vDateDisplayFormat = "mm/dd/yy";
var vNumUnits = 0;
var vCaptionType;
var vDepId = 1;
var vTaskList = new Array();
var vFormatArr = new Array("day","week","month","quarter");
var vQuarterArr = new Array(1,1,1,2,2,2,3,3,3,4,4,4);
var vMonthDaysArr = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var vMonthArr = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
/**
* Set current display format (minute/hour/day/week/month/quarter)
* Only the first 4 arguments are used, for example:
* <code>
* g.setFormatArr("day","week","month");
* </code>
* will show 3 formatting options (day/week/month) at the bottom right of the gantt chart
* @method setFormatArr
* @return {void}
*/ this.setFormatArr = function() {
vFormatArr = new Array();
for(var i = 0; i < arguments.length; i++) {vFormatArr[i] = arguments[i];}
if(vFormatArr.length>4){vFormatArr.length=4;}
};
/**
* Show/Hide resource column
* @param pShow {Number} 1=Show,0=Hide
* @method setShowRes
* @return {void}
*/ this.setShowRes = function(pShow) { vShowRes = pShow; };
/**
* Show/Hide duration column
* @param pShow {Number} 1=Show,0=Hide
* @method setShowDur
* @return {void}
*/ this.setShowDur = function(pShow) { vShowDur = pShow; };
/**
* Show/Hide completed column
* @param pShow {Number} 1=Show,0=Hide
* @method setShowComp
* @return {void}
*/ this.setShowComp = function(pShow) { vShowComp = pShow; };
/**
* Show/Hide start date column
* @param pShow {Number} 1=Show,0=Hide
* @method setShowStartDate
* @return {void}
*/ this.setShowStartDate = function(pShow) { vShowStartDate = pShow; };
/**
* Show/Hide end date column
* @param pShow {Number} 1=Show,0=Hide
* @method setShowEndDate
* @return {void}
*/ this.setShowEndDate = function(pShow) { vShowEndDate = pShow; };
/**
* Overall date input format
* @param pShow {String} (mm/dd/yyyy,dd/mm/yyyy,yyyy-mm-dd)
* @method setDateInputFormat
* @return {void}
*/ this.setDateInputFormat = function(pShow) { vDateInputFormat = pShow; };
/**
* Overall date display format
* @param pShow {String} (mm/dd/yyyy,dd/mm/yyyy,yyyy-mm-dd)
* @method setDateDisplayFormat
* @return {void}
*/ this.setDateDisplayFormat = function(pShow) { vDateDisplayFormat = pShow; };
/**
* Set gantt caption
* @param pType {String}
<p>Caption-Displays a custom caption set in TaskItem<br>
Resource-Displays task resource<br>
Duration-Displays task duration<br>
Complete-Displays task percent complete</p>
* @method setCaptionType
* @return {void}
*/ this.setCaptionType = function(pType) { vCaptionType = pType };
/**
* Set current display format and redraw gantt chart (minute/hour/day/week/month/quarter)
* @param pFormat {String} (mm/dd/yyyy,dd/mm/yyyy,yyyy-mm-dd)
* @method setFormat
* @return {void}
*/ this.setFormat = function(pFormat){
vFormat = pFormat;
this.Draw();
};
/**
* Returns whether resource column is shown
* @method getShowRes
* @return {Number}
*/ this.getShowRes = function(){ return vShowRes };
/**
* Returns whether duration column is shown
* @method getShowDur
* @return {Number}
*/ this.getShowDur = function(){ return vShowDur };
/**
* Returns whether percent complete column is shown
* @method getShowComp
* @return {Number}
*/ this.getShowComp = function(){ return vShowComp };
/**
* Returns whether start date column is shown
* @method getShowStartDate
* @return {Number}
*/ this.getShowStartDate = function(){ return vShowStartDate };
/**
* Returns whether end date column is shown
* @method getShowEndDate
* @return {Number}
*/ this.getShowEndDate = function(){ return vShowEndDate };
/**
* Returns date input format
* @method getDateInputFormat
* @return {String}
*/ this.getDateInputFormat = function() { return vDateInputFormat };
/**
* Returns current display format
* @method getDateDisplayFormat
* @return {String}
*/ this.getDateDisplayFormat = function() { return vDateDisplayFormat };
/**
* Returns current gantt caption type
* @method getCaptionType
* @return {String}
*/ this.getCaptionType = function() { return vCaptionType };
/**
* Calculates X/Y coordinates of a task and sets the Start and End properties of the TaskItem
* @method CalcTaskXY
* @return {Void}
*/ this.CalcTaskXY = function ()
{
var vList = this.getList();
var vTaskDiv;
var vParDiv;
var vLeft, vTop, vHeight, vWidth;
for(i = 0; i < vList.length; i++)
{
vID = vList[i].getID();
vTaskDiv = document.getElementById("taskbar_"+vID);
vBarDiv = document.getElementById("bardiv_"+vID);
vParDiv = document.getElementById("childgrid_"+vID);
if(vBarDiv) {
vList[i].setStartX( vBarDiv.offsetLeft );
vList[i].setStartY( vParDiv.offsetTop+vBarDiv.offsetTop+6 );
vList[i].setEndX( vBarDiv.offsetLeft + vBarDiv.offsetWidth );
vList[i].setEndY( vParDiv.offsetTop+vBarDiv.offsetTop+6 );
};
};
};
/**
* Adds a TaskItem to the Gantt object task list array
* @method AddTaskItem
* @return {Void}
*/ this.AddTaskItem = function(value)
{
vTaskList.push(value);
};
/**
* Returns task list Array
* @method getList
* @return {Array}
*/ this.getList = function() { return vTaskList };
/**
* Clears dependency lines between tasks
* @method clearDependencies
* @return {Void}
*/ this.clearDependencies = function()
{
var parent = document.getElementById('rightside');
var depLine;
var vMaxId = vDepId;
for ( i=1; i<vMaxId; i++ ) {
depLine = document.getElementById("line"+i);
if (depLine) { parent.removeChild(depLine); }
};
vDepId = 1;
};
/**
* Draw a straight line (colored one-pixel wide DIV), need to parameterize doc item
* @method sLine
* @return {Void}
*/ this.sLine = function(x1,y1,x2,y2) {
vLeft = Math.min(x1,x2);
vTop = Math.min(y1,y2);
vWid = Math.abs(x2-x1) + 1;
vHgt = Math.abs(y2-y1) + 1;
vDoc = document.getElementById('rightside');
// retrieve DIV
var oDiv = document.createElement('div');
oDiv.id = "line"+vDepId++;
oDiv.style.position = "absolute";
oDiv.style.margin = "0px";
oDiv.style.padding = "0px";
oDiv.style.overflow = "hidden";
oDiv.style.border = "0px";
// set attributes
oDiv.style.zIndex = 0;
oDiv.style.backgroundColor = "red";
oDiv.style.left = vLeft + "px";
oDiv.style.top = vTop + "px";
oDiv.style.width = vWid + "px";
oDiv.style.height = vHgt + "px";
oDiv.style.visibility = "visible";
vDoc.appendChild(oDiv);
};
/**
* Draw a diaganol line (calc line x,y pairs and draw multiple one-by-one sLines)
* @method dLine
* @return {Void}
*/ this.dLine = function(x1,y1,x2,y2) {
var dx = x2 - x1;
var dy = y2 - y1;
var x = x1;
var y = y1;
var n = Math.max(Math.abs(dx),Math.abs(dy));
dx = dx / n;
dy = dy / n;
for ( i = 0; i <= n; i++ )
{
vx = Math.round(x);
vy = Math.round(y);
this.sLine(vx,vy,vx,vy);
x += dx;
y += dy;
};
};
/**
* Draw dependency line between two points (task 1 end -> task 2 start)
* @method drawDependency
* @return {Void}
*/ this.drawDependency =function(x1,y1,x2,y2)
{
if(x1 + 10 < x2)
{
this.sLine(x1,y1,x1+4,y1);
this.sLine(x1+4,y1,x1+4,y2);
this.sLine(x1+4,y2,x2,y2);
this.dLine(x2,y2,x2-3,y2-3);
this.dLine(x2,y2,x2-3,y2+3);
this.dLine(x2-1,y2,x2-3,y2-2);
this.dLine(x2-1,y2,x2-3,y2+2);
}
else
{
this.sLine(x1,y1,x1+4,y1);
this.sLine(x1+4,y1,x1+4,y2-10);
this.sLine(x1+4,y2-10,x2-8,y2-10);
this.sLine(x2-8,y2-10,x2-8,y2);
this.sLine(x2-8,y2,x2,y2);
this.dLine(x2,y2,x2-3,y2-3);
this.dLine(x2,y2,x2-3,y2+3);
this.dLine(x2-1,y2,x2-3,y2-2);
this.dLine(x2-1,y2,x2-3,y2+2);
}
};
/**
* Draw all task dependencies
* @method DrawDependencies
* @return {Void}
*/ this.DrawDependencies = function () {
//First recalculate the x,y
this.CalcTaskXY();
this.clearDependencies();
var vList = this.getList();
for(var i = 0; i < vList.length; i++)
{
vDepend = vList[i].getDepend();
if(vDepend) {
var vDependStr = vDepend + '';
var vDepList = vDependStr.split(',');
var n = vDepList.length;
for(var k=0;k<n;k++) {
var vTask = this.getArrayLocationByID(vDepList[k]);
if(vList[vTask].getVisible()==1)
this.drawDependency(vList[vTask].getEndX(),vList[vTask].getEndY(),vList[i].getStartX()-1,vList[i].getStartY())
}
}
}
};
/**
* Find location of TaskItem based on the task ID
* @method getArrayLocationByID
* @return {Void}
*/ this.getArrayLocationByID = function(pId) {
var vList = this.getList();
for(var i = 0; i < vList.length; i++)
{
if(vList[i].getID()==pId)
return i;
}
};
/**
* Draw gantt chart
* @method Draw
* @return {Void}
*/ this.Draw = function()
{
var vMaxDate = new Date();
var vMinDate = new Date();
var vTmpDate = new Date();
var vNxtDate = new Date();
var vCurrDate = new Date();
var vTaskLeft = 0;
var vTaskRight = 0;
var vNumCols = 0;
var vID = 0;
var vMainTable = "";
var vLeftTable = "";
var vRightTable = "";
var vDateRowStr = "";
var vItemRowStr = "";
var vColWidth = 0;
var vColUnit = 0;
var vChartWidth = 0;
var vNumDays = 0;
var vDayWidth = 0;
var vStr = "";
var vNameWidth = 220;
var vStatusWidth = 70;
var vLeftWidth = 15 + 220 + 70 + 70 + 70 + 70 + 70;
if(vTaskList.length > 0)
{
// Process all tasks preset parent date and completion %
JSGantt.processRows(vTaskList, 0, -1, 1, 1);
// get overall min/max dates plus padding
vMinDate = JSGantt.getMinDate(vTaskList, vFormat);
vMaxDate = JSGantt.getMaxDate(vTaskList, vFormat);
// Calculate chart width variables. vColWidth can be altered manually to change each column width
// May be smart to make this a parameter of GanttChart or set it based on existing pWidth parameter
if(vFormat == 'day') {
vColWidth = 18;
vColUnit = 1;
}
else if(vFormat == 'week') {
vColWidth = 37;
vColUnit = 7;
}
else if(vFormat == 'month') {
vColWidth = 37;
vColUnit = 30;
}
else if(vFormat == 'quarter') {
vColWidth = 60;
vColUnit = 90;
}
else if(vFormat=='hour')
{
vColWidth = 18;
vColUnit = 1;
}
else if(vFormat=='minute')
{
vColWidth = 18;
vColUnit = 1;
}
vNumDays = (Date.parse(vMaxDate) - Date.parse(vMinDate)) / ( 24 * 60 * 60 * 1000);
vNumUnits = vNumDays / vColUnit;
vChartWidth = vNumUnits * vColWidth + 1;
vDayWidth = (vColWidth / vColUnit) + (1/vColUnit);
vMainTable =
'<TABLE id=theTable cellSpacing=0 cellPadding=0 border=0><TBODY><TR>' +
'<TD vAlign=top bgColor=#ffffff>';
if(vShowRes !=1) vNameWidth+=vStatusWidth;
if(vShowDur !=1) vNameWidth+=vStatusWidth;
if(vShowComp!=1) vNameWidth+=vStatusWidth;
if(vShowStartDate!=1) vNameWidth+=vStatusWidth;
if(vShowEndDate!=1) vNameWidth+=vStatusWidth;
// DRAW the Left-side of the chart (names, resources, comp%)
vLeftTable =
'<DIV class=scroll id=leftside style="width:' + vLeftWidth + 'px"><TABLE cellSpacing=0 cellPadding=0 border=0><TBODY>' +
'<TR style="HEIGHT: 17px">' +
' <TD style="WIDTH: 15px; HEIGHT: 17px"></TD>' +
' <TD style="WIDTH: ' + vNameWidth + 'px; HEIGHT: 17px"><NOBR></NOBR></TD>';
if(vShowRes ==1) vLeftTable += ' <TD style="WIDTH: ' + vStatusWidth + 'px; HEIGHT: 17px"></TD>' ;
if(vShowDur ==1) vLeftTable += ' <TD style="WIDTH: ' + vStatusWidth + 'px; HEIGHT: 17px"></TD>' ;
if(vShowComp==1) vLeftTable += ' <TD style="WIDTH: ' + vStatusWidth + 'px; HEIGHT: 17px"></TD>' ;
if(vShowStartDate==1) vLeftTable += ' <TD style="WIDTH: ' + vStatusWidth + 'px; HEIGHT: 17px"></TD>' ;
if(vShowEndDate==1) vLeftTable += ' <TD style="WIDTH: ' + vStatusWidth + 'px; HEIGHT: 17px"></TD>' ;
vLeftTable +=
'<TR style="HEIGHT: 20px">' +
' <TD style="BORDER-TOP: #efefef 1px solid; WIDTH: 15px; HEIGHT: 20px"></TD>' +
' <TD style="BORDER-TOP: #efefef 1px solid; WIDTH: ' + vNameWidth + 'px; HEIGHT: 20px"><NOBR></NOBR></TD>' ;