Example #1
0
    def __init__(self):
        GChart.__init__(self, XChartSize=300, YChartSize=450)
        self.setChartTitle("<h2>2<sup>x</sup> vs x</h2>")
        self.addCurve()
        self.getCurve().getSymbol().setHovertextTemplate(
                        formatAsHovertext("${y}=2^${x}"))
        self.getCurve().setLegendLabel("<b>2<sup>x</sup></b>")
        self.getCurve().getSymbol().setBackgroundColor("red")
        self.getCurve().getSymbol().setBorderColor("black")
        self.getCurve().getSymbol().setWidth(9)
        self.getCurve().getSymbol().setHeight(9)

        # add (log10-transformed) powers of 2 from 1/4 to 8
        for i in range(-2, 4):
            self.getCurve().addPoint(i,log10(math.pow(2,i)))

        # GChart's "=10^" NumberFormat prefix inverts the log10
        # transform
        self.getYAxis().setTickLabelFormat("=10^#.##")
        # add conventional log-scaled ticks from .1 to 10
        self.getYAxis().addTick(log10(0.1))
        x = 0.1
        while x < 10:
            for y in range(2, 11):
                self.getYAxis().addTick(log10(x*y))
            x *= 10

        self.getXAxis().setAxisLabel("<b>x</b>")
        self.getXAxis().setHasGridlines(True)
        self.getXAxis().setTickCount(6)

        self.getYAxis().setAxisLabel("<b>2<sup>x</sup></b>")
        self.getYAxis().setHasGridlines(True)
    def _bar_segment_hover_text(self, testrun_id, symbol, step_idx, dts):
        """
        The hover text for the bar segment
        @type testrun_id: C{str}
        @param testrun_id: The testrun id

        @type symbol: L{pyjamas.chart.Symbol}
        @param symbol: The
      
        @type step_idx: C{int}
        @param step_idx: The index of the `step` in te testrun (for this bar)
        
        @type dts: C{list} of C{int}
        @param dts: The timedeltas for the whole testrun
        """
        symbol.setHoverAnnotationSymbolType(
                                  SymbolType.ANCHOR_MOUSE_SNAP_TO_Y)
        symbol.setHoverLocation(AnnotationLocation.SOUTHEAST)
        start_time = sum(dts[:step_idx])
        end_time = sum(dts[:step_idx+1])
        step = self._steps[step_idx]
        ht = "<b>%s</b> <i>%s</i>: %ss-%ss" % (testrun_id, step, 
                                                start_time, end_time)
        ht = formatAsHovertext(ht)
        symbol.setHovertextTemplate(ht)
Example #3
0
    def __init__(self):
        GChart.__init__(self, XChartSize=300, YChartSize=450)
        self.setChartTitle("<h2>2<sup>x</sup> vs x</h2>")
        self.addCurve()
        self.getCurve().getSymbol().setHovertextTemplate(
            formatAsHovertext("${y}=2^${x}"))
        self.getCurve().setLegendLabel("<b>2<sup>x</sup></b>")
        self.getCurve().getSymbol().setBackgroundColor("red")
        self.getCurve().getSymbol().setBorderColor("black")
        self.getCurve().getSymbol().setWidth(9)
        self.getCurve().getSymbol().setHeight(9)

        # add (log10-transformed) powers of 2 from 1/4 to 8
        for i in range(-2, 4):
            self.getCurve().addPoint(i, log10(math.pow(2, i)))

        # GChart's "=10^" NumberFormat prefix inverts the log10
        # transform
        self.getYAxis().setTickLabelFormat("=10^#.##")
        # add conventional log-scaled ticks from .1 to 10
        self.getYAxis().addTick(log10(0.1))
        x = 0.1
        while x < 10:
            for y in range(2, 11):
                self.getYAxis().addTick(log10(x * y))
            x *= 10

        self.getXAxis().setAxisLabel("<b>x</b>")
        self.getXAxis().setHasGridlines(True)
        self.getXAxis().setTickCount(6)

        self.getYAxis().setAxisLabel("<b>2<sup>x</sup></b>")
        self.getYAxis().setHasGridlines(True)
