Page 1 of 1

GANTT chart automatic reposition (TeeChart Pro 6.01)

Posted: Thu Jun 05, 2008 4:43 pm
by 8575451
In a GANTT chart I have added the possibility to reposition and to resize the bars of the graphic with TGanttTool component, but I have two problems:

(1) If there are different bars/tasks of the GANTT chart connected among them, when I reposition or resize a bar, the other connected bars are not repositioned automatically. If I move a bar that represents a task to perform until its end finish after the start of the following task to perform, that the following tasks are not repositioned automatically to start just in the end of the prevoius task. This automatic repositioning is possible to perform with the component?


(2) I need to show a popup menu when press rightclick mouse button on a concrete bar. The problem is that, when select a menu item, the bar is repositioned while moves the mouse pointer, and it's necessary to click again to finish the repositioning.
I try to avoid this bad functionality deactivating drag and resize, but without success. I show you an example:

Code: Select all

procedure TForm1.SerieGanttClick(Sender: TChartSeries; ValueIndex: Integer;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 if Button = mbRight then
 begin
  Gantt.AllowDrag := False;
  Gantt.AllowResize := False;
  Try
  PopupMenu.PopUp(X, Y + 100);
  Finally
   Gantt.AllowDrag := True;
   Gantt.AllowResize := True;
  End;
 end;
end;

It is possible to deactivate this funcionality when show a popup menu and select an item without the repositioning problem?

Regards

Jose

Posted: Fri Jun 06, 2008 8:52 am
by yeray
Hi Jose,

1) I think you should use OnDragBar and OnResizeBar events from your Gantt Tool to explore the whole Gantt series and modify start or end values when they are superposed. I think you should do something like following. But note that it's not completed, but maybe it's a good start.

Code: Select all

procedure TForm1.ChartTool1ResizeBar(Sender: TGanttTool; GanttBar: Integer;
  BarPart: TGanttToolBarPart);
var i: Integer;
wide: Double;
begin
  with Series1 do
  begin
    for i:=0 to Series1.Count-1 do
    begin
      if (StartValues.Items[i] > StartValues.Items[GanttBar]) and (StartValues.Items[i] < EndValues.Items[GanttBar]) then
      begin
        wide := EndValues.Items[i] - StartValues.Items[i];
        StartValues.Items[i] := EndValues.Items[GanttBar];
        EndValues.Items[i] := StartValues.Items[i] + wide;
      end;
    end;
  end;
end;
2) I've tried what you say and achieved it with OnClickSeries and OnMouseDown events. I think that your problem here was that the Gantt series started to drag/resize before disabling the functionalities.

Code: Select all

procedure TForm1.Series1Click(Sender: TChartSeries; ValueIndex: Integer;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbRight then
  begin
    ChartTool1.AllowDrag := True;
    ChartTool1.AllowResize := True;
  end;
end;

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (Button = mbRight) and (Series1.Clicked(X,Y) >= 0) then
  begin
    ChartTool1.AllowDrag := False;
    ChartTool1.AllowResize := False;

    Try
      ShowMessage('okay');
    finally
    end;
  end;
end;

Posted: Fri Jun 06, 2008 11:36 am
by 8575451
Hi Yeray!

Point 2 is solved. Thanks!!!!

About point 1, I see that if reposition one bar, change all bars according init bar position. I think that the better way is to reposition all bars that depend on bar repositioned/resized when the user release the mouse button (in the mouse up event).

There are an easy way to access all bars that depends of one bar, and reposition recursively from one bar to forward?

Thanks in advance

Posted: Fri Jun 06, 2008 1:27 pm
by narcis
Hi GEINFOR,
There are an easy way to access all bars that depends of one bar, and reposition recursively from one bar to forward?
Yes, you can use NextTask property. You can find an eample using NextTask on this thread.

Hope this helps!

Posted: Fri Jun 06, 2008 3:58 pm
by 8575451
Ok, Narcís. Moltes gràcies.

Jose

Posted: Mon Jun 09, 2008 7:08 am
by narcis
Hola Jose,

De res! :wink: