' Name: Plot_Stick_Type3
'
' Title: Plot stick time-series graphs (thin bars) for 3-range pH
'
' Topics: Views
'
' Description: Plot data as vertical "sticks" or thin bars
'              
' 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_Stick_Type2", { MinX, MaxX, MinY, MaxY, OriginX, OriginY, ScaleX, ScaleY, theVTab, theBitMap, PlotItem, Guidelines, ColList } )
'
' 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)
Guidelines = Self.Get(11)
ColList = Self.Get(12)
nib = 1
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 starting from pH 7 (neutral):
' any part exceeding the set guidelines is coloured according to the rules in classcodes.txt.

totalBits = theBitMap.GetSize
selBits = theBitMap.Count
av.ClearMsg
av.ClearStatus
record = 0
if (selBits>0) then
  OriginY7 = OriginY+((7-MinY)*ScaleY)
  Y_List = List.Make
  nGuide = 0
  for each Guideline in Guidelines
    VariableYg = OriginY+((Guideline-MinY)*ScaleY)
    Y_List.Add(VariableYg)
    nGuide = nGuide+1
  end
  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
      av.ShowMsg("Plotting graph of"++PlotItem.AsString++"="++Variable.AsString++"...")
      VariableX = OriginX+((nDate-MinX)*ScaleX)
      VariableY = OriginY+((Variable-MinY)*ScaleY)
      ' Three cases

      if (Variable<=Guidelines.Get(0)) then
        aLine = Line.Make(VariableX@Y_List.Get(0),VariableX@VariableY)
        gLine = GraphicShape.Make(aLine)
        'aSymbol = gLine.GetSymbol.SetColor( ColList.Get( 4 ) )

        FatLine = BasicPen.Make
        FatLine.SetSize(nib)
        FatLine.SetColor(Color.GetRed)
        aSymbol = gLine.SetSymbol(FatLine)
        theGraphics.AddBatch(gLine)
        aLine = Line.Make(VariableX@OriginY7,VariableX@Y_List.Get(0))
        'aLine = Line.Make( VariableX@Y_List.Get( 1 ),VariableX@Y_List.Get( 0 ) )

        gLine = GraphicShape.Make(aLine)
        'aSymbol = gLine.GetSymbol.SetColor( ColList.Get( 3 ) )

        FatLine = BasicPen.Make
        FatLine.SetSize(nib)
        FatLine.SetColor(Color.GetGreen)
        aSymbol = gLine.SetSymbol(FatLine)
        theGraphics.AddBatch(gLine)
      end
      if ((Variable>Guidelines.Get(0)) and (Variable<=Guidelines.Get(1))) then
        aLine = Line.Make(VariableX@OriginY7,VariableX@VariableY)
        gLine = GraphicShape.Make(aLine)
        FatLine = BasicPen.Make
        FatLine.SetSize(nib)
        FatLine.SetColor(Color.GetGreen)
        aSymbol = gLine.SetSymbol(FatLine)
        theGraphics.AddBatch(gLine)
      end
      if (Variable>=Guidelines.Get(1)) then
        aLine = Line.Make(VariableX@Y_List.Get(1),VariableX@VariableY)
        gLine = GraphicShape.Make(aLine)
        FatLine = BasicPen.Make
        FatLine.SetSize(nib)
        FatLine.SetColor(Color.GetCyan)
        aSymbol = gLine.SetSymbol(FatLine)
        theGraphics.AddBatch(gLine)
        aLine = Line.Make(VariableX@OriginY7,VariableX@Y_List.Get(1))
        gLine = GraphicShape.Make(aLine)
        FatLine = BasicPen.Make
        FatLine.SetSize(nib)
        FatLine.SetColor(Color.GetGreen)
        aSymbol = gLine.SetSymbol(FatLine)
        theGraphics.AddBatch(gLine)
      end
    end
  end
end
theGraphics.EndBatch
return {}