# Introduced when a change to the TCA loading affected Larry at APL, but Autoplot was unaffected because it used a 
# different route.  This sets the QFunction directly instead of via Java reflection.

reset()

from org.virbo.dataset import DDataSet
descriptor= DDataSet.createRank2(3,0)
descriptor.putProperty(QDataSet.LABEL,0,"x");
descriptor.putProperty(QDataSet.UNITS,0,Units.seconds);
descriptor.putProperty(QDataSet.FORMAT,0,"%5.1f");
descriptor.putProperty(QDataSet.LABEL,1,"cos(x)");
descriptor.putProperty(QDataSet.UNITS,1,Units.seconds);
descriptor.putProperty(QDataSet.FORMAT,1,"%5.2f");
descriptor.putProperty(QDataSet.LABEL,2,"sin(x)");
descriptor.putProperty(QDataSet.UNITS,2,Units.seconds);
descriptor.putProperty(QDataSet.FORMAT,2,"%5.2f");

from org.virbo.dataset import AbstractQFunction

class MyQF( AbstractQFunction ):

   def exampleInput( self ):
      return dataset( '2014-09-16T00:00Z' )

   def value( self, t ):
      x= abs( modp( convertUnitsTo(t-self.exampleInput(),Units.seconds), '86400s' ) )
      ret= dataset( [ x,cos(x),sin(x)] )
      ret.putProperty(QDataSet.BUNDLE_0,descriptor)
      return ret

import time
time.sleep(1)

dom.plots[0].xaxis.controller.dasAxis.setTcaFunction( MyQF() )
dom.plots[0].xaxis.controller.dasAxis.setDrawTca(True)
bind( dom, 'timeRange', dom.plots[0].xaxis, 'range' )

import time
#time.sleep(1)

writeToPng( 'test037_timeTcaQFunctionTest.png' )

#from java.io import File
#print File('test037_tcaQFunctionTest.png').absolutePath