Example #4
0
    def __init__(self):
        GChart.__init__(self)

        self.updateButton = Button(
            "<b><big>Generate New Simulated Revenues</big></b>")

        self.setChartSize(WIDTH, HEIGHT)
        self.setChartTitle("<b><big><big>" + "Simulated Quarterly Revenues" +
                           "</big></big><br>&nbsp;</b>")
        self.updateButton.addClickListener(self)
        self.setChartFootnotes(self.updateButton)

        for iCurve in range(len(barLabels)):
            self.addCurve()  # one curve per quarter
            self.getCurve().getSymbol().setSymbolType(
                SymbolType.VBAR_SOUTHWEST)
            self.getCurve().getSymbol().setBackgroundColor(barColors[iCurve])
            self.getCurve().setLegendLabel(barLabels[iCurve])
            self.getCurve().getSymbol().setHovertextTemplate(
                formatAsHovertext(barLabels[iCurve] + " revenue=${y}"))
            self.getCurve().getSymbol().setModelWidth(1.0)
            self.getCurve().getSymbol().setBorderColor("black")
            self.getCurve().getSymbol().setBorderWidth(1)
            for jGroup in range(len(groupLabels)):
                # the '+1' creates a bar-sized gap between groups
                y = rnd() * MAX_REVENUE
                print "x, y", 1 + iCurve + jGroup * (len(barLabels) + 1), y
                self.getCurve().addPoint(
                    1 + iCurve + jGroup * (len(barLabels) + 1), y)
                self.getCurve().getPoint().setAnnotationText(barLabels[iCurve])
                self.getCurve().getPoint().setAnnotationLocation(
                    AnnotationLocation.NORTH)

        for i in range(len(groupLabels)):
            # formula centers tick-label horizontally on each group
            self.getXAxis().addTick(
                len(barLabels) / 2. + i * (len(barLabels) + 1), groupLabels[i])

        self.getXAxis().setTickLabelFontSize(20.0)
        self.getXAxis().setTickLabelThickness(40.0)
        self.getXAxis().setTickLength(6.0)
        # small tick-like gap...
        self.getXAxis().setTickThickness(0)
        # but with invisible ticks
        self.getXAxis().setAxisMin(0)
        # keeps first bar on chart

        self.getYAxis().setAxisMin(0)
        # Based on sim revenue range
        self.getYAxis().setAxisMax(MAX_REVENUE)
        # of 0 to MAX_REVENUE.
        self.getYAxis().setTickCount(11)
        self.getYAxis().setHasGridlines(True)
        self.getYAxis().setTickLabelFormat("$#,###")
Example #5
0
    def __init__(self):
        GChart.__init__(self)


        self.updateButton = Button("<b><big>Generate New Simulated Revenues</big></b>")

        self.setChartSize(WIDTH, HEIGHT)
        self.setChartTitle("<b><big><big>" +
                    "Simulated Quarterly Revenues" +
                    "</big></big><br>&nbsp;</b>")
        self.updateButton.addClickListener(self)
        self.setChartFootnotes(self.updateButton)

        for iCurve in range(len(barLabels)):
            self.addCurve()     # one curve per quarter
            self.getCurve().getSymbol().setSymbolType(SymbolType.VBAR_SOUTHWEST)
            self.getCurve().getSymbol().setBackgroundColor(barColors[iCurve])
            self.getCurve().setLegendLabel(barLabels[iCurve])
            self.getCurve().getSymbol().setHovertextTemplate(
                formatAsHovertext(barLabels[iCurve] + " revenue=${y}"))
            self.getCurve().getSymbol().setModelWidth(1.0)
            self.getCurve().getSymbol().setBorderColor("black")
            self.getCurve().getSymbol().setBorderWidth(1)
            for jGroup in range(len(groupLabels)):
                # the '+1' creates a bar-sized gap between groups
                y = rnd()*MAX_REVENUE
                print "x, y", 1+iCurve+jGroup*(len(barLabels)+1), y
                self.getCurve().addPoint(1+iCurve+jGroup*(len(barLabels)+1), y)
                self.getCurve().getPoint().setAnnotationText(barLabels[iCurve])
                self.getCurve().getPoint().setAnnotationLocation(
                                    AnnotationLocation.NORTH)



        for i in range(len(groupLabels)):
            # formula centers tick-label horizontally on each group
            self.getXAxis().addTick(
                        len(barLabels)/2. + i*(len(barLabels)+1),
                        groupLabels[i])

        self.getXAxis().setTickLabelFontSize(20.0)
        self.getXAxis().setTickLabelThickness(40.0)
        self.getXAxis().setTickLength(6.0);    # small tick-like gap...
        self.getXAxis().setTickThickness(0); # but with invisible ticks
        self.getXAxis().setAxisMin(0);       # keeps first bar on chart

        self.getYAxis().setAxisMin(0);           # Based on sim revenue range
        self.getYAxis().setAxisMax(MAX_REVENUE); # of 0 to MAX_REVENUE.
        self.getYAxis().setTickCount(11)
        self.getYAxis().setHasGridlines(True)
        self.getYAxis().setTickLabelFormat("$#,###")
Example #6
0
    def __init__(self):
        GChart.__init__(self)

        self.setChartSize(200, 200)
        self.setBorderWidth("0px")
        self.setHoverParameterInterpreter(
                            CurveNumberHoverParameterInterpreter())
        template = formatAsHovertext(
                            "Curve #${curveNumber}:<br>x=${x}, y=${y}")
        for iCurve in range(3):
            self.addCurve()
            self.getCurve().getSymbol().setHovertextTemplate(template)
            for iPoint in range(10):
                self.getCurve().addPoint(iPoint, (iCurve+1)*iPoint)
Example #7
0
    def __init__(self):
        GChart.__init__(self)

        self.setChartSize(200, 200)
        self.setBorderWidth("0px")
        self.setHoverParameterInterpreter(
            CurveNumberHoverParameterInterpreter())
        template = formatAsHovertext(
            "Curve #${curveNumber}:<br>x=${x}, y=${y}")
        for iCurve in range(3):
            self.addCurve()
            self.getCurve().getSymbol().setHovertextTemplate(template)
            for iPoint in range(10):
                self.getCurve().addPoint(iPoint, (iCurve + 1) * iPoint)
