simplyvikram / google-chartwrapper

Automatically exported from code.google.com/p/google-chartwrapper
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Negative values are dropped with a scaled text encoding #25

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
* What steps will reproduce the problem?
   >>> VerticalBarGroup([10,10,30,-30,10],scale=('-50','50'),encoding='text')

* What is the expected output? What do you see instead?
   All negative values are discarded (not even replaced by a missing value).

What version of the product are you using? On what operating system?
SVNr221 - Python 2.6.1 (MacOS10.6.2

Potential fix:
In encoding.Encoder.encodedata, replace `` elif value >= -1 `` by ``else:``

Original issue reported on code.google.com by pierregmcode@gmail.com on 2 Dec 2009 at 4:55

GoogleCodeExporter commented 9 years ago
The potential fix has no effect on the outcome of the example you provided. 
What is
the expected output? Im looking for the proper chart URL. I can kinda imagine 
what it
should look like, but my imagination tends to suck in general.

Original comment by justquick on 2 Dec 2009 at 4:21

GoogleCodeExporter commented 9 years ago
Justin,
Try that:
>>> import GChartWrapper as gchart
>>> G = gchart.VerticalBarStack([43.56,-35.62,-48.34,57.50,67.30,60.91])
>>> G.show()
>>> print G.url
"http://chart.apis.google.com/chart?chd=t:43.6,57.5,67.3,60.9&chs=300x150&cht=bv
s"

Negative values have been dropped, resulting in only 4 bars. 
I would expect to get the following URL
"http://chart.apis.google.com/chart?chd=t:43.6,-35.6,-48.3,57.5,67.3,60.9&chs=30
0x150&cht=bvs"
where bars 2 and 3 are missing.

Likewise, with a `scale` input:
>>> G = gchart.VerticalBarStack([43.56,-35.62,-48.34,57.50,67.30,60.91])
>>> G.scale(-40,+70)
>>> G.show()

The current code still drops the bars w/ negative values
"http://chart.apis.google.com/chart?chds=-40,70&chd=t:43.6,57.5,67.3,60.9&chs=30
0x150&cht=bvs"

I expect to see get that URL
"http://chart.apis.google.com/chart?chd=t:43.6,-35.6,-48.3,57.5,67.3,60.9&chds=-
40,70&chs=300x150&cht=bvs"
where now only bar #3 is missing (it's below the lowest range)

Original comment by pierregmcode@gmail.com on 2 Dec 2009 at 10:38

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
The problem lies in encodedata in encoding.py. All values below -1 are ignored.

def encodedata(self, data):
        sub_data = []
        enc_size = len(self.codeset['coding'])
        for value in data:
            if value in (None,'None'):
                sub_data.append(self.codeset['none'])
            elif isinstance(value, str):
                sub_data.append(value)
            elif value >= -1:
                try:
                    sub_data.append(self.codeset['value'](self.scalevalue(value)))
                except:
                    raise ValueError('cannot encode value: %s'%value)
        return self.codeset['dchar'].join(sub_data)

Original comment by pie...@musmato.com on 14 Apr 2012 at 2:31