TGRAPH Technical Question


Re: TGRAPH Technical Question

Postby Silvio.Falconi » Fri Dec 26, 2014 4:01 pm

Antonio,

I made the modifies on tgraph and I tried it run but then after sone tooltip showed make an error



Time from start: 0 hours 0 mins 47 secs
Error occurred at: 26-12-2014, 16:54:03
Error description: Error BASE/1132 Limiti superati: accesso all'array
Args:
[ 1] = A { ... } length: 1
[ 2] = N 2

Stack Calls
===========
Called from: Lib\tgraph\tgraph.prg => (b)TGRAPH:MOUSEMOVE( 1883 )
Called from: Lib\tgraph\tgraph.prg => TGRAPH:MOUSEMOVE( 1883 )
Called from: => TWINDOW:HANDLEEVENT( 0 )
Called from: .\source\classes\CONTROL.PRG => TGRAPH:HANDLEEVENT( 1733 )
Called from: .\source\classes\WINDOW.PRG => _FWH( 3345 )
Called from: => WINRUN( 0 )
Called from: .\source\classes\WINDOW.PRG => TWINDOW:ACTIVATE( 1050 )
Called from: source\Main.prg => TAPPLICATION:ACTIVATE( 394 )
Called from: source\Main.prg => MAIN( 55 )





I found an error on new addserie method
Time from start: 0 hours 0 mins 9 secs
Error occurred at: 26-12-2014, 17:05:15
Error description: Error BASE/1123 Parametro errato: AADD
Args:
[ 1] = U
[ 2] = C 0

Stack Calls
===========
Called from: => AADD( 0 )
Called from: Lib\tgraph\tgraph.prg => TGRAPH:ADDSERIE( 460 )
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: TGRAPH Technical Question

Postby Antonio Linares » Fri Dec 26, 2014 4:24 pm

Silvio,

Could you please provide a small example to reproduce the error ? many thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: TGRAPH Technical Question

Postby Silvio.Falconi » Fri Dec 26, 2014 5:06 pm

Antonio,
this is the test
the dbf I sent you


test.prg


Code: Select all  Expand view
#include "FiveWin.ch"
#include "constant.ch"



Function Grafico()
   local oBar, oCol, oCont,oOptions
   local aBrowse

   local i,oLogoBmp,oCursor

   LOCAL oBrush := TBrush():New("NULL",,,)
   Local aMes:={ "Gen","Feb","Mar","Apr","Mag","Giu","Lug","Ago","Set","Oct","Nov","Dic" }
   Local aEntrate :={}
   Local aUscite :={}


   Local nBottom   := 45
   Local nRight    := 120

   Local nWidth :=  Max( nRight * DLG_CHARPIX_W, 180 )
   Local nHeight := nBottom * DLG_CHARPIX_H

 Local   cClrEntrate    := 7031871
 Local   cClrUscite     := 204


    Local   nMaxValGraph   := 2000


   Local aCanE :={ { "Gen", 0 }, { "Feb", 0 }, { "Mar", 0 }, { "Apr", 0 }, ;
                 { "Mag", 0 }, { "Giu", 0 }, { "Lug", 0 }, { "Ago", 0 }, ;
                 { "Set", 0 }, { "Oct", 0 }, { "Nov", 0 }, { "Dic", 0 }  }

   Local aCanU :={ { "Gen", 0 }, { "Feb", 0 }, { "Mar", 0 }, { "Apr", 0 }, ;
                 { "Mag", 0 }, { "Giu", 0 }, { "Lug", 0 }, { "Ago", 0 }, ;
                 { "Set", 0 }, { "Oct", 0 }, { "Nov", 0 }, { "Dic", 0 }  }



     USE MOVIMENTI ALIAS MV


 SELECT MV

    MV->(DbGoTop())


    MV->( DBEVAL( { || IF(Month( FIELD->APFECHA ) >0, aCanE[ Month( FIELD->APFECHA ) ][ 2 ]+= IIF( FIELD->APTIPO="E", MV->APIMPTOTAL,0), ) }) )
    MV->( DBEVAL( { || IF(Month( FIELD->APFECHA ) >0, aCanU[ Month( FIELD->APFECHA ) ][ 2 ]+= IIF( FIELD->APTIPO="U", MV->APIMPTOTAL,0), ) }) )


         For n=1 to len( aCanE)
            AADD(  aEntrate,aCanE[n][2])
         next n


        For n=1 to len( aCanU)
            AADD(  aUscite,aCanU[n][2])
         next n



     DEFINE DIALOG oDlg        ;
   TITLE "Test New Graph"    ;
   SIZE nWidth, nHeight  TRANSPARENT PIXEL


   oGraph:=TGraph():New(0,0,oDlg,oDlg:nBottom/2,oDlg:nWidth/4)
   oGraph:cPicture:="99,999.99"
   oGraph:SetYVals(aMes)
   oGraph:nType   :=1
   oGraph:cTitX   :="Importo Totale"
   oGraph:cTitY   :="Mesi"
   oGraph:lYVal   :=.T.
   oGraph:lLegends:=.T.
   oGraph:lPopUp  :=.F.
   oGraph:nBarD   :=15
   oGraph:nXRanges:=20
   oGraph:l3D :=.f.
   oGraph:nBarSep:=5
   oGraph:lxGrid :=.T.
   oGraph:lYGrid  :=.f.




oGraph:cTitle:="Visualizzazione annuale dei movimenti di entrata ed uscita"
oGraph:AddSerie(aEntrate,"Entrate",cClrEntrate)
oGraph:AddSerie(aUscite,"Uscite",cClrUscite)


oGraph:cToolTip = { | nAt | Str( nAt ) }



ACTIVATE DIALOG oDlg

return nil
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: TGRAPH Technical Question

Postby Antonio Linares » Fri Dec 26, 2014 5:20 pm

Silvio,

Your example is working fine here.

Maybe you did a wrong modification of class TGraph ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: TGRAPH Technical Question

Postby George » Fri Dec 26, 2014 5:35 pm

Antonio,

Thanks to your code we can have a more efficient Tooltip in TGRAPH class.
I just add the following code to be able to:
1. Activate or no the Tooltip
2. Tooltips now are working with one or two series values

Regards,

George

Code: Select all  Expand view
// Add
    DATA lToolTip   // Default = FALSE

    //-------------------------------
    // To display tooltip
    oGraph:lToolTip := TRUE
    oGraph:cToolTip = { | nAt, nRow, nCol | oGraph:ToolTip( nAt, nRow, nCol) }

//--------------------------------------------------
METHOD ToolTip(nAt, nRow, nCol) CLASS TGRAPH
 // Display Tootip for one or two value series
             if nAt/2 - int(nAt/2) = 0
                // Even (Series 2)
                nI := nAt/2
                ::ShowToolTip( nRow, nCol, ::aYVals[nI] + CRLF+ ::cLabelSerie2 + " = $"+ ::aSeries2[nI]   )
            else
                // Odd  (Series 1)
                nI := int(nAt/2)+1
                ::ShowToolTip( nRow, nCol, ::aYVals[nI] + CRLF+ ::cLabelSerie1 + " = "  + ::aSeries1[nI]   )
            endif

 //------------------------------------------------------------------------
 METHOD MouseMove( nRow, nCol, nFlags ) CLASS TGraph
    LOCAL nAt := 0

    if ::lToolTip = .T.
        if ! Empty( ::aBarCoors )
            nAt = AScan( ::aBarCoors,;
                { | aCoors | nRow <= aCoors[ 2 ] .and. ;
                nRow >= aCoors[ 2 ] - aCoors[ 3 ] .and. ;
                nCol >= aCoors[ 1 ] .and. ;
                nCol <= aCoors[ 1 ] + aCoors[ 4 ] } )
                if nAt != 0
                    DEFAULT ::cToolTip := { | nAt | AllTrim( Transform( ::aData[ 1 ][ nAt ],;
                        "999,999,999.99" ) ) }
                    //::ShowToolTip( nRow, nCol, Eval( ::cToolTip, nAt ) )
                    ::ShowToolTip( nRow, nCol, Eval( ::cToolTip, nAt, nRow, nCol ) )
                else
                    ::DestroyTooltip()
                endif
            endif
        endif
return nil

return (.T.)
Last edited by George on Fri Dec 26, 2014 5:40 pm, edited 1 time in total.
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: TGRAPH Technical Question

Postby Antonio Linares » Fri Dec 26, 2014 5:38 pm

George,

Many thanks

But what will happen if the Graph is only showing one serie only ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: TGRAPH Technical Question

Postby George » Fri Dec 26, 2014 5:43 pm

In my testing the tooltip is working fine with one series only:

[url][url=http://postimage.org/]Image[/url]
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: TGRAPH Technical Question

Postby Antonio Linares » Fri Dec 26, 2014 6:26 pm

George,

Also in Class TGraph there is only a DATA aSeries. I guess DATAs aSeries1 and aSeries2 are yours, in your own modification of Class TGraph.

DATA aSeries can hold n series, so you could use this:

Code: Select all  Expand view
   oGraph:cToolTip =  { | nAt, nSerie | nSerie := If( nAt % ;
                         Len( oGraph:aSeries ) == 0, Len( oGraph:aSeries ),;
                         Int( nAt % Len( oGraph:aSeries ) ) ),;
                         "Series: " + Alltrim( Str( nSerie ) ) + CRLF + ;
                         "Bar: " + AllTrim( Str( Int( nAt / Len( oGraph:aSeries ) ) + 1 + ;
                         If( nAt % Len( oGraph:aSeries ) == 0, -1, 0 ) ) ) }              
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: TGRAPH Technical Question

Postby George » Fri Dec 26, 2014 7:43 pm

Antonio,
I found that "METHOD AddSerie( aDat, cLegend, nColor, nType, l3D )" is creating the same aDat array twice (when using two series value) to hold first and second series.
This the reason that I had to add two arrays in this method in order to keep the two series number in separate array.

I think that this can be a start for you, or maybe a fellow programmer that knows better than me the TGRAPH class, can develop a generic method to display tooltips for "n" series values.

Regards,

George

Code: Select all  Expand view
METHOD AddSerie( aDat, cLegend, nColor, nType, l3D ) CLASS TGraph
    LOCAL nI
    DEFAULT nType := NIL, ;
        l3D   := NIL

    AAdd( ::aSeries, { cLegend, nColor, nType, l3D } )
    AAdd( ::aData , aDat )
    AAdd( ::aSTemp , { cLegend, nColor, nType, l3D } )
    AAdd( ::aDTemp, aDat )

  // Coded added
    IF len( ::aSeries ) = 1
        // Series 1
        FOR nX := 1 TO  LEN(aDat)
            aadd(::aSeries1, transform(int(aDat[nX]),  "@B 999,999" ) )
        NEXT
        ::cLabelSerie1 := ::aSeries[len( ::aSeries )] [1]
    ELSE
        // Series 2
        FOR nX := 1 TO  LEN(aDat)
            aadd(::aSeries2, transform(int(aDat[nX]*100),  "@B 999,999,999" ))
        NEXT
        ::cLabelSerie2 := ::aSeries[len( ::aSeries )] [1]
    ENDIF

RETURN Len( ::aSeries )
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: TGRAPH Technical Question

Postby Antonio Linares » Fri Dec 26, 2014 7:46 pm

George,

if you test the code that I have posted then you will see that you can already display tooltips for "n" series values
without having to modify that Class TGraph method.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: TGRAPH Technical Question

Postby Silvio.Falconi » Fri Dec 26, 2014 11:09 pm

Antonio,
can have on my email the new tgraph with last George ( and Linares) modifies please ?
Perhaps I made error to insert modifies
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: TGRAPH Technical Question

Postby George » Fri Dec 26, 2014 11:21 pm

You are right Antonio!
After reviewing a little more the TGRAPH class I am able to display the tooltips for one and two series with these additions only
Code: Select all  Expand view
//---------------------------------------------------------------------------
// To use Tooltips in TGRAPH Class (only tested with one and two series!)
//---------------------------------------------------------------------------
// In your program

oGraph:lToolTip := TRUE

oGraph:cToolTip =  { | nAt, nSerie, nRow, nCol | nSerie := If( nAt % ;
                         Len( oGraph:aSeries ) == 0, Len( oGraph:aSeries ),;
                         Int( nAt % Len( oGraph:aSeries ) ) ),;
                         oGraph:ToolTip( nAt, nRow, nCol, nSerie) }


//--------------------------------------------------------
// Data to be added to TGRAPH Class
//-----------------------------------------------------
DATA aBarCoors    
DATA lToolTip  INIT .F.


 //------------------------------------------------------------------------
 // Methods to add in TGRAPH Class
 //------------------------------------------------------------------------
 METHOD MouseMove( nRow, nCol, nFlags ) CLASS TGraph
    LOCAL nAt := 0
    if ::lToolTip = .T.
        if ! Empty( ::aBarCoors )
            nAt = AScan( ::aBarCoors,;
                { | aCoors | nRow <= aCoors[ 2 ] .and. ;
                nRow >= aCoors[ 2 ] - aCoors[ 3 ] .and. ;
                nCol >= aCoors[ 1 ] .and. ;
                nCol <= aCoors[ 1 ] + aCoors[ 4 ] } )
                if nAt != 0
                    ::ShowToolTip( nRow, nCol, Eval( ::cToolTip, nAt, nRow, nCol ) )
                else
                    ::DestroyTooltip()
                endif
            endif
        endif
return nil

//-------------------------------------------------------------------------
METHOD ToolTip(nAt, nRow, nCol, nSerie) CLASS TGRAPH
    LOCAL nSeries := len(::aSeries), nI
    if nSeries = 1
         ::ShowToolTip( nRow, nCol, ::aYVals[nAt] + CRLF+ ::aSeries[1][1] + " = " +  alltrim(str(::aData[1][nAT])))
    elseif nAt/2 - int(nAt/2) = 0
        // Even
        nI := int(nAt/nSeries)
         ::ShowToolTip( nRow, nCol, ::aYVals[nI] + CRLF+ ::aSeries[nSerie][1] +  " = "  +  alltrim(str(::aData[nSerie][nI])) )
    else
        // Odd
        nI := int(nAt/nSeries) + 1
        ::ShowToolTip( nRow, nCol, ::aYVals[nI] + CRLF+ ::aSeries[nSerie][1] + " = "  + alltrim(str(::aData[nSerie][nI])) )
    endif
 return nil
 


Regards,

George
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: TGRAPH Technical Question

Postby George » Fri Dec 26, 2014 11:23 pm

Silvio,
Please try the above code and let me know if this work for you.

Regards,

George
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: TGRAPH Technical Question

Postby Silvio.Falconi » Fri Dec 26, 2014 11:29 pm

Now it seem run here

I made :
DATA aBarCoors AS ARRAY INIT {} // Array with Bars coords. added by Antonio Linares
DATA aSeries1 AS ARRAY INIT {} // Array containing Series 1 Value
DATA aSeries2 AS ARRAY INIT {} // Array containing Series 2 Value

DATA cLabelSerie1 // Serie 1 Label
DATA cLabelSerie2 // Serie 2 Label

DATA lToolTip AS LOGIC INIT .F. // Default = FALSE


then I wish asl a question for the tooltip

oGraph:cToolTip = { | nAt, nSerie | nSerie := If( nAt % ;
Len( oGraph:aSeries ) == 0, Len( oGraph:aSeries ),;
Int( nAt % Len( oGraph:aSeries ) ) ),;
"Series: " + Alltrim( Str( nSerie ) ) + CRLF + ;
"Bar: " + AllTrim( Str( Int( nAt / Len( oGraph:aSeries ) ) + 1 + ;
If( nAt % Len( oGraph:aSeries ) == 0, -1, 0 ) ) ) }


I have :

oGraph:AddSerie(aEntrate,"Entrate",cClrEntrate)
oGraph:AddSerie(aUscite,"Uscite",cClrUscite)

If I want show the cLegend of each series and the his value how I can insert into ctooltip ? thanks
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 93 guests