Jump to content

Graphical Monitor of whatever


taietel
 Share

Recommended Posts

Andreik posted here a question regarding some graphical controls similar with the ones from task manager (which uses  DavesFrameClass controls).

This is an example to start with (still needs a lot of work):

Screenshot:

Posted Image

#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>
; sample control to monitor something (v2.0)
; by Mihai Iancu (aka taietel at yahoo dot com)
; modify to fit your needs
Global $points[1]
Global $aControl[8]
Global $hGui = GUICreate("A Whatever Monitor", 200, 120)
GUISetState(@SW_SHOW)

AdlibRegister("_Timer", 1000);register the timer

While 1
    Sleep(10)
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _Timer()
    Local $RandVal = Random(0,100,1); Replace this with your value to monitor
    ;let's generate graph based on my brain activity at this moment...
    _MControl_DrawGraph($RandVal)
    GUICtrlSetData($aControl[1],"taietel's brain:  "&$RandVal)
EndFunc

Func _MControl_Create($iX=10,$iY=10,$iW=180,$iH=80,$GridSpace=10,$GridColor=0x008800,$iBkColor=0x000000)
    If $iX = -1 Then $iX = 10
    If $iY = -1 Then $iY = 10
    If $iW < 180 Then $iW = 180
    If $iH < 80 Then $iH = 80

    Local $hGrafic = GUICtrlCreateGraphic($iX, $iY, $iW, $iH)
    GUICtrlSetColor(-1, $GridColor)
    GUICtrlSetBkColor(-1, $iBkColor)
    GUICtrlSetCursor(-1,0)

    Local $hValMon = GUICtrlCreateLabel("",$iX, $iY+$IH, $iW,12,BitOR($SS_LEFT,$SS_CENTERIMAGE))
    GUICtrlSetFont(-1,6,400,0,"Terminal")
    GUICtrlSetColor(-1,0x00CC00)
    GUICtrlSetBkColor(-1,0x000000)
    ;store the data
    _ArrayInsert($aControl,0,$hGrafic)
    _ArrayInsert($aControl,1,$hValMon)
    _ArrayInsert($aControl,2,$iX)
    _ArrayInsert($aControl,3,$iY)
    _ArrayInsert($aControl,4,$iW)
    _ArrayInsert($aControl,5,$iH)
    _ArrayInsert($aControl,6,$GridColor)
    _ArrayInsert($aControl,7,$GridSpace)
    Return $aControl
EndFunc

Func _MControl_DrawGraph($iValue)
    Local $MaxValue = 100
    Local $MinValue = 0
    Local $maxSteps
    Local $fromPoint
    Local $toPoint
    Local $Step = 3
    If $iValue< $MinValue Or $iValue > $MaxValue Then
        Return False
    Else
        $maxSteps = $aControl[4]/$Step
        If UBound($points) >= $maxSteps Then
            For $i = 1 To UBound($points)-1
                _ArraySwap($points[$i - 1],$points[$i])
                _ArrayDelete($points,$i)
                Return False
            Next
        EndIf
        _ArrayInsert($points,UBound($points),$iValue)
    GUICtrlDelete($aControl[0])
    _MControl_Create()
    For $i = $aControl[5] To 0 Step - $aControl[7]
        GUICtrlSetGraphic($aControl[0], $GUI_GR_COLOR, $aControl[6])
        GUICtrlSetGraphic($aControl[0], $GUI_GR_MOVE, 0, $i)
        GUICtrlSetGraphic($aControl[0], $GUI_GR_LINE, $aControl[4], $i)
    Next
    For $i = $aControl[7] - 1 To $aControl[4] Step $aControl[7]
        GUICtrlSetGraphic($aControl[0], $GUI_GR_MOVE, $i,0)
        GUICtrlSetGraphic($aControl[0], $GUI_GR_LINE, $i,$aControl[5])
    Next
    If UBound($points) > 0 Then
        For $i = 1 To UBound($points)-1
            $fromPoint = $aControl[5] / ($MaxValue - $MinValue) * ($points[$i - 1] - $MinValue)
            $toPoint = $aControl[5] / ($MaxValue - $MinValue) * ($points[$i] - $MinValue)
            GUICtrlSetGraphic($aControl[0], $GUI_GR_COLOR, 0xFFFF00)
            GUICtrlSetGraphic($aControl[0], $GUI_GR_MOVE, $aControl[4] - (UBound($points) - $i + 1) * $Step, $aControl[5] - $fromPoint)
            GUICtrlSetGraphic($aControl[0], $GUI_GR_LINE, $aControl[4] - (UBound($points) - $i) * $Step, $aControl[5] - $toPoint)
        Next
        GUICtrlSetGraphic($aControl[0], $GUI_GR_REFRESH)
    EndIf
        Return True
    EndIf
EndFunc

Feel free to use it!

M.I.

