' Name: Plot_Bar
'
' Title: Plot bar time series graph
'
' Topics: Views
'
' Description: Plot data as vertical thin bars (doesn't work when zoomed out)
'              
' Author: Michael Silberbauer 2001
' Institute for Water Quality Studies, Department of Water and Sanitation
' Private Bag X313 PRETORIA South Africa 0001
' Requires:
'
' Self:av.Run( "Plot_Bar", { MinX, MaxX, MinY, MaxY, OriginX, OriginY, ScaleX, ScaleY, theVTab, theBitMap, PlotItem, Guideline } )
'
' Results:
' -----------------------------------------------------------------------------

MinX = Self.Get(0)
MaxX = Self.Get(1)
MinY = Self.Get(2)
MaxY = Self.Get(3)
OriginX = Self.Get(4)
OriginY = Self.Get(5)
ScaleX = Self.Get(6)
ScaleY = Self.Get(7)
theVTab = Self.Get(8)
theBitMap = Self.Get(9)
PlotItem = Self.Get(10)
Guideline = Self.Get(11)
theProject = av.GetProject
theView = av.GetActiveDoc
theGraphics = theView.GetGraphics
theDisplay = theView.GetDisplay
theVarField = theVTab.FindField(PlotItem.AsString)
the_nDateField = theVTab.FindField("Ndate")
theDateField = theVTab.FindField("Date")
theTimeField = theVTab.FindField("Time")

' Plot each data point as a vertical bar:
' the part exceeding the set guideline is red.

totalBits = theBitMap.GetSize
selBits = theBitMap.Count
av.ClearMsg
av.ClearStatus
record = 0
av.ShowMsg("Plotting graph of"++PlotItem.AsString++"...")
if (selBits>0) then
  VariableY2 = OriginY+((Guideline-MinY)*ScaleY)
  for each rec in theBitMap
    record = record+1
    av.SetStatus(100*(record/selBits))
    Variable = theVTab.ReturnValue(theVarField,rec)
    TimeText = theVTab.ReturnValue(theTimeField,rec)
    nDate = theVTab.ReturnValue(theDateField,rec)
    nDate = nDate.SetFormat("J").AsString.AsNumber
    hTime = (TimeText.AsNumber/100).Round
    mTime = (TimeText.AsNumber/100)-hTime
    mTime = mTime/60
    nDate = nDate+((hTime+mTime)/24)
    nDate0 = nDate-0.25
    nDate2 = nDate+0.25
    if (Variable>=0) then
      VariableX = OriginX+((nDate-MinX)*ScaleX)
      VariableX0 = OriginX+((nDate-MinX)*ScaleX)
      VariableX2 = OriginX+((nDate2-MinX)*ScaleX)
      VariableY = OriginY+((Variable-MinY)*ScaleY)
      if (Variable<=Guideline) then
        aRect = Rect.MakeXY(VariableX0,OriginY,VariableX2,VariableY)
        gRect = GraphicShape.Make(aRect)
        aSymbol = RasterFill.Make
        aSymbol.SetColor(Color.GetBlack)
        aSymbol.SetOLColor(Color.GetBlack)
        gRect.SetSymbol(aSymbol)
        theGraphics.AddBatch(gRect)
      else
        aRect = Rect.MakeXY(VariableX0,OriginY,VariableX2,VariableY2)
        gRect = GraphicShape.Make(aRect)
        aSymbol = RasterFill.Make
        aSymbol.SetColor(Color.GetBlack)
        aSymbol.SetOLColor(Color.GetBlack)
        gRect.SetSymbol(aSymbol)
        theGraphics.AddBatch(gRect)
        aRect = Rect.MakeXY(VariableX0,VariableY2,VariableX2,VariableY)
        gRect = GraphicShape.Make(aRect)
        aSymbol = RasterFill.Make
        aSymbol.SetColor(Color.GetRed)
        aSymbol.SetOLColor(Color.GetRed)
        gRect.SetSymbol(aSymbol)
        theGraphics.AddBatch(gRect)
      end
    end
  end
end
theGraphics.EndBatch
return {}