Page 1 of 1

Using DragPoint in a Gantt Chart

Posted: Mon Jul 13, 2009 12:31 pm
by 9243846
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

Re: Using DragPoint in a Gantt Chart

Posted: Tue Jul 14, 2009 8:26 am
by yeray
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;

Re: Using DragPoint in a Gantt Chart

Posted: Tue Jul 14, 2009 11:25 am
by 9243846
Thank you very much, that gave me a good insight into several other things as well.

Tony