[edit] v1: it doesn't move when it reaches the left side. (29 downloads, replaced with v2)

         v2: Now it slides, but when it reaches the left side, it jumps a value (working on it...) 

Control_Monitor.au3

Edited by taietel
Link to comment
Share on other sites

Very cool. Nice job! I'm guessing using the basic AutoIt functions, it wouldn't be possible to scroll the graph too?

Link to comment
Share on other sites

Cool. A little birdie (I'm looking at you KaFu ;)) just told me about the Scrolling Line Graph UDF, which does scrolling and more - but its a bit more code of course, and requires GDIPlus. Most of that could probably be rewritten to use GDI32, but I'm not in dire need of such functionality really.

I was pretty surprised you were able to do as much as you have, using basic AutoIt functions I wasn't even aware of :)

Link to comment
Share on other sites

WARNING: silly little example follows...

; sample control to monitor something
; by Mihai Iancu (aka taietel at yahoo dot com)
; modify to fit your needs

#region Organize Includes
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

HotKeySet("{ESC}", "term")
OnAutoItExitRegister("_exit")

Global $aControl[6] ; this array stores data regarding the control
Global $m = 1 ; initiate timer
Global $oldval ; to store previous value of the graph
Global COnst $ScriptTitle = "Whatever Monitor"
Global Const $MilliSeconds = 86.7

; an approximate 1.5 hertz square wave -- hah is that possible? I guess, as long as it is not zero hertz    =O
;~ Global Const $SquareWaveString = "0,0,0,0,0,0,0,0,0,0,10,10,10,10,10,10,10,10,10,10,0,0,0,0,0,0,0,0,0,0,20,20,20,20,20,20,20,20,20,20,0,0,0,0,0,0,0,0,0,0,30,30,30,30,30,30,30,30,30,30,0,0,0,0,0,0,0,0,0,0,40,40,40,40,40,40,40,40,40,40,0,0,0,0,0,0,0,0,0,0,50,50,50,50,50,50,50,50,50,50,0,0,0,0,0,0,0,0,0,0,60,60,60,60,60,60,60,60,60,60,0,0,0,0,0,0,0,0,0,0,70,70,70,70,70,70,70,70,70,70,0,0,0,0,0,0,0,0,0,0,80,80,80,80,80,80,80,80,80,80,80,0"

; an approximate one hertz square wave of amplitude 90
;~ Global Const $SquareWaveString = "0,0,0,0,0,90,90,90,90,90,0,0,0,0,0,90,90,90,90,90,0,0,0,0,0,90,90,90,90,90,0,0,0,0,0,90,90,90,90,90,0,0,0,0,0,90,90,90,90,90,0,0,0,0,0,90,90,90,90,90,0,0,0,0,0,90,90,90,90,90,0,0,0,0,0,90,90,90,90,90,0,0,0,0,0,90,90,90,90,90,0,0,0,0,0,90,90,90,90,90,0,0,0,0,0,90,90,90,90,90,0,0,0,0,0,90,90,90,90,90,0,0,0,0,0,90,90,90,90,90,0,0,0,0,0,90,90,90,90,90,0,0,0,0,0,90,90,90,90,90,0,0,0,0,0,90,90,90,90,90,0,0,0,0"

;
Global Const $SquareWaveString = "0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,90,0,0,90,0"

Global Const $SquareWave = StringSplit($SquareWaveString, ',')

Global Const $hGui = GUICreate($ScriptTitle, 520, 132)

WinSetTrans($ScriptTitle, '', 230)

GUISetState()

_MControl_Create(-1, -1, 510, 100, 12)

AdlibRegister("_Timer", $MilliSeconds) ; register the timer

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _MControl_Create($iX = 10, $iY = 10, $iW = 120, $iH = 50, Const $iGridStep = 10, Const $iGridColor = 0x008800)

    If $iX = -1 Then $iX = 10
    If $iY = -1 Then $iY = 10
    If $iW < 120 Then $iW = 120
    If $iH < 50 Then $iH = 50
    If $iGridStep <= 0 Then Return SetError(-1, 0, 1)

    Local Const $hGrafic = GUICtrlCreateGraphic($iX, $iY, $iW, $iH)

    GUICtrlSetBkColor(-1, 0x000000)
    GUICtrlSetCursor(-1, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $iGridColor)

    For $i = 0 To $iH Step $iGridStep

        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, $iW, $i)

    Next

    For $j = 0 To $iW Step $iGridStep

        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $j, 0)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, $j, $iH)

    Next

    Local Const $hValMon = GUICtrlCreateLabel(' ', $iX, $iY + $iH + 1, $iW + 1, 12, BitOR($SS_LEFT, $SS_CENTERIMAGE))

    GUICtrlSetFont(-1, 6, 400, 0, "Terminal")
    GUICtrlSetColor(-1, 0x00CC00)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

    ; store the data I've told you about in the begining
    _ArrayInsert($aControl, 0, $hGrafic)
    _ArrayInsert($aControl, 1, $hValMon)
    _ArrayInsert($aControl, 2, $iX)
    _ArrayInsert($aControl, 3, $iY)
    _ArrayInsert($aControl, 4, $iW)
    _ArrayInsert($aControl, 5, $iH)

    Return $aControl