Example #8
0
    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)
Example #9
0
    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)
Example #10
0
 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)
Example #11
0
    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)
    def _bar_segment_hover_text(self, testrun_id, symbol, step_idx, dts):
        """
        The hover text for the bar segment
        @type testrun_id: C{str}
        @param testrun_id: The testrun id

        @type symbol: L{pyjamas.chart.Symbol}
        @param symbol: The
      
        @type step_idx: C{int}
        @param step_idx: The index of the `step` in te testrun (for this bar)
        
        @type dts: C{list} of C{int}
        @param dts: The timedeltas for the whole testrun
        """
        symbol.setHoverAnnotationSymbolType(SymbolType.ANCHOR_MOUSE_SNAP_TO_Y)
        symbol.setHoverLocation(AnnotationLocation.SOUTHEAST)
        start_time = sum(dts[:step_idx])
        end_time = sum(dts[:step_idx + 1])
        step = self._steps[step_idx]
        ht = "<b>%s</b> <i>%s</i>: %ss-%ss" % (testrun_id, step, start_time,
                                               end_time)
        ht = formatAsHovertext(ht)
        symbol.setHovertextTemplate(ht)
Example #13
0
** setAnnotationFontWeight
**
*"""

DEFAULT_FONT_WEIGHT = "normal"
"""*
** The default template string used to generate the hovertext
** displayed when the user hovers their mouse above a point
** on a curve (pie slices have a different default).
**
** @see Symbol#setHovertextTemplate setHovertextTemplate
** @see #DEFAULT_PIE_SLICE_HOVERTEXT_TEMPLATE
**    DEFAULT_PIE_SLICE_HOVERTEXT_TEMPLATE
**
"""
DEFAULT_HOVERTEXT_TEMPLATE = formatAsHovertext("(${x}, ${y})")
"""*
** The default hover feedback location used to position the
** hover feedback when the user hovers their mouse above a point
** on a curve (pie slices, and bar symbols have different
** defaults).
**
** @see Symbol#setHoverLocation setHoverLocation
** @see #DEFAULT_PIE_SLICE_HOVER_LOCATION DEFAULT_PIE_SLICE_HOVER_LOCATION
** @see #DEFAULT_VBAR_BASELINE_HOVER_LOCATION DEFAULT_VBAR_BASELINE_HOVER_LOCATION
** @see #DEFAULT_VBARBOTTOM_HOVER_LOCATION DEFAULT_VBARBOTTOM_HOVER_LOCATION
** @see #DEFAULT_VBARTOP_HOVER_LOCATION DEFAULT_VBARTOP_HOVER_LOCATION
** @see #DEFAULT_HBAR_BASELINE_HOVER_LOCATION DEFAULT_HBAR_BASELINE_HOVER_LOCATION
** @see #DEFAULT_HBARLEFT_HOVER_LOCATION DEFAULT_HBARLEFT_HOVER_LOCATION
** @see #DEFAULT_HBARRIGHT_HOVER_LOCATION DEFAULT_HBARRIGHT_HOVER_LOCATION
**
Example #14
0
**
*"""

DEFAULT_FONT_WEIGHT = "normal"

"""*
** The default template string used to generate the hovertext
** displayed when the user hovers their mouse above a point
** on a curve (pie slices have a different default).
**
** @see Symbol#setHovertextTemplate setHovertextTemplate
** @see #DEFAULT_PIE_SLICE_HOVERTEXT_TEMPLATE
**    DEFAULT_PIE_SLICE_HOVERTEXT_TEMPLATE
**
"""
DEFAULT_HOVERTEXT_TEMPLATE = formatAsHovertext("(${x}, ${y})")
"""*
** The default hover feedback location used to position the
** hover feedback when the user hovers their mouse above a point
** on a curve (pie slices, and bar symbols have different
** defaults).
**
** @see Symbol#setHoverLocation setHoverLocation
** @see #DEFAULT_PIE_SLICE_HOVER_LOCATION DEFAULT_PIE_SLICE_HOVER_LOCATION
** @see #DEFAULT_VBAR_BASELINE_HOVER_LOCATION DEFAULT_VBAR_BASELINE_HOVER_LOCATION
** @see #DEFAULT_VBARBOTTOM_HOVER_LOCATION DEFAULT_VBARBOTTOM_HOVER_LOCATION
** @see #DEFAULT_VBARTOP_HOVER_LOCATION DEFAULT_VBARTOP_HOVER_LOCATION
** @see #DEFAULT_HBAR_BASELINE_HOVER_LOCATION DEFAULT_HBAR_BASELINE_HOVER_LOCATION
** @see #DEFAULT_HBARLEFT_HOVER_LOCATION DEFAULT_HBARLEFT_HOVER_LOCATION
** @see #DEFAULT_HBARRIGHT_HOVER_LOCATION DEFAULT_HBARRIGHT_HOVER_LOCATION
**