def testAxisConstruction(self): axis = common.Axis() self.assertTrue(axis.min is None) self.assertTrue(axis.max is None) axis = common.Axis(-2, 16) self.assertEqual(axis.min, -2) self.assertEqual(axis.max, 16)
def testOtherDependentAxesAreAlsoSet(self): self.chart.AddAxis(common.AxisPosition.LEFT, common.Axis()) self.chart.AddAxis(common.AxisPosition.RIGHT, common.Axis()) self.assertEqual(4, len(self.chart.GetDependentAxes())) self.auto_scale(self.chart) for axis in self.chart.GetDependentAxes(): self.assertEqual(1, axis.min) self.assertEqual(3, axis.max)
def testGetDependentIndependentAxes(self): c = self.chart self.assertEqual([c.left, c.right], c.GetDependentAxes()) self.assertEqual([c.top, c.bottom], c.GetIndependentAxes()) right2 = c.AddAxis(common.AxisPosition.RIGHT, common.Axis()) bottom2 = c.AddAxis(common.AxisPosition.BOTTOM, common.Axis()) self.assertEqual([c.left, c.right, right2], c.GetDependentAxes()) self.assertEqual([c.top, c.bottom, bottom2], c.GetIndependentAxes())
def testAxisAssignment(self): """Make sure axis assignment works properly""" new_axis = common.Axis() self.chart.top = new_axis self.assertTrue(self.chart.top is new_axis) new_axis = common.Axis() self.chart.bottom = new_axis self.assertTrue(self.chart.bottom is new_axis) new_axis = common.Axis() self.chart.left = new_axis self.assertTrue(self.chart.left is new_axis) new_axis = common.Axis() self.chart.right = new_axis self.assertTrue(self.chart.right is new_axis)
def testAxisProperties(self): self.ExpectAxes('', '') self.chart.top.labels = ['cow', 'horse', 'monkey'] self.chart.top.label_positions = [3.7, 10, -22.9] self.ExpectAxes('0:|cow|horse|monkey', '0,3.7,10,-22.9') self.chart.left.labels = [10, 20, 30] self.chart.left.label_positions = [0, 50, 100] self.ExpectAxes('0:|10|20|30|1:|cow|horse|monkey', '0,0,50,100|1,3.7,10,-22.9') self.assertEqual(self.Param('chxt'), 'y,t') sub_axis = self.chart.AddAxis(common.AxisPosition.BOTTOM, common.Axis()) sub_axis.labels = ['CAPS', 'lower'] sub_axis.label_positions = [0, 50] self.ExpectAxes('0:|10|20|30|1:|CAPS|lower|2:|cow|horse|monkey', '0,0,50,100|1,0,50|2,3.7,10,-22.9') self.assertEqual(self.Param('chxt'), 'y,x,t') self.chart.bottom.labels = ['A', 'B', 'C'] self.chart.bottom.label_positions = [0, 33, 66] self.ExpectAxes( '0:|10|20|30|1:|A|B|C|2:|CAPS|lower|3:|cow|horse|monkey', '0,0,50,100|1,0,33,66|2,0,50|3,3.7,10,-22.9') self.assertEqual(self.Param('chxt'), 'y,x,x,t')
def testMultipleAxisLabels(self): self.ExpectAxes('', '') left_axis = self.chart.AddAxis(common.AxisPosition.LEFT, common.Axis()) left_axis.labels = [10, 20, 30] left_axis.label_positions = [0, 50, 100] self.ExpectAxes('0:|10|20|30', '0,0,50,100') bottom_axis = self.chart.AddAxis(common.AxisPosition.BOTTOM, common.Axis()) bottom_axis.labels = ['A', 'B', 'c', 'd'] bottom_axis.label_positions = [0, 33, 66, 100] sub_axis = self.chart.AddAxis(common.AxisPosition.BOTTOM, common.Axis()) sub_axis.labels = ['CAPS', 'lower'] sub_axis.label_positions = [0, 50] self.ExpectAxes('0:|10|20|30|1:|A|B|c|d|2:|CAPS|lower', '0,0,50,100|1,0,33,66,100|2,0,50') self.chart.AddAxis(common.AxisPosition.RIGHT, left_axis) self.ExpectAxes('0:|10|20|30|1:|10|20|30|2:|A|B|c|d|3:|CAPS|lower', '0,0,50,100|1,0,50,100|2,0,33,66,100|3,0,50') self.assertEqual(self.Param('chxt'), 'y,r,x,x')
def PerRunDurationBarGraph(run_data, scale=None): """Output a Google Chart API URL showing per-run durations.""" chart = google_chart_api.BarChart() chart.vertical = False chart.bottom.label_gridlines = True chart.bottom.label_positions = chart.bottom.labels max_run_avg = -1 runs = {} for (ns, run_averages) in run_data: chart.left.labels.append(ns) for run_num, run_avg in enumerate(run_averages): if run_num not in runs: runs[run_num] = [] runs[run_num].append(run_avg) if run_avg > max_run_avg: max_run_avg = run_avg if max_run_avg < 0: print "No decent data to graph: %s" % run_data return None if not scale: scale = int(math.ceil(max_run_avg / 5) * 5) if len(runs) == 1: bar_count = len(runs[0]) chart.AddBars(runs[0]) else: bar_count = 0 for run_num in sorted(runs): bar_count += len(runs[run_num]) chart.AddBars(runs[run_num], label='Run %s' % (run_num + 1), color=DarkenHexColorCode('4684ee', run_num * 3)) tick = _GoodTicks(scale, num_ticks=15.0) labels = range(0, scale, tick) + [scale] chart.bottom.min = 0 chart.display.enhanced_encoding = True bottom_axis = chart.AddAxis('x', common.Axis()) bottom_axis.labels = ['Duration in ms.'] bottom_axis.label_positions = [int((max_run_avg / 2.0) * .9)] chart.bottom.labels = labels chart.bottom.max = labels[-1] return chart.display.Url(CHART_WIDTH, _BarGraphHeight(bar_count))
def MinimumDurationBarGraph(fastest_data, scale=None): """Output a Google Chart API URL showing minimum-run durations.""" chart = google_chart_api.BarChart() chart.vertical = False chart.bottom.label_gridlines = True chart.bottom.label_positions = chart.bottom.labels chart.AddBars([x[1] for x in fastest_data]) chart.left.labels = [x[0].name for x in fastest_data] slowest_time = fastest_data[-1][1] if not scale: scale = int(math.ceil(slowest_time / 5) * 5) tick = _GoodTicks(scale, num_ticks=15.0) labels = range(0, scale, tick) + [scale] chart.bottom.min = 0 chart.bottom.max = scale chart.display.enhanced_encoding = True bottom_axis = chart.AddAxis('x', common.Axis()) bottom_axis.labels = ['Duration in ms.'] bottom_axis.label_positions = [int((scale / 2.0) * .9)] chart.bottom.labels = labels return chart.display.Url(CHART_WIDTH, _BarGraphHeight(len(chart.left.labels)))
'NY': 54475, 'CT': 5544, 'RI': 1545, 'NJ': 8722, 'PA': 46058 } northwest = ('WA', 'OR', 'ID', 'MT', 'WY') northeast = ('ME', 'VT', 'NH', 'MA', 'NY', 'CT', 'RI', 'NJ', 'PA') states = northwest + northeast areas = [area[s] for s in states] print '<html><body>' print '<h1>Areas of States in the Northwest and Northeast US</h1>' print '<h3>(in square miles)</h3>' chart = google_chart_api.BarChart(areas) chart.bottom.labels = states region_axis = common.Axis() region_axis.min = 0 region_axis.max = 100 region_axis.labels = ['Northwest', 'Northeast'] region_axis.label_positions = [20, 60] chart.AddAxis(common.AxisPosition.BOTTOM, region_axis) ylabels = range(0, 150001, 50000) chart.left.min = min(ylabels) chart.left.max = max(ylabels) chart.left.labels = ['%sK' % (x / 1000) for x in ylabels] chart.left.label_positions = ylabels print chart.display.Img(500, 220) print '</body></html>'