are these possible/easy with GCW? (newbie)

27 views
Skip to first unread message

Dan

unread,
Jul 27, 2009, 5:40:30 PM7/27/09
to GChartWrapper
Hello- I'm just starting to use the GChartWrapper, and have a few
questions that I was not able to answer by looking at the examples and
epydocs (apologies if I missed them in there).

1) Does GCW handle encoding a list of floats into Google Chart's 61
quantized levels (ABCD...) ? (or some other format that reduces the
length of the URL)

2) Related to (1), does GCW work with negative numbers in line charts
and bar charts?

3) does GCW have functions to handle time values, like translating
from epoch seconds to more human-readable labels?

Each of these three could be done manually in my code of course. But
if they're already part of the GCW routines, then I'd be glad to re-
use them.

thanks
Dan

Dan

unread,
Jul 27, 2009, 6:09:37 PM7/27/09
to GChartWrapper


On Jul 27, 2:40 pm, Dan <danbr...@gmail.com> wrote:
> Hello- I'm just starting to use the GChartWrapper, and have a few
> questions that I was not able to answer by looking at the examples and
> epydocs (apologies if I missed them in there).
>
> 1) Does GCW handle encoding a list of floats into Google Chart's 61
> quantized levels (ABCD...) ? (or some other format that reduces the
> length of the URL)
OK, I found the Encoder() object and its encode() method, so I think I
understand how to translate from numbers to the URL-friendly levels
understood by the google chart API. But scaling is a different process
that I would need...

>
> 2) Related to (1), does GCW work with negative numbers in line charts
> and bar charts?
It looks like this should be done with the Encoder.scalevalue() method
-- but it appears to have been disabled with the wistful comment "one
day..." ?

def scalevalue(self, value):
return value # one day...
if self.encoding != 'text' and self.scale and \
isinstance(value, int) or isinstance(value, float):
if type(self.scale) == type(()):
lower,upper = self.scale
else:
lower,upper = 0,float(self.scale)
value = int(round(float(value - lower) * self.codeset
['max_value'] / upper))
return min(value, self.codeset['max_value'])

Dan

unread,
Jul 27, 2009, 6:43:27 PM7/27/09
to GChartWrapper
The monologue continues...
I enabled the scalevalue method by commenting out the "return value"
line, then came across this bug. The Encoder.scalevalue() method
appears to work well for data sets where none of the values is less
than the lower limit from the scale parameter tuple. But when this is
not the case, to prevent unintended index wraparound, I suggest
changing this line:
return min(value, self.codeset['max_value'])

to this:
return min(max(0,value), self.codeset['max_value'])

also the epydocs could be improved to describe what kinds of values
are expected for the scale parameter, ie. assume a range of 0..scale,
or if a tuple then a range of scale[0]..scale[1].

justquick

unread,
Jul 27, 2009, 7:42:05 PM7/27/09
to GChartWrapper
> 1) Does GCW handle encoding a list of floats into Google Chart's 61
> quantized levels (ABCD...) ? (or some other format that reduces the
> length of the URL)

Why do you want to reduce the length of the url? Are you trying to
create high data density charts?

> 2) Related to (1), does GCW work with negative numbers in line charts
> and bar charts?

Yes it should, you can use the position method to declare the position
(orientation) of the zero axis
http://www.chartography.net/media/google-chartwrapper-demo/bar_zero.html

> 3) does GCW have functions to handle time values, like translating
> from epoch seconds to more human-readable labels?

No. But if you have some that would be usefull for GCW apps, please
post them.

Justin

PS - Your efforts to hack the Encoder.scalevalue method are in vain;
that feature was forsaken in favor of text scaling where
encoding='text' and then use the scale method to adjust

Dan

unread,
Jul 27, 2009, 8:13:54 PM7/27/09
to GChartWrapper


On Jul 27, 4:42 pm, justquick <justqu...@gmail.com> wrote:
> > 1) Does GCW handle encoding a list of floats into Google Chart's 61
> > quantized levels (ABCD...) ? (or some other format that reduces the
> > length of the URL)
>
> Why do you want to reduce the length of the url? Are you trying to
> create high data density charts?
yes. I'll be working with a few hundred points, say 700, on a time
axis that could have irregular spacing. That means I should look at
using simple encoding, right? to stay within the typical 1024
character limit (or guideline) of a URL?

>
> > 2) Related to (1), does GCW work with negative numbers in line charts
> > and bar charts?
>
> Yes it should, you can use the position method to declare the position
> (orientation) of the zero axishttp://www.chartography.net/media/google-chartwrapper-demo/bar_zero.html
ok

>
> > 3) does GCW have functions to handle time values, like translating
> > from epoch seconds to more human-readable labels?
>
> No. But if you have some that would be usefull for GCW apps, please
> post them.
ok

>
> Justin
>
> PS - Your efforts to hack the Encoder.scalevalue method are in vain;
> that feature was forsaken in favor of text scaling where
> encoding='text' and then use the scale method to adjust

hmm... would you suggest that I do the scaling and quantization in my
own code, or try to implement scaling for encoding='simple' in the GCW
library?

justquick

unread,
Jul 27, 2009, 8:43:38 PM7/27/09
to GChartWrapper
dont scale your values in the code, just construct a chart using text
encoding and then use the .scale method

G=Line([1,2,3,4,5],encoding='text')
G.scale(2,4)
Reply all
Reply to author
Forward
0 new messages