FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Ram贸n Avenda帽o`s TGantt design
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Ram贸n Avenda帽o`s TGantt design
Posted: Sat Oct 01, 2011 03:00 PM
Class TGantt from Ram贸n is really simple and such simplicity makes it be very flexible. In fact all the modifications implemented after the original design, are simple details with no relevance and that are not needed really :-)

A TGantt object is a control (inherits from TControl) which manages an array of items. Those items have coordinates and they get painted on the surface of the TGantt. Besides that, we can use the mouse to move those items and to redimension them. Thats all! :-)

What we may want to do with those items is our matter (as programmers). Lets review a first example very easy to use TGantt so we understand it:

testgant.prg
Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "Gantt.ch"

function Main()

聽 聽local oWnd, oGantt

聽 聽DEFINE WINDOW oWnd TITLE "Class TGantt test"
聽 聽
聽 聽@ 1, 1 GANTT oGantt SIZE 300, 300 OF oWnd
聽 聽
聽 聽AAdd( oGantt:aItems, { 聽10, 10, 聽30, 聽80, CLR_BLUE } ) 
聽 聽AAdd( oGantt:aItems, { 聽40, 30, 聽60, 110, CLR_RED } ) 
聽 聽AAdd( oGantt:aItems, { 聽70, 50, 聽90, 聽90, CLR_GREEN } ) 
聽 聽AAdd( oGantt:aItems, { 100, 10, 120, 聽80, CLR_CYAN } ) 
聽 聽AAdd( oGantt:aItems, { 130, 50, 150, 120, CLR_YELLOW } ) 
聽 聽
聽 聽oWnd:oClient = oGantt

聽 聽ACTIVATE WINDOW oWnd

return nil


As you can see, we define 5 items for this Gantt, and we assign a color to each one. We could assign much more data, but for now, lets focus on the main idea. The result looks this way:



Moving and resizing the items:


You can download the EXE from here, so you can move and redimension the items with the mouse. Full source code included:
http://code.google.com/p/fivewin-contributions/downloads/detail?name=gantt.zop&can=2&q=
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 437
Joined: Fri Oct 07, 2005 12:56 PM
Re: Ram贸n Avenda帽o`s TGantt design
Posted: Sat Oct 01, 2011 05:34 PM
Antonio Linares wrote:Class TGantt from Ram贸n is really simple and such simplicity makes it be very flexible. In fact all the modifications implemented after the original design, are simple details with no relevance and that are not needed really :-)

A TGantt object is a control (inherits from TControl) which manages an array of items. Those items have coordinates and they get painted on the surface of the TGantt. Besides that, we can use the mouse to move those items and to redimension them. Thats all! :-)

You can download the EXE from here, so you can move and redimension the items with the mouse. Full source code included:
http://code.google.com/p/fivewin-contributions/downloads/detail?name=gantt.zop&can=2&q=



Wowwww ! Thanks to you Antonio ! It's very cool !
Rimantas U.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Ram贸n Avenda帽o`s TGantt design
Posted: Sat Oct 01, 2011 07:01 PM
Now lets consider that we want to represent some "month" related data. We have implemented a Method GridMonth() in Class TGantt that shows a usefull grid :-)

Code (fw): Select all Collapse
METHOD GridMonth() CLASS TGantt

聽 聽local n, nWidth := ::nWidth() / 31
聽 聽
聽 聽MoveTo( ::hDC, 0, 18 )
聽 聽LineTo( ::hDC, ::nWidth, 18 )
聽 聽
聽 聽for n = 1 to 30
聽 聽 聽 MoveTo( ::hDC, nWidth * n, 0 ) 
聽 聽 聽 LineTo( ::hDC, nWidth * n, ::nHeight )
聽 聽next 聽
聽 聽
聽 聽for n = 1 to 31
聽 聽 聽 ::Say( 3, 7 + ( ( n - 1 ) * nWidth ),;
聽 聽 聽 聽 聽 聽 聽If( n < 10, " ", "" ) + AllTrim( Str( n ) ),,, If( ::oFont != nil, ::oFont,), .T. )
聽 聽next 聽 聽 

return nil


We modify our first example this way:
Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "Gantt.ch"

function Main()

聽 聽local oFont, oWnd, oGantt

聽 聽DEFINE FONT oFont NAME "Verdana" SIZE 0, -10

聽 聽DEFINE WINDOW oWnd TITLE "Class TGantt test"
聽 聽
聽 聽@ 1, 1 GANTT oGantt SIZE 300, 300 OF oWnd
聽 聽
聽 聽oGantt:SetFont( oFont )
聽 聽oGantt:lGridMonth = .T.
聽 聽
聽 聽AAdd( oGantt:aItems, { 聽30, 10, 聽50, 聽80, CLR_BLUE } ) 
聽 聽AAdd( oGantt:aItems, { 聽60, 30, 聽80, 110, CLR_RED } ) 
聽 聽AAdd( oGantt:aItems, { 聽90, 50, 110, 聽90, CLR_GREEN } ) 
聽 聽AAdd( oGantt:aItems, { 120, 10, 140, 聽80, CLR_CYAN } ) 
聽 聽AAdd( oGantt:aItems, { 150, 50, 170, 120, CLR_YELLOW } ) 
聽 聽
聽 聽oWnd:oClient = oGantt

聽 聽ACTIVATE WINDOW oWnd

return nil


And here we have the result:


EXE and full source code:
http://code.google.com/p/fivewin-contributions/downloads/detail?name=gantt2.zop&can=2&q=
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Ram贸n Avenda帽o`s TGantt design
Posted: Mon Oct 03, 2011 03:24 PM

Of course you will need a "legend" that defines each bar.

I created a modified chart using xBrowse with arrays. The data columns provide the necessary info on the left, and a color bar fills the "status" chart to the right.

In any case, you will need a descriptor field to define what the chart means, not just the columns.

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Ram贸n Avenda帽o`s TGantt design
Posted: Tue Oct 04, 2011 03:24 PM

Antonio,

Thanks for the tutorial. Very useful.

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion