def _get_plot_area(self, template): plot_area_elements = [] num_bars_cluster = len(self._column_header) num_clusters = len(self._clusters) cluster_padding = template['rstack']['padding'] cluster_width_bars = 1 + 2*cluster_padding total_bar_count = cluster_width_bars * num_clusters bar_frac = 1.0 / total_bar_count bar_width_def = latex_length('barwidth', '%f\\xmax' % bar_frac) cluster_width_def = latex_length('clusterwidth', '%f\\barwidth' % cluster_width_bars) padding_def = latex_length('padding', '%f\\barwidth' % cluster_padding) bar_width_def.comment = 'RStack width defs' bar_width_def.space_before = 1 self._definitions.append(bar_width_def) self._definitions.append(cluster_width_def) self._definitions.append(padding_def) style_key = 'bar-styles-%d' % num_bars_cluster if style_key in template['rstack']: bar_styles = template['rstack'][style_key] else: bar_styles = template['rstack']['bar-styles-n'][:num_bars_cluster] bar_style_comment = tikz_comment('Bar styles') bar_style_comment.space_before = 1 self._definitions.append(bar_style_comment) for i, style in enumerate(bar_styles): bar_style_name = self._bar_ns[i] bar_style = tikz_style(bar_style_name) bar_style.set_option(style) self._definitions.append(bar_style) # plot the bars bar_comment = tikz_comment('Bars') bar_comment.space_before = 1 self._plot_elements.append(bar_comment) #base = '0' if self.ymin <= 0 else '\\ymin' if self.ymin != 0: raise RuntimeError('Invalid base for row stack?') for i, (key, values) in enumerate(self._clusters): base = 0 offset = '%d\\clusterwidth + \\padding' % (i) for j, value in enumerate(values): p1 = '(%s, %f)' % (offset, base) p2 = '++(\\barwidth, %s)' % value white_bar = tikz_rectangle(p1, p2) white_bar.set_option('fill', 'white') real_bar = tikz_rectangle(p1, p2) real_bar.set_option(self._bar_ns[j]) self._plot_elements.append(white_bar) self._plot_elements.append(real_bar) base = base + float(value)
def _get_plot_area(self, template): plot_area_elements = [] num_bars_cluster = len(self._column_header) num_clusters = len(self._clusters) cluster_padding = template['cstack']['padding'] cluster_width_bars = num_bars_cluster + 2*cluster_padding total_bar_count = cluster_width_bars * num_clusters bar_frac = 1.0 / total_bar_count bar_width_def = latex_length('barwidth', '%f\\xmax' % bar_frac) cluster_width_def = latex_length('clusterwidth', '%f\\barwidth' % cluster_width_bars) padding_def = latex_length('padding', '%f\\barwidth' % cluster_padding) bar_width_def.comment = 'CStack width defs' bar_width_def.space_before = 1 self._definitions.append(bar_width_def) self._definitions.append(cluster_width_def) self._definitions.append(padding_def) style_key = 'bar-styles-%d' % num_bars_cluster if style_key in template['cstack']: bar_styles = template['cstack'][style_key] else: bar_styles = template['cstack']['bar-styles-n'][:num_bars_cluster] bar_style_comment = tikz_comment('Bar styles') bar_style_comment.space_before = 1 self._definitions.append(bar_style_comment) for i, style in enumerate(bar_styles): bar_style_name = self._bar_ns[i] bar_style = tikz_style(bar_style_name) bar_style.set_option(style) self._definitions.append(bar_style) # plot the bars bar_comment = tikz_comment('Bars') bar_comment.space_before = 1 self._plot_elements.append(bar_comment) base = '0' if self.ymin <= 0 else '\\ymin' baseline_def = latex_def('base', base) self._plot_elements.append(baseline_def) if self.ymin < 0: zero_line = tikz_line('(\\xmin, 0)', '(\\xmax, 0)') self._plot_elements.append(zero_line) for i, (key, values) in enumerate(self._clusters): for j, value in enumerate(values): value = min(self.ymax, value) offset = '%d\\clusterwidth + \\padding + %d\\barwidth' % (i, j) p1 = '(%s, \\base)' % offset p2 = '++(\\barwidth, %s - \\base)' % value white_bar = tikz_rectangle(p1, p2) white_bar.set_option('fill', 'white') real_bar = tikz_rectangle(p1, p2) real_bar.set_option(self._bar_ns[j]) self._plot_elements.append(white_bar) self._plot_elements.append(real_bar)