EndFunc ;==>_MControl_Create

Func _MControl_Graph($Value)

    If $Value >= $aControl[4] Then $Value = $aControl[4] - 1

    Local Const $Step = 3
    Local Const $w = $aControl[4]
    Local Const $h = $aControl[5]

    GUICtrlSetGraphic($aControl[0], $GUI_GR_COLOR, 0xFFFF00)
    GUICtrlSetGraphic($aControl[0], $GUI_GR_LINE, $w - $Step * $m, $h - $Value)
    GUICtrlSetGraphic($aControl[0], $GUI_GR_REFRESH)

    $oldval = $Value

    If $m = $SquareWave[0] Then

        MsgBox(64, $ScriptTitle, "This was just an example." & @CRLF & "Now play with it!")
        AdlibUnRegister()
        Exit
    EndIf
EndFunc ;==>_MControl_Graph

Func _Timer()

    ; generate square wave
    Local Const $v = $SquareWave[$m]
    _MControl_Graph($v)

    If $m <= 1 Then
        GUICtrlSetData($aControl[1], " Value: " & $v & ", Elapsed: " & $m * (100 / 1000) & " second")
    Else
        GUICtrlSetData($aControl[1], " Value: " & $v & ", Elapsed: " & $m * (100 / 1000) & " seconds")
    EndIf

    $m += 1 ; increment the value
EndFunc ;==>_Timer

Func term()
    Exit
EndFunc ;==>term

Func _exit()
    OnAutoItExitUnregister("_exit")
    GUIDelete($hGui)
EndFunc
Edited by jaberwocky6669
Link to comment
Share on other sites

jaberwocky6669, nice one!  ;) Playing already! 

Try to set the hGui transparency to 230, increase iH to 12 (the height of the label) and replace bg color of the label from 0x000000 to $GUI_BKCOLOR_TRANSPARENT. When I've changed those in your example, the graph didn't flicker; just the label, a little bit.

Link to comment
Share on other sites

Indeed there is far less flicker. Sweet!

I got this to work on my machine for 16.2 seconds (+/- one tenth of a second). So now it does an approximate one hertz squarewave.

See previous post #6 for the example update ^^^^

Link to comment
Share on other sites

urgent

this is something wrong with this scrip :

D:\Desktop\autoit joy\moniter.au3(15,29) : ERROR: AdlibRegister(): undefined function.

AdlibRegister("_Timer", 1000)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

D:\Desktop\autoit joy\moniter.au3 - 1 error(s), 0 warning(s)

Link to comment
Share on other sites

 johnlock, you have an older version of Autoit. Replace AdlibRegister with AdlibEnable.

[edit] Download the latest version of AutoIt and run it again, then see if the error occurs again.

Edited by taietel
Link to comment
Share on other sites

Andreik, this was more like a proof of concept. It flickers because it redraw the whole thing once the function is called (I'll use some functions of KaFu (*DeferWindowPos) for solving that). The data is stored in an array as it is processed, every "i" value becoming "i-1". I've tried not to use GDI, using just simple functions.

Zibit, I've thought of that, but I have to finish it first, with a little delay (some problems need to be solved first  ;) ). If you have more spare time, be my guest! :)

The "problem" with skipping a value when it reaches the left side is almost solved (was related with the array).

Link to comment
Share on other sites

Your problem with flickering can be mostly solved with use of:

1)GUI double buffer using 0x2000000 as an extended style

2) Put GUISetState(@SW_LOCK) and GUISetState(@SW_UNLOCK) around your re-graphing function, just before it's deleted and until just after it's refreshed.

Example:

#include <GUIConstantsEx.au3>

GUICreate("", 586, 314, -1, -1, -1, 0x2000000)

Global $aData[101]
Global $gGraph = _Graph_Create(50, 18, 513, 254)
_Graph_SetRange_X($gGraph, 1, 100, 0)
_Graph_SetRange_Y($gGraph, 0, 100, 10)
_Redraw()

GUISetState()
Do
    Sleep(50)
    _Randomise()
    _Redraw()
Until GUIGetMsg() = -3

Func _Randomise()
    For $i = 1 To 99
        $aData[$i] = $aData[$i + 1]
    Next
    $aData[100] = Random(0, 100)
EndFunc   ;==>_Randomise

