Stats = class(Object, function(o, x, y, w, h, obj, prop, n)
	Object.init(o, x, y, w, h)
	o.prop = prop
	o.obj = obj
	o.n = name
	o.ringLength = 128
	o.objVals = {} -- this is the ring array
	-- fill the ring array with the current value of the object
	for i=1,o.ringLength do
		o.objVals[i] = obj[o.prop]
	end
	o.high = obj[o.prop]
	o.low = obj[o.prop]
	o.ringStep = 0
	o.tint = {r=32, g=32, b=45}
	o.textTint = {r=0, g=255, b=255}
	o.layer = 4
	o.sprite = sprites["white.png"]
	o.scrollFactor = Vec2(0,0)
	o.updateFreq = 50
	o.updateCount = o.updateFreq
end)

function Stats:update()
	self.updateCount = self.updateCount - 1
	if self.updateCount > 0 then return end
	self.updateCount = self.updateFreq
	-- step the ring pos forward and store the value of the object
	self.ringStep = self.ringStep + 1
	if self.ringStep > self.ringLength then
		self.ringStep = 1
	end
	self.objVals[self.ringStep] = self.obj[self.prop]
	-- recalc low and high vals
	self.low = self.objVals[self.ringStep]
	self.high = self.objVals[self.ringStep]
	for i=1,self.ringLength do
		self.low = math.min(self.low, self.objVals[i])
		self.high = math.max(self.high, self.objVals[i])
	end
end

function Stats:draw()
	-- draw the background
	self:drawStretched()
	-- draw the current number
	tb:setColor(self.textTint.r, self.textTint.g, self.textTint.b)
	tb:addText(self.objVals[self.ringStep] .. self.prop, self.pos.x, self.pos.y+sfontSize, true)
	-- loop through the ring and draw the values
	local o = Object(self.pos.x, self.pos.y, self.w/self.ringLength, 1)
	o.scrollFactor = self.scrollFactor
	o.sprite = self.sprite
	o.tint = self.textTint
	o.layer = self.layer
	for i=1,self.ringLength do
		local s = (self.ringStep+i)%self.ringLength + 1
		o.pos.y = self.pos.y+sfontSize + (1-(self.objVals[s]-self.low)/(self.high-self.low+1)) * (self.h-sfontSize)-1
		o.pos.x = math.floor(self.pos.x + o.w*(i-1))
		o:drawStretched()
	end
end