[reportlab-users] Need to extend NormalDateXValueAxis to be with hour, minute and second

Robin Becker robin at reportlab.com
Mon May 9 13:01:41 EDT 2016






On 09/05/2016 12:30, Fatih Karatana wrote:
> Hi,
>
> In the current version, we have only date value on
> NormalDateXValueAxis like "yyyy-mm-dd", but what I need to extend this display
> by including hour, minutes and seconds too.
>
> It will certainly help on my project to arrange the LinePlot graph
> values by hourly period.
>
> Any help and advice will be appreciated.
..

I started on this and got so far as

class TimeValueAxis(ValueAxis):
	_mc = 60
	_hc = 60*_mc
	_dc = 24*_hc

	def __init__(self,*args,**kwds):
		ValueAxis.__init__(self,*args,**kwds)
		if not self.labelTextFormat:
			self.labelTextFormat = self.timeLabelTextFormatter

	def _calcValueStep(self):
		'''Calculate _valueStep for the axis or get from valueStep.'''
		if self.valueStep is None:
			rawRange = self._valueMax - self._valueMin
			rawInterval = rawRange / 
min(float(self.maximumTicks-1),(float(self._length)/self.minimumTickSpacing))
			#here's where we try to choose the correct value for the unit
			if rawInterval >= self._dc:
				d = self._dc
				self._unit = 'days'
			elif rawInterval >= self._hc:
				d = self._hc
				self._unit = 'hours'
			elif rawInterval >= self._mc:
				d = self._mc
				self._unit = 'minutes'
			else:
				d = 1
			self._unitd = d
			if d>1:
				rawInterval = int(rawInterval/d)
			self._valueStep = nextRoundNumber(rawInterval) * d
		else:
			self._valueStep = self.valueStep

	def timeLabelTextFormatter(self,val):
		pass

class XTimeValueAxis(_XTicks,TimeValueAxis,XValueAxis):
	pass

the intent is just to map seconds into a suitable interval definition. The 
labelling is the hard part which I have not even thought about. In addition if 
sub ticks are wanted we need to specify hou they should be defined etc etc.
-- 
Robin Becker


More information about the reportlab-users mailing list