Func _Redraw()
    GUISetState(@SW_LOCK)
    _Graph_Clear($gGraph)
    _Graph_SetGrid_X($gGraph, 5, 0x468c2f)
    _Graph_SetGrid_Y($gGraph, 10, 0x468c2f)
    _Graph_Set_Color($gGraph, 0xF9F32B)
    _Graph_Plot_Start($gGraph, 1, $gGraph[1])
    For $i = 1 To 100
        _Graph_Plot_Line($gGraph, $i, $aData[$i])
        _Graph_Plot_Point($gGraph, $i, $aData[$i])
    Next
    _Graph_Refresh($gGraph)
    GUISetState(@SW_UNLOCK)
EndFunc   ;==>_Redraw



;#### GRAPH UDF ###############################################################################################################

; #FUNCTION# ============================================================================
; Name...........: _Graph_Create
; Description ...: Creates graph area, and prepares array of specified data
; Syntax.........: _Graph_Create($iLeft,$iTop,$iWidth,$iHeight)
; Parameters ....: $iLeft - left most position in GUI
;                  $iTop - top most position in GUI
;                   $iWidth - width of graph in pixels
;                   $iHeight - height of graph in pixels
; Return values .: Returns array containing variables for subsequent functions...
;                    Returned Graph array is:
;                    [1] graphic control handle
;                    [2] left
;                    [3] top
;                    [4] width
;                    [5] height
;                    [6] x low
;                    [7] x high
;                    [8] y low
;                    [9] y high
;                    [10] x ticks handles
;                    [11] x labels handles
;                    [12] y ticks handles
;                    [13] y labels handles
;                    [14] Border Colour
;                    [15] Fill Colour
; =======================================================================================
Func _Graph_Create($iLeft, $iTop, $iWidth, $iHeight, $hColourBorder = 0x000000, $hColorFill = 0xFFFFFF)
    $hWnd = GUICtrlCreateGraphic($iLeft, $iTop, $iWidth + 1, $iHeight + 1)
    GUICtrlSetColor(-1, $hColourBorder)
    GUICtrlSetBkColor(-1, $hColorFill)
    Local $ahTicksLabelsX[1]
    Local $ahTicksLabelsY[1]
    Local $ahTicksX[1]
    Local $ahTicksY[1]
    Dim $aGraphArray[16] = ["", $hWnd, $iLeft, $iTop, $iWidth, $iHeight, 0, 1, 0, 1, _
            $ahTicksX, $ahTicksLabelsX, $ahTicksY, $ahTicksLabelsY, $hColourBorder, $hColorFill]
    Return $aGraphArray
EndFunc   ;==>_Graph_Create



; #FUNCTION# ============================================================================
; Name...........: _Graph_Delete
; Description ...: Deletes previously created graph and related ticks/labels
; Syntax.........: _Graph_Delete(ByRef $aGraphArray)
; Parameters ....: $aGraphArray - the array returned from _Graph_Create
; =======================================================================================
Func _Graph_Delete(ByRef $aGraphArray)
    ;----- delete x ticks/labels -----
    $ahTicksX = $aGraphArray[10]
    $ahTicksLabelsX = $aGraphArray[11]
    For $i = 1 to (UBound($ahTicksX) - 1)
        GUICtrlDelete($ahTicksX[$i])
    Next
    For $i = 1 to (UBound($ahTicksLabelsX) - 1)
        GUICtrlDelete($ahTicksLabelsX[$i])
    Next
    ;----- delete y ticks/labels -----
    $ahTicksY = $aGraphArray[12]
    $ahTicksLabelsY = $aGraphArray[13]
    For $i = 1 to (UBound($ahTicksY) - 1)
        GUICtrlDelete($ahTicksY[$i])
    Next
    For $i = 1 to (UBound($ahTicksLabelsY) - 1)
        GUICtrlDelete($ahTicksLabelsY[$i])
    Next
    Dim $ahTicksLabelsY[1]
    ;----- delete graphic control -----
    GUICtrlDelete($aGraphArray[1])
    ;----- close array -----
    $aGraphArray = 0
EndFunc   ;==>_Graph_Delete



; #FUNCTION# ============================================================================
; Name...........: _Graph_Clear
; Description ...: Clears graph content
; Syntax.........: _Graph_Clear(ByRef $aGraphArray)
; Parameters ....: $aGraphArray - the array returned from _Graph_Create
; =======================================================================================
Func _Graph_Clear(ByRef $aGraphArray)
    GUICtrlDelete($aGraphArray[1])
    $aGraphArray[1] = GUICtrlCreateGraphic($aGraphArray[2], $aGraphArray[3], _
            $aGraphArray[4] + 1, $aGraphArray[5] + 1)
    GUICtrlSetBkColor(-1, 0x000000)
    GUICtrlSetColor(-1, 0x000000)
EndFunc   ;==>_Graph_Clear



