File: GChartExample06.py

package info (click to toggle)
pyjamas 0.7~%2Bpre2-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 10,656 kB
  • ctags: 12,331
  • sloc: python: 74,493; php: 805; sh: 291; makefile: 59; xml: 9
file content (62 lines) | stat: -rw-r--r-- 2,503 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from pyjamas.chart.HovertextChunk import formatAsHovertext
from pyjamas.chart.GChart import GChart
from pyjamas.chart import AnnotationLocation
from pyjamas.chart import SymbolType

"""*
* Defines a "square pie chart", that is, a
* fat, axes-free, stacked bar chart that is
* often an acceptable alterto a pie-chart.
* <p>
*
* Even though, as of version 2.0, GChart also supports
* round pie charts, square pie charts are still
* much more efficient.
*
"""
class GChartExample06(GChart):
    def __init__(self):
        GChart.__init__(self)
        self.setChartTitle("<b><i>Market Share by Region</i></b>")
        SIZE = 200
        self.setChartSize(SIZE, SIZE)
        region = ["USA", "Canada", "Mexico", "India", "France", "Iceland"]
        # elements in this array must sum to 100.
        percent = [35, 25, 15, 10, 10, 5]
        colors = ["red", "green", "yellow", "fuchsia", "silver", "aqua"]
        sum = 0
        for i in range(len(percent)-1, -1, -1):
            self.addCurve()
            self.getCurve().getSymbol().setSymbolType(SymbolType.BOX_SOUTHEAST)
            self.getCurve().getSymbol().setModelHeight(percent[i])
            self.getCurve().getSymbol().setBackgroundColor(colors[i])
            self.getCurve().getSymbol().setBorderColor(colors[i])
            self.getCurve().getSymbol().setWidth(SIZE)
            self.getCurve().getSymbol().setHoverAnnotationSymbolType(
                                        SymbolType.ANCHOR_MOUSE_SNAP_TO_Y)
            self.getCurve().getSymbol().setHoverLocation(
                                        AnnotationLocation.SOUTHEAST)

            ht = "%s, %d%%" % (region[i], percent[i])
            ht = formatAsHovertext(ht)
            self.getCurve().getSymbol().setHovertextTemplate(ht)
            self.getCurve().setLegendLabel(region[i])
            self.getCurve().addPoint(0, 100-sum)
            self.getCurve().getPoint().setAnnotationText(region[i])
            self.getCurve().getPoint().setAnnotationFontWeight("bold")
            self.getCurve().getPoint().setAnnotationLocation(
                                            AnnotationLocation.CENTER)
            sum += percent[i]

        self.getXAxis().setTickCount(0)
        self.getXAxis().setTickThickness(0)
        self.getXAxis().setAxisMin(0)
        self.getXAxis().setAxisMax(SIZE)
        self.getYAxis().setTickCount(0)
        self.getYAxis().setTickThickness(0)
        self.getYAxis().setAxisMin(0)
        self.getYAxis().setAxisMax(100)