#!/usr/local/bin/ruby
#
#
# ./timeaxis.rb

require "ClibPDF"

respmax = 10.0
yearformat = ClibPDF::YEAR_2DIGIT

pdf = ClibPDF::PDF.open(0)
pdf.enableCompression(ClibPDF::YES)
pdf.init
pdf.pageInit(1, ClibPDF::PORTRAIT, ClibPDF::LETTER, ClibPDF::LETTER)
pdf.translate(0.0, 1.0)

tm = Time.mktime(1998, 1, 1, 0, 0, 0)
ybump = 0.5*ClibPDF::INCH

tm2 = tm + 60 * 60 * 4
yoffset = -0.2*ClibPDF::INCH

timeDomain = ClibPDF::TimePlotDomain.new( 1.0*ClibPDF::INCH, 8.0*ClibPDF::INCH,
													  4.0*ClibPDF::INCH, 0.5*ClibPDF::INCH,
													  tm, tm2, 0.0, respmax, ClibPDF::TIME, ClibPDF::LINEAR, 0)
oldDomain = pdf.setPlotDomain(timeDomain)
timeDomain.fillDomainWithGray(0.85)

pdf.setgray(0.0)
tAxis = ClibPDF::TimeAxis.new(0.0, 4.0*ClibPDF::INCH, ClibPDF::TIME, tm, tm2)
tAxis.attachAxisToDomain(timeDomain, 0.0, yoffset)
tAxis.setTimeAxisNumberFormat(ClibPDF::MONTH_NAME, ClibPDF::YEAR_2DIGIT, "Helvetica", 11.0)
tAxis.drawAxis()
tAxis.freeAxis()

for i in 0..3
  case i
  when 0
	tm2 = Time.mktime(1998, 1, 2, 0, 0, 0)
  when 1
	tm2 = Time.mktime(1998, 1, 5, 0, 0, 0)
  when 2
	tm2 = Time.mktime(1998, 7, 1, 0, 0, 0)
  when 3
	tm2 = Time.mktime(2002, 1, 1, 0, 0, 0)
	yearformat = ClibPDF::YEAR_FULL
  end
  yoffset -= ybump
  pdf.setgray(0.0)
  tAxis = ClibPDF::TimeAxis.new(0.0, 4.0*ClibPDF::INCH, ClibPDF::TIME, tm, tm2)
  tAxis.attachAxisToDomain(timeDomain, 0.0, yoffset)
  tAxis.setTimeAxisNumberFormat(ClibPDF::MONTH_NAME, yearformat, "Helvetica", 11.0)
  tAxis.drawAxis()
  tAxis.freeAxis()
end

pdf.setPlotDomain(oldDomain)
timeDomain.freePlotDomain

pdf.finalizeAll
pdf.savePDFmemoryStreamToFile("timeaxis.pdf")

#pdf.launchPreview
pdf.close