; #FUNCTION# ============================================================================
; Name...........: _Graph_SetRange_X
; Description ...: Allows user to set the range of the X axis and set ticks and rounding levels
; Syntax.........: _Graph_SetRange_X(ByRef $aGraphArray,$iLow,$iHigh,$iXTicks = 1,$bLabels = 1,$iRound = 0)
; Parameters ....:    $aGraphArray - the array returned from _Graph_Create
;                    $iLow - the lowest value for the X axis (can be negative)
;                    $iHigh - the highest value for the X axis
;                    $iXTicks - [optional] number of ticks to show below axis, if = 0 then no ticks created
;                    $bLabels - [optional] 1=show labels, any other number=do not show labels
;                    $iRound - [optional] rounding level of label values
; =======================================================================================
Func _Graph_SetRange_X(ByRef $aGraphArray, $iLow, $iHigh, $iXTicks = 1, $bLabels = 1, $iRound = 0)
    ;----- load user vars to array -----
    $aGraphArray[6] = $iLow
    $aGraphArray[7] = $iHigh
    ;----- prepare nested array -----
    $ahTicksX = $aGraphArray[10]
    $ahTicksLabelsX = $aGraphArray[11]
    ;----- delete any existing ticks -----
    For $i = 1 to (UBound($ahTicksX) - 1)
        GUICtrlDelete($ahTicksX[$i])
    Next
    Dim $ahTicksX[1]
    ;----- create new ticks -----
    For $i = 1 To $iXTicks + 1
        ReDim $ahTicksX[$i + 1]
        $ahTicksX[$i] = GUICtrlCreateLabel("", (($i - 1) * ($aGraphArray[4] / $iXTicks)) + $aGraphArray[2], _
                $aGraphArray[3] + $aGraphArray[5], 1, 5)
        GUICtrlSetBkColor(-1, 0x000000)
        GUICtrlSetState(-1, $GUI_DISABLE)
    Next
    ;----- delete any existing labels -----
    For $i = 1 to (UBound($ahTicksLabelsX) - 1)
        GUICtrlDelete($ahTicksLabelsX[$i])
    Next
    Dim $ahTicksLabelsX[1]
    ;----- create new labels -----
    For $i = 1 To $iXTicks + 1
        ReDim $ahTicksLabelsX[$i + 1]
        $ahTicksLabelsX[$i] = GUICtrlCreateLabel("", _
                ($aGraphArray[2] + (($aGraphArray[4] / $iXTicks) * ($i - 1))) - (($aGraphArray[4] / $iXTicks) / 2), _
                $aGraphArray[3] + $aGraphArray[5] + 10, $aGraphArray[4] / $iXTicks, 13, 1)
        GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    Next
    ;----- if labels are required, then fill -----
    If $bLabels = 1 Then
        For $i = 1 To (UBound($ahTicksLabelsX) - 1)
            GUICtrlSetData($ahTicksLabelsX[$i], _
                    StringFormat("%." & $iRound & "f", _Graph_Reference_Pixel("p", (($i - 1) * ($aGraphArray[4] / $iXTicks)), _
                    $aGraphArray[6], $aGraphArray[7], $aGraphArray[4])))
        Next
    EndIf
    ;----- load created arrays back into array -----
    $aGraphArray[10] = $ahTicksX
    $aGraphArray[11] = $ahTicksLabelsX
EndFunc   ;==>_Graph_SetRange_X



; #FUNCTION# ============================================================================
; Name...........: _Graph_SetRange_Y
; Description ...: Allows user to set the range of the Y axis and set ticks and rounding levels
; Syntax.........: _Graph_SetRange_Y(ByRef $aGraphArray,$iLow,$iHigh,$iYTicks = 1,$bLabels = 1,$iRound = 0)
; Parameters ....:    $aGraphArray - the array returned from _Graph_Create
;                    $iLow - the lowest value for the Y axis (can be negative)
;                    $iHigh - the highest value for the Y axis
;                    $iYTicks - [optional] number of ticks to show next to axis, if = 0 then no ticks created
;                    $bLabels - [optional] 1=show labels, any other number=do not show labels
;                    $iRound - [optional] rounding level of label values
; =======================================================================================
Func _Graph_SetRange_Y(ByRef $aGraphArray, $iLow, $iHigh, $iYTicks = 1, $bLabels = 1, $iRound = 0)
    ;----- load user vars to array -----
    $aGraphArray[8] = $iLow
    $aGraphArray[9] = $iHigh
    ;----- prepare nested array -----
    $ahTicksY = $aGraphArray[12]
    $ahTicksLabelsY = $aGraphArray[13]
    ;----- delete any existing ticks -----
    For $i = 1 to (UBound($ahTicksY) - 1)
        GUICtrlDelete($ahTicksY[$i])
    Next
    Dim $ahTicksY[1]
    ;----- create new ticks -----
    For $i = 1 To $iYTicks + 1
        ReDim $ahTicksY[$i + 1]
        $ahTicksY[$i] = GUICtrlCreateLabel("", $aGraphArray[2] - 5, _
                ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)), 5, 1)
        GUICtrlSetBkColor(-1, 0x000000)
        GUICtrlSetState(-1, $GUI_DISABLE)
    Next
    ;----- delete any existing labels -----
    For $i = 1 to (UBound($ahTicksLabelsY) - 1)
        GUICtrlDelete($ahTicksLabelsY[$i])
    Next
    Dim $ahTicksLabelsY[1]
    ;----- create new labels -----
    For $i = 1 To $iYTicks + 1
        ReDim $ahTicksLabelsY[$i + 1]
        $ahTicksLabelsY[$i] = GUICtrlCreateLabel("", $aGraphArray[2] - 40, _
                ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)) - 6, 30, 13, 2)
        GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    Next
    ;----- if labels are required, then fill -----
    If $bLabels = 1 Then
        For $i = 1 To (UBound($ahTicksLabelsY) - 1)
            GUICtrlSetData($ahTicksLabelsY[$i], StringFormat("%." & $iRound & "f", _Graph_Reference_Pixel("p", _
                    (($i - 1) * ($aGraphArray[5] / $iYTicks)), $aGraphArray[8], $aGraphArray[9], $aGraphArray[5])))
        Next
    EndIf
    ;----- load created arrays back into array -----
    $aGraphArray[12] = $ahTicksY
    $aGraphArray[13] = $ahTicksLabelsY
