home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / STANDARD / GANTT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  4.8 KB  |  164 lines

  1. {*********************************************}
  2. { TeeChart Delphi Component Library           }
  3. { Gantt Series Type Demo                      }
  4. { Copyright (c) 1995-1996 by David Berneda    }
  5. { All rights reserved                         }
  6. {*********************************************}
  7. unit Gantt;
  8.  
  9. interface
  10.  
  11. uses
  12.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  13.   Forms, Dialogs, Chart, Series, ExtCtrls, StdCtrls, GanttCh,
  14.   Teengine, Buttons, TeeProcs;
  15.  
  16. type
  17.   TGanttForm = class(TForm)
  18.     Chart1: TChart;
  19.     Panel1: TPanel;
  20.     Label1: TLabel;
  21.     Shape1: TShape;
  22.     BitBtn3: TBitBtn;
  23.     GanttSeries1: TGanttSeries;
  24.     Memo1: TMemo;
  25.     Label2: TLabel;
  26.     procedure FormCreate(Sender: TObject);
  27.     procedure Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  28.       Y: Integer);
  29.     procedure Chart1GetNextAxisLabel(Sender: TChartAxis;
  30.       LabelIndex: Longint; var LabelValue: Double; var Stop: Boolean);
  31.     procedure GanttSeries1Click(Sender: TChartSeries; ValueIndex: Integer;
  32.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  33.   private
  34.     { Private declarations }
  35.   public
  36.     { Public declarations }
  37.   end;
  38.  
  39. implementation
  40.  
  41. {$R *.DFM}
  42.  
  43. Uses UDemUtil;
  44.  
  45. (*
  46.  *********************************
  47.   HOW TO ADD GANTT BARS MANUALLY ?
  48.  *********************************
  49.  
  50. Use the  AddGantt or AddGanttColor methods.
  51.  
  52. ( This demo do not uses this methods )
  53.  
  54. Example:
  55.  
  56.    GanttSeries1.AddGantt(  EncodeDate( 1997, 1,  1 ),
  57.                            EncodeDate( 1997, 1, 31 ),
  58.                            0,
  59.                            'Programming' );
  60.  
  61. Or...
  62.  
  63.    GanttSeries1.AddGanttColor(  EncodeDate( 1997, 1,  1 ),
  64.                                 EncodeDate( 1997, 1, 31 ),
  65.                                 0,
  66.                                 'Programming',
  67.                                 clGreen );
  68.  
  69.  
  70.    Where "0" is the desired vertical position for this bar.
  71.    Choose the vertical position you prefer.
  72.  
  73.    To connect gantt bars:
  74.  
  75.    1) Store the "AddGantt" or "AddGanttColor" function return longint:
  76.  
  77.       Var tmp1, tmp2 : Longint;
  78.  
  79.       tmp1:=GanttSeries1.AddGantt(  EncodeDate( 1997, 1,  1 ),
  80.                                     EncodeDate( 1997, 1, 31 ),
  81.                                     0,
  82.                                     'Programming' );
  83.  
  84.       tmp2:=GanttSeries1.AddGantt(  EncodeDate( 1997, 4,  1 ),
  85.                                     EncodeDate( 1997, 4, 30 ),
  86.                                     0,
  87.                                     'Testing' );
  88.  
  89.    2) Then use the NextTask property:
  90.  
  91.      GanttSeries1.NextTask[ tmp1 ] := tmp2 ;
  92.  
  93.      This will draw a line from 'Programming' gantt bar to 'Testing' bar.
  94.  
  95.      The "ConnectingLinePen" property is the pen used to draw lines.
  96.  
  97. *)
  98.  
  99. procedure TGanttForm.FormCreate(Sender: TObject);
  100. begin
  101.   GanttSeries1.FillSampleValues(GanttSeries1.NumSampleValues); { <-- Some random points }
  102.   { change cursor when mouse moves over Gantt bars... }
  103.   GanttSeries1.Cursor:=crTeeHand;
  104. end;
  105.  
  106. procedure TGanttForm.Chart1MouseMove(Sender: TObject; Shift: TShiftState;
  107.   X, Y: Integer);
  108. var tmpTask:Longint;
  109. begin
  110.   tmpTask:=GanttSeries1.Clicked(x,y);  { <-- if mouse is over a gantt bar... }
  111.   if tmpTask<>-1 then
  112.   begin { set a sample label and a sample shape color }
  113.     Label1.Caption:=DateToStr(GanttSeries1.XValues[tmpTask]);
  114.     Label2.Caption:=DateToStr(GanttSeries1.EndValues[tmpTask]);
  115.     Shape1.Brush.Color:=GanttSeries1.ValueColor[tmpTask];
  116.   end
  117.   else
  118.   begin  { clear label and shape samples }
  119.     Label1.Caption:='';
  120.     Label2.Caption:='';
  121.     Shape1.Brush.Color:=Panel1.Color;
  122.   end;
  123. end;
  124.  
  125. procedure TGanttForm.Chart1GetNextAxisLabel(Sender: TChartAxis;
  126.   LabelIndex: Longint; var LabelValue: Double; var Stop: Boolean);
  127. var year,month,day:Word;
  128. begin
  129.   { this will set the Bottom Axis (Dates) Labels to the First
  130.     day of each month. }
  131.   if Sender=Chart1.BottomAxis then
  132.   begin
  133.     { LabelValue has the "candidate" value where the Axis label will be painted. }
  134.     DecodeDate(LabelValue,year,month,day);
  135.     { we force that value to be the first day in month }
  136.     Day:=1;
  137.     Month:=Month+1;
  138.     if Month>12 then
  139.     Begin
  140.       Month:=1;
  141.       Year:=Year+1;
  142.     end;
  143.     { Then we set the preferred Label value }
  144.     LabelValue:=EncodeDate(year,month,day);
  145.     { we want more labels !! }
  146.     Stop:=False;
  147.   end;
  148. end;
  149.  
  150. procedure TGanttForm.GanttSeries1Click(Sender: TChartSeries;
  151.   ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X,
  152.   Y: Integer);
  153. begin
  154.   if Button=mbLeft then
  155.   With Sender do
  156.     ValueColor[ValueIndex]:=EditColor(Self,ValueColor[ValueIndex])
  157.   else
  158.     Chart1.CancelMouse:=False;
  159.     { setting CancelMouse to True notifies TeeChart engine to STOP
  160.       handling the mouse click and NOT start zoom or scroll. }
  161. end;
  162.  
  163. end.
  164.