pgollakota/django-chartit — pull request #4 by bastir85 (2012-04-22 20:32:55+00:00)
Title: addes support for lambda functions on model data

Hey,

I added support for lambda functions that is applied on the data field. Here is an example, how it works:
The model definition:
class Events(models.Model):
key = models.CharField(max_length=255,unique_for_date="date",db_index=True)
date = models.DateField(db_index=True)
clicks = models.PositiveIntegerField(default=0)

view code:
eventdata = \
DataPool(
series=
[{'options': {
'source': Events.objects.filter(key=key)},
'terms': [
('date',lambda d: d.toordinal()),
'clicks'
]}
])

#Step 2: Create the Chart object
cht = Chart(
datasource = eventdata,
series_options =
[{'options':{
'type': 'line',
'stacking': False},
'terms':{
'date': [
'clicks']
}}],
chart_options =
{'title': {
'text': 'Clicks'},
'xAxis': {
'title': {
'text': 'Date'}}},
x_sortf_mapf_mts = (None,lambda i: datetime.fromordinal(i).strftime("%d-%m"),False)