EndFunc   ;==>_Graph_SetRange_Y



; #FUNCTION# =============================================================================
; Name...........: _Graph_Plot_Start
; Description ...: Move starting point of plot
; Syntax.........: _Graph_Plot_Start(ByRef $aGraphArray,$iX,$iY)
; Parameters ....:     $aGraphArray - the array returned from _Graph_Create
;                    $iX - x value to start at
;                    $iY - y value to start at
; ========================================================================================
Func _Graph_Plot_Start(ByRef $aGraphArray, $iX, $iY)
    ;----- MOVE pen to start point -----
    GUICtrlSetGraphic($aGraphArray[1], $GUI_GR_MOVE, _
            _Graph_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _
            _Graph_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]))
EndFunc   ;==>_Graph_Plot_Start



; #FUNCTION# =============================================================================
; Name...........: _Graph_Plot_Line
; Description ...: draws straight line to x,y from previous point / starting point
; Syntax.........: _Graph_Plot_Line(ByRef $aGraphArray,$iX,$iY)
; Parameters ....:     $aGraphArray - the array returned from _Graph_Create
;                    $iX - x value to draw to
;                    $iY - y value to draw to
; ========================================================================================
Func _Graph_Plot_Line(ByRef $aGraphArray, $iX, $iY)
    ;----- Draw line from previous point to new point -----
    GUICtrlSetGraphic($aGraphArray[1], $GUI_GR_LINE, _
            _Graph_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _
            _Graph_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]))
EndFunc   ;==>_Graph_Plot_Line



; #FUNCTION# =============================================================================
; Name...........: _Graph_Plot_Point
; Description ...: draws point at coords
; Syntax.........: _Graph_Plot_Point(ByRef $aGraphArray,$iX,$iY)
; Parameters ....:     $aGraphArray - the array returned from _Graph_Create
;                    $iX - x value to draw at
;                    $iY - y value to draw at
; ========================================================================================
Func _Graph_Plot_Point(ByRef $aGraphArray, $iX, $iY)
    ;----- Draw point from previous point to new point -----
    GUICtrlSetGraphic($aGraphArray[1], $GUI_GR_DOT, _
            _Graph_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _
            _Graph_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]))
EndFunc   ;==>_Graph_Plot_Point



; #FUNCTION# =============================================================================
; Name...........: _Graph_Plot_Dot
; Description ...: draws single pixel dot at coords
; Syntax.........: _Graph_Plot_Dot(ByRef $aGraphArray,$iX,$iY)
; Parameters ....:   $aGraphArray - the array returned from _Graph_Create
;                    $iX - x value to draw at
;                    $iY - y value to draw at
; ========================================================================================
Func _Graph_Plot_Dot(ByRef $aGraphArray, $iX, $iY)
    ;----- Draw point from previous point to new point -----
    GUICtrlSetGraphic($aGraphArray[1], $GUI_GR_PIXEL, _
            _Graph_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _
            _Graph_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]))
EndFunc   ;==>_Graph_Plot_Dot



; #FUNCTION# =============================================================================
; Name...........: _Graph_Set_Color
; Description ...: sets the color for the next drawing
; Syntax.........: _Graph_Set_Color(ByRef $aGraphArray,$hColor,$hBkGrdColor = $GUI_GR_NOBKCOLOR)
; Parameters ....:   $aGraphArray - the array returned from _Graph_Create
;                    $hColor - the color of the next item
;                    $hBkGrdColor - the background color of the next item
; ========================================================================================
Func _Graph_Set_Color(ByRef $aGraphArray, $hColor, $hBkGrdColor = $GUI_GR_NOBKCOLOR)
    GUICtrlSetGraphic($aGraphArray[1], $GUI_GR_COLOR, $hColor, $hBkGrdColor)
