Beispiel #1
0
    def _GetAxisParams(self, chart):
        """Collect params related to our various axes (x, y, right-hand)."""
        axis_types = []
        axis_ranges = []
        axis_labels = []
        axis_label_positions = []
        axis_label_gridlines = []
        mark_length = max(self._width, self._height)
        for i, axis_pair in enumerate(a for a in chart._GetAxes()
                                      if a[1].labels):
            axis_type_code, axis = axis_pair
            axis_types.append(axis_type_code)
            if axis.min is not None or axis.max is not None:
                assert axis.min is not None  # Sanity check: both min & max must be set.
                assert axis.max is not None
                axis_ranges.append('%s,%s,%s' % (i, axis.min, axis.max))

            labels, positions = self._GetAxisLabelsAndPositions(axis, chart)
            if labels:
                axis_labels.append('%s:' % i)
                axis_labels.extend(labels)
            if positions:
                positions = [i] + list(positions)
                axis_label_positions.append(','.join(
                    str(x) for x in positions))
            if axis.label_gridlines:
                axis_label_gridlines.append("%d,%d" % (i, -mark_length))

        return util.JoinLists(
            axis_type=axis_types,
            axis_range=axis_ranges,
            axis_label=axis_labels,
            axis_position=axis_label_positions,
            axis_tick_marks=axis_label_gridlines,
        )
Beispiel #2
0
 def _GetColors(self, chart):
     """Color series color parameter."""
     colors = []
     for series in chart.data:
         if not series.data:
             continue
         colors.append(series.style.color)
     return util.JoinLists(color=colors)
Beispiel #3
0
 def _GetColors(self, chart):
     if chart._colors:
         # Colors were overridden by the user
         colors = chart._colors
     else:
         # Build the list of colors from individual segments
         colors = []
         for pie in chart.data:
             for segment in pie:
                 if segment and segment.color:
                     colors.append(segment.color)
     return util.JoinLists(color=colors)
Beispiel #4
0
 def _GetLineStyles(self, chart):
     """Get LineStyle parameters."""
     styles = []
     for series in chart.data:
         style = series.style
         if style:
             styles.append('%s,%s,%s' % (style.width, style.on, style.off))
         else:
             # If one style is missing, they must all be missing
             # TODO: Add a test for this; throw a more meaningful exception
             assert (not styles)
     return util.JoinLists(line_style=styles)
Beispiel #5
0
    def _GetDataSeriesParams(self, chart):
        """Collect params related to the data series."""

        pie_points = []
        labels = []
        max_val = 1
        for pie in chart.data:
            points = []
            for segment in pie:
                if segment:
                    points.append(segment.size)
                    max_val = max(max_val, segment.size)
                    labels.append(segment.label or '')
            if points:
                pie_points.append(points)

        encoder = self._GetDataEncoder(chart)
        result = util.EncodeData(chart, pie_points, 0, max_val, encoder)
        result.update(util.JoinLists(label=labels))
        return result
Beispiel #6
0
    def _GetDataSeriesParams(self, chart):
        """Collect params related to the data series."""
        y_min, y_max = chart.GetDependentAxis().min, chart.GetDependentAxis(
        ).max
        series_data = []
        markers = []
        for i, series in enumerate(chart.data):
            data = series.data
            if not data:  # Drop empty series.
                continue
            series_data.append(data)

            for x, marker in series.markers:
                args = [marker.shape, marker.color, i, x, marker.size]
                markers.append(','.join(str(arg) for arg in args))

        encoder = self._GetDataEncoder(chart)
        result = util.EncodeData(chart, series_data, y_min, y_max, encoder)
        result.update(util.JoinLists(marker=markers))
        return result
Beispiel #7
0
    def _ApplyBarChartStyle(self, chart):
        """If bar style is specified, fill in the missing data and apply it."""
        # sanity checks
        if chart.style is None or not chart.data:
            return {}

        (bar_thickness, bar_gap,
         group_gap) = (chart.style.bar_thickness, chart.style.bar_gap,
                       chart.style.group_gap)
        # Auto-size bar/group gaps
        if bar_gap is None and group_gap is not None:
            bar_gap = max(0, group_gap / 2)
            if not chart.style.use_fractional_gap_spacing:
                bar_gap = int(bar_gap)
        if group_gap is None and bar_gap is not None:
            group_gap = max(0, bar_gap * 2)

        # Set bar thickness to auto if it is missing
        if bar_thickness is None:
            if chart.style.use_fractional_gap_spacing:
                bar_thickness = 'r'
            else:
                bar_thickness = 'a'
        else:
            # Convert gap sizes to pixels if needed
            if chart.style.use_fractional_gap_spacing:
                if bar_gap:
                    bar_gap = int(bar_thickness * bar_gap)
                if group_gap:
                    group_gap = int(bar_thickness * group_gap)

        # Build a valid spec; ignore group gap if chart is stacked,
        # since there are no groups in that case
        spec = [bar_thickness]
        if bar_gap is not None:
            spec.append(bar_gap)
            if group_gap is not None and not chart.stacked:
                spec.append(group_gap)
        return util.JoinLists(bar_size=spec)
Beispiel #8
0
 def _GetLegendParams(self, chart):
     """Get params for showing a legend."""
     if chart._show_legend:
         return util.JoinLists(data_series_label=chart._legend_labels)
     return {}