Wish xGraph Provide a hook to enable replacement of the index value of Draw Cursors with a lookup for dates

rgarnett1955

Active Member
Licensed User
Longtime User
Hi

I love the traveling cursor annotations, but the index value is not always useful, particularly where times and dates for the underlying index values.

Would it be possible to add a feature that calls an external sub with the index value and that sub returns either a number or a date string. Quite often process data has large time gaps which are recorded with time stamps, but which the index doesn't show and the x values of the graph don't reflect.

I realize you can capture mouse moves and process the index in that sub and output the date time to a label field, but it would be really nice to replace dateTimes in the traveling annotation.

It's just a thought, not essential, but it would be rather nice.
CursorCaptionWithDateTime.png




Best regards
Rob
 

rgarnett1955

Active Member
Licensed User
Longtime User
Hi Klaus,

I did a mod to xGraph to provide for data-times and am posting it in case anyone else has a similar need.

I added this code
x Graph Code Mos's to display date time in cursor annotations:
Private xDataType As Int                ' Sets whether to display default inded: vale or date time
Public CurveXLookupDates(10000) As Long 'rjg stores millisecond ticks

    'Draws the cursor values
    If mDrawCursorValues = True Then
        For i = 0 To lstTwoCursors.Size - 1
            TC = lstTwoCursors.Get(i)
            If TC.XIndex >= ScaleX.IBegin And TC.XIndex <= ScaleX.IEnd Then
                x = Graph.Left + (TC.XIndex - ScaleX.IBegin) / (ScaleX.IEnd - ScaleX.IBegin) * Graph.Width
'                Txt = "  Index = " & TC.XIndex & "  "

                ' rjg block mod start
                Select xDataType
                    Case 0
                        Txt = "  " & TC.XIndex & " : " & NumberFormat3(CurveX(TC.XIndex), 6) & "  "
                        
                    Case 1
                        Txt = "  " & DateTime.Time(CurveXLookupDates(TC.XIndex)) & "  "
                        
                    Case 2
                        Txt = "  " & DateTime.Date(CurveXLookupDates(TC.XIndex)) & "
                        
                    Case 3
                        Txt = "  " & DateTime.Date(CurveXLookupDates(TC.XIndex)) & "  "  & DateTime.Time(CurveXLookupDates(TC.XIndex)) & " "
                    
                    Case Else
                        Txt = "  " & TC.XIndex & " : " & NumberFormat3(CurveX(TC.XIndex), 6) & "  "
                End Select
                ' rjg block mod end

                TxtWidth = MeasureTextWidth(Txt, Texts.ScaleFont)
                For c = 0 To lstCurvesToDisplay.Size - 1
                    Txt = " " & NumberFormat3(CurveY(lstCurvesToDisplay.Get(c), TC.XIndex), 6) & " "
                    TxtWidth = Max(TxtWidth, MeasureTextWidth(Txt, Texts.ScaleFont))
                Next
                TxtWidth_2 = TxtWidth / 2
                TxtHeight = Texts.ScaleTextHeight * (lstCurvesToDisplay.Size + 1) + 0.4 * Texts.ScaleTextHeight
                TxtColor =  xui.Color_White
'                TxtColor = xui.Color_ARGB(200, 255, 255, 255)
                xt = Min(x, Graph.Right - TxtWidth_2)
                xt = Max(xt, Graph.Left + TxtWidth_2)
                If i = 1 And Abs(xt - x1) < TxtWidth Then
                    yt = Graph.Top + 2 * xd  + TxtHeight + 3dip
                Else
                    yt = Graph.Top + 2 * xd
                    x1 = xt
                End If
                RectTxt.Initialize(xt - TxtWidth_2, yt, xt + TxtWidth_2, yt + TxtHeight)
                xcvsTwoCursors.DrawRect(RectTxt, TxtColor, True, 1dip)
'                Txt = "  Index = " & TC.XIndex & "  "
                ' rjg block mod start
                Select xDataType
                    Case 0
                        Txt = "  " & TC.XIndex & " : " & NumberFormat3(CurveX(TC.XIndex), 6) & "  "
                        
                    Case 1
                        Txt = "  " & DateTime.Time(CurveXLookupDates(TC.XIndex)) & "  "
                        
                    Case 2
                        Txt = "  " & DateTime.Date(CurveXLookupDates(TC.XIndex)) & "
                        
                    Case 3
                        Txt = "  " & DateTime.Date(CurveXLookupDates(TC.XIndex)) & "  "  & DateTime.Time(CurveXLookupDates(TC.XIndex)) & " "
                    
                    Case Else
                        Txt = "  " & TC.XIndex & " : " & NumberFormat3(CurveX(TC.XIndex), 6) & "  "
                End Select
                ' rjg block mod end
                xcvsTwoCursors.DrawText(Txt, xt, yt + Texts.ScaleTextHeight, Texts.ScaleFont, TC.Color, "CENTER")
                yt = yt + Texts.ScaleTextHeight
                For nc = 0 To lstCurvesToDisplay.Size - 1
                    c = lstCurvesToDisplay.Get(nc)
                    If mUseCustomColors = False Then
                        col = CurveColor(nc)
                    Else
                        col = CurveCustomColor(c)
                    End If
                    If mGraphWithMissingData = True And CurveY(lstCurvesToDisplay.Get(nc), TC.XIndex) >= mMissingDataValue Then
                        Txt = "NaN"
                    Else
                        Txt = NumberFormat3(CurveY(lstCurvesToDisplay.Get(nc), TC.XIndex), 6)
                    End If
                    yt = yt + Texts.ScaleTextHeight
                    xcvsTwoCursors.DrawText(Txt, xt, yt, Texts.ScaleFont, col, "CENTER")
                Next
            End If
        Next
    End If
    xcvsTwoCursors.Invalidate
End Sub

There are a couple of functions for setting and getting the desired output.

Functions to set desired x annotations:
' Sets the type for data display in the cursors
'0 = Use index
'1 = Looked up vars Date-Time ticks - display Time
'2 = Looked up vars Date-Time ticks - display Date
'3 = Looked up vars Date-Time ticks - display Date and Time
Public Sub setXLookupDataType(dataType As Int)
    xDataType = dataType
End Sub


' Gets the type for data display in the cursors
'0 = Use index
'1 = Looked up vars Date-Time ticks - display Time
'2 = Looked up vars Date-Time ticks - display Date
'3 = Looked up vars Date-Time ticks - display Date and Time
Public Sub getXLookupDataType As Int
    Return xDataType
End Sub


The output is shown below:

Snag_36a2b8a5.png


Regards
Rob
 

Attachments

  • xGraph_rjg.zip
    17.3 KB · Views: 205
Top