EndFunc   ;==>_Graph_Set_Color



; #FUNCTION# =============================================================================
; Name...........: _Graph_Set_PenSize
; Description ...: sets the pen for the next drawing
; Syntax.........: _Graph_Set_PenSize(ByRef $aGraphArray,$iSize = 1)
; Parameters ....:   $aGraphArray - the array returned from _Graph_Create
;                    $iSize - size of pen line
; ========================================================================================
Func _Graph_Set_PenSize(ByRef $aGraphArray, $iSize = 1)
    GUICtrlSetGraphic($aGraphArray[1], $GUI_GR_PENSIZE, $iSize)
EndFunc   ;==>_Graph_Set_PenSize



; #FUNCTION# =============================================================================
; Name...........: _Graph_Plot_Bar_X
; Description ...: Draws bar chart bar from the x axis
; Syntax.........: _Graph_Plot_Bar_X(ByRef $aGraphArray,$iStart,$iWidth,$nYValue,$hColor = 0x000000,$hBkGrdColor = $GUI_GR_NOBKCOLOR)
; Parameters ....:   $aGraphArray - the array returned from _Graph_Create
;                    $iStart - the x axis value for start of bar (in x axis units)
;                    $iWidth - width of the bar (in x axis units)
;                    $nYValue - 'height' of the bar (in y axis units)
;                    $hColor - Bar border colour
;                    $hBkGrdColor - Bar fill colour
; ========================================================================================
Func _Graph_Plot_Bar_X(ByRef $aGraphArray, $iStart, $iWidth, $nYValue, $hColor = 0x000000, $hBkGrdColor = $GUI_GR_NOBKCOLOR)
    ;----- Draw Bar for BarChart Application -----
    _Graph_Set_Color($aGraphArray, $hColor, $hBkGrdColor)
    GUICtrlSetGraphic($aGraphArray[1], $GUI_GR_RECT, _
            _Graph_Reference_Pixel("x", $iStart, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ ;x
            $aGraphArray[5] + 1, _
            Round(_Graph_Reference_Pixel("x", $iStart + $iWidth, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) - _ ;width
            _Graph_Reference_Pixel("x", $iStart, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) + 1), _
             -$aGraphArray[5] + _Graph_Reference_Pixel("y", $nYValue, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) - 1) ;height
    ;- redraw axis in case coloured -
    _Graph_Set_Color($aGraphArray, $aGraphArray[14], $GUI_GR_NOBKCOLOR)
    GUICtrlSetGraphic($aGraphArray[1], $GUI_GR_RECT, 0, 0, $aGraphArray[4] + 1, $aGraphArray[5] + 1)
    ;- set colour back to default -
    _Graph_Set_Color($aGraphArray, 0x000000, $GUI_GR_NOBKCOLOR)
EndFunc   ;==>_Graph_Plot_Bar_X



; #FUNCTION# =============================================================================
; Name...........: _Graph_Plot_Bar_Y
; Description ...: Draws bar chart bar from the y axis
; Syntax.........: _Graph_Plot_Bar_Y(ByRef $aGraphArray,$iStart,$iWidth,$nYValue,$hColor = 0x000000,$hBkGrdColor = $GUI_GR_NOBKCOLOR)
; Parameters ....:   $aGraphArray - the array returned from _Graph_Create
;                    $iStart - the y axis value for start of bar (in y axis units)
;                    $iWidth - width of the bar (in y axis units)
;                    $nXValue - 'length' of the bar (in x axis units)
;                    $hColor - Bar border colour
;                    $hBkGrdColor - Bar fill colour
; ========================================================================================
Func _Graph_Plot_Bar_Y(ByRef $aGraphArray, $iStart, $iWidth, $nYValue, $hColor = 0x000000, $hBkGrdColor = $GUI_GR_NOBKCOLOR)
    ;----- Draw Bar for BarChart Application -----
    _Graph_Set_Color($aGraphArray, $hColor, $hBkGrdColor)
    GUICtrlSetGraphic($aGraphArray[1], $GUI_GR_RECT, _
            0, _ ;x
            _Graph_Reference_Pixel("y", $iStart + $iWidth, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ ;y
            _Graph_Reference_Pixel("x", $nYValue, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) + 1, _ ;width
            _Graph_Reference_Pixel("y", $iStart, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) - _ ;height
            _Graph_Reference_Pixel("y", $iStart + $iWidth, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) + 1)
    ;- redraw axis in case coloured -
    _Graph_Set_Color($aGraphArray, $aGraphArray[14], $GUI_GR_NOBKCOLOR)
    GUICtrlSetGraphic($aGraphArray[1], $GUI_GR_RECT, 0, 0, $aGraphArray[4] + 1, $aGraphArray[5] + 1)
    ;- set colour back to default -
    _Graph_Set_Color($aGraphArray, 0x000000, $GUI_GR_NOBKCOLOR)
EndFunc   ;==>_Graph_Plot_Bar_Y



; #FUNCTION# =============================================================================
; Name...........: _Graph_SetGrid_X
; Description ...: Adds X gridlines.
; Syntax.........: _Graph_SetGrid(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0)
; Parameters ....:  $aGraphArray - the array returned from _Graph_Create
;                   $Ticks - sets line at every nth unit assigned to axis
;                   $hColor - [optional] RGB value, defining color of grid. Default is a light gray
; =======================================================================================
Func _Graph_SetGrid_X(ByRef $aGraphArray, $Ticks = 1, $hColor = 0xf0f0f0)
    _Graph_Set_Color($aGraphArray, $hColor, $GUI_GR_NOBKCOLOR)
    Select
        Case $Ticks > 0
            For $i = $aGraphArray[6] To $aGraphArray[7] Step $Ticks
                If $i = Number($aGraphArray[6]) Or $i = Number($aGraphArray[7]) Then ContinueLoop
                GUICtrlSetGraphic($aGraphArray[1], $GUI_GR_RECT, _ ;rectangle
                        _Graph_Reference_Pixel("x", $i, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ ;x
                        1, _ ;y
                        1, _ ;width
                        $aGraphArray[5] - 1) ;height
            Next
    EndSelect
    _Graph_Set_Color($aGraphArray, 0x000000)
EndFunc   ;==>_Graph_SetGrid_X



; #FUNCTION# =============================================================================
; Name...........: _Graph_SetGrid_Y
; Description ...: Adds Y gridlines.
; Syntax.........: _Graph_SetGrid(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0)
; Parameters ....:  $aGraphArray - the array returned from _Graph_Create
;                   $Ticks - sets line at every nth unit assigned to axis
;                   $hColor - [optional] RGB value, defining color of grid. Default is a light gray
; =======================================================================================
Func _Graph_SetGrid_Y(ByRef $aGraphArray, $Ticks = 1, $hColor = 0xf0f0f0)
    _Graph_Set_Color($aGraphArray, $hColor, $GUI_GR_NOBKCOLOR)
    Select
        Case $Ticks > 0
            For $i = $aGraphArray[8] To $aGraphArray[9] Step $Ticks
                If $i = Number($aGraphArray[8]) Or $i = Number($aGraphArray[9]) Then ContinueLoop
                GUICtrlSetGraphic($aGraphArray[1], $GUI_GR_RECT, _ ;rectangle
                        1, _ ;x
                        _Graph_Reference_Pixel("y", $i, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ ;y
                        $aGraphArray[4] - 1, _ ;width
                        1) ;height
            Next
    EndSelect
    _Graph_Set_Color($aGraphArray, 0x000000)
EndFunc   ;==>_Graph_SetGrid_Y



; #FUNCTION# =============================================================================
; Name...........: _Graph_Refresh
; Description ...: refreshes the graphic
; Syntax.........: _Graph_Refresh(ByRef $aGraphArray)
; Parameters ....:   $aGraphArray - the array returned from _Graph_Create
; ========================================================================================
Func _Graph_Refresh(ByRef $aGraphArray)
    GUICtrlSetGraphic($aGraphArray[1], $GUI_GR_REFRESH)
EndFunc   ;==>_Graph_Refresh



; #FUNCTION# =============================================================================
; Name...........: _Graph_Reference_Pixel
; Description ...: INTERNAL FUNCTION - performs pixel reference calculations
; Syntax.........: _Graph_Reference_Pixel($iType,$iValue,$iLow,$iHigh,$iTotalPixels)
; Parameters ....:     $iType - "x"=x axis pix, "y" = y axis pix, "p"=value from pixels
;                    $iValue - pixels reference or value
;                    $iLow - lower limit of axis
;                    $iHigh - upper limit of axis
;                    $iTotalPixels - total number of pixels in range (either width or height)
; =========================================================================================
Func _Graph_Reference_Pixel($iType, $iValue, $iLow, $iHigh, $iTotalPixels)
    ;----- perform pixel reference calculations -----
    Switch $iType
        Case "x"
            Return (($iTotalPixels / ($iHigh - $iLow)) * (($iHigh - $iLow) * (($iValue - $iLow) / ($iHigh - $iLow))))
        Case "y"
            Return ($iTotalPixels - (($iTotalPixels / ($iHigh - $iLow)) * (($iHigh - $iLow) * (($iValue - $iLow) / ($iHigh - $iLow)))))
        Case "p"
            Return ($iValue / ($iTotalPixels / ($iHigh - $iLow))) + $iLow
    EndSwitch
EndFunc   ;==>_Graph_Reference_Pixel
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...