Using DragPoint in a Gantt Chart

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
TonyHunt
Newbie
Newbie
Posts: 15
Joined: Mon Jan 15, 2007 12:00 am

Using DragPoint in a Gantt Chart

Post by TonyHunt » Mon Jul 13, 2009 12:31 pm

I am investigating Using DragPoint in a Gantt Chart on the Y axis. This works well but I would like to be able so enable a 'SnapTo' or Step feature rather than the smooth linear result I am getting from the DragPoint at the moment.

I have seen the 'Desired Increment' on the Left Axis but regrettably this doesn't appear to do what I want.

Any suggestions for a work around and any samples of using the Gantt chart in more depth would be much appreciated.

Best Wishes

Tony Hunt

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Using DragPoint in a Gantt Chart

Post by Yeray » Tue Jul 14, 2009 8:26 am

Hi Tony,

There is the Gantt Drag tool that allows dragging but without allowing you to set the tolerance you wish.
Here you have an example of how you could do something like what you requested without any tool, directly using OnMouseDown, OnMouseUp and OnMouseMove events:

Code: Select all

var
  Form1: TForm1;
  DraggingIndex, DraggingTolerance, StartX: Integer;
  OldStartValue, OldEndValue: Double;
  series1: TGanttSeries;
implementation

{$R *.dfm}

procedure TForm1.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  DraggingIndex := -1;
end;

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  DraggingIndex := Series1.Clicked(X, Y);
  if (DraggingIndex>-1) then
  begin
    StartX := X;
    OldStartValue := series1.StartValues.Items[DraggingIndex];
    OldEndValue := series1.EndValues.Items[DraggingIndex];
  end;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var movedValues: double;
begin
  if (Series1.Clicked(X, Y) <> -1) then
  begin
    Chart1.Cursor := crHandPoint;
    Chart1.CancelMouse := True;
  end;

  if (DraggingIndex>-1) then
  begin
    movedValues := Abs(Chart1.Axes.Bottom.CalcPosPoint(X))-Abs(Chart1.Axes.Bottom.CalcPosPoint(StartX));
    series1.StartValues.Items[DraggingIndex] := OldStartValue + round(movedValues / DraggingTolerance)*DraggingTolerance;
    series1.EndValues.Items[DraggingIndex] := OldEndValue + round(movedValues / DraggingTolerance)*DraggingTolerance;
    Chart1.Title.Text.Text := floattostr(X-StartX);
    Chart1.Draw;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D := false;
  Chart1.AllowZoom := false;

  series1 := TGanttSeries.Create(self);
  Chart1.AddSeries(series1);
  series1.FillSampleValues(6);

  DraggingIndex := -1;
  DraggingTolerance := 5;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

TonyHunt
Newbie
Newbie
Posts: 15
Joined: Mon Jan 15, 2007 12:00 am

Re: Using DragPoint in a Gantt Chart

Post by TonyHunt » Tue Jul 14, 2009 11:25 am

Thank you very much, that gave me a good insight into several other things as well.

Tony

Post Reply