File: GChartExample07.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,682 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

"""* Basic pie chart
* <p>
*
* This chart uses the built-in HTML-element based pie chart
* rendering.  As of GChart 2.5, faster drawn, better
* looking, solid-filled pie slices can be produced by
* plugging an external canvas library into GChart.  See the
* <tt>setCanvasFactory</tt> method's javadocs for the
* details, and the various pie charts on GChart's live demo
* for complete working examples.
*
"""
class GChartExample07 (GChart):
    def __init__(self):
        GChart.__init__(self)
        pieMarketShare = [0.65,0.20,0.10,0.05]
        pieTypes = ["Apple", "Cherry", "Pecan", "Bannana"]
        pieColors = ["green", "red", "maroon", "yellow"]
        
        self.setChartSize(300, 200)
        self.setChartTitle("<h3>2008 Sales by Pie Flavor" +
                            "<br>(Puny Pies, Inc.) </h3>")
        self.setLegendVisible(False)
        self.getXAxis().setAxisVisible(False)
        self.getYAxis().setAxisVisible(False)
        self.getXAxis().setAxisMin(0)
        self.getXAxis().setAxisMax(10)
        self.getXAxis().setTickCount(0)
        self.getYAxis().setAxisMin(0)
        self.getYAxis().setAxisMax(10)
        self.getYAxis().setTickCount(0)
        # this line orients the center of the first slice (apple) due east
        self.setInitialPieSliceOrientation(0.75 - pieMarketShare[0]/2)
        for i in range(len(pieMarketShare)):
            self.addCurve()
            self.getCurve().addPoint(5,5)
            self.getCurve().getSymbol().setSymbolType(
                                    SymbolType.PIE_SLICE_OPTIMAL_SHADING)
            self.getCurve().getSymbol().setBorderColor("white")
            self.getCurve().getSymbol().setBackgroundColor(pieColors[i])
            # next two lines define pie diameter in x-axis model units
            self.getCurve().getSymbol().setModelWidth(6)
            self.getCurve().getSymbol().setHeight(0)
            self.getCurve().getSymbol().setFillSpacing(0)
            self.getCurve().getSymbol().setFillThickness(3)
            self.getCurve().getSymbol().setHovertextTemplate(
                    formatAsHovertext(pieTypes[i] + ", " +
                            "%d%%" % round(100*pieMarketShare[i])))
            self.getCurve().getSymbol().setPieSliceSize(pieMarketShare[i])
            self.getCurve().getPoint().setAnnotationText(pieTypes[i])
            self.getCurve().getPoint().setAnnotationLocation(
                                    AnnotationLocation.OUTSIDE_PIE_ARC)