|
|
|
@ -24,9 +24,9 @@ Base for pygal charts
|
|
|
|
|
from __future__ import division |
|
|
|
|
from pygal.view import Margin, Box |
|
|
|
|
from pygal.util import ( |
|
|
|
|
get_text_box, get_texts_box, cut, rad, humanize, truncate) |
|
|
|
|
get_text_box, get_texts_box, cut, rad, humanize, truncate, split_title) |
|
|
|
|
from pygal.svg import Svg |
|
|
|
|
from pygal.util import cached_property, reverse_text_len |
|
|
|
|
from pygal.util import cached_property |
|
|
|
|
from math import sin, cos, sqrt |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -73,22 +73,6 @@ class BaseGraph(object):
|
|
|
|
|
return object.__getattribute__(self.config, attr) |
|
|
|
|
return object.__getattribute__(self, attr) |
|
|
|
|
|
|
|
|
|
def _split_title(self): |
|
|
|
|
if not self.title: |
|
|
|
|
self.title = [] |
|
|
|
|
return |
|
|
|
|
size = reverse_text_len(self.width, self.title_font_size * 1.1) |
|
|
|
|
title = self.title.strip() |
|
|
|
|
self.title = [] |
|
|
|
|
while len(title) > size: |
|
|
|
|
title_part = title[:size] |
|
|
|
|
i = title_part.rfind(' ') |
|
|
|
|
if i == -1: |
|
|
|
|
i = len(title_part) |
|
|
|
|
self.title.append(title_part[:i]) |
|
|
|
|
title = title[i:].strip() |
|
|
|
|
self.title.append(title) |
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
def all_series(self): |
|
|
|
|
return self.series + self.secondary_series |
|
|
|
@ -107,6 +91,7 @@ class BaseGraph(object):
|
|
|
|
|
|
|
|
|
|
def _compute_margin(self): |
|
|
|
|
"""Compute graph margins from set texts""" |
|
|
|
|
self._legend_at_left_width = 0 |
|
|
|
|
for series_group in (self.series, self.secondary_series): |
|
|
|
|
if self.show_legend and series_group: |
|
|
|
|
h, w = get_texts_box( |
|
|
|
@ -119,14 +104,12 @@ class BaseGraph(object):
|
|
|
|
|
sqrt(self._order) - 1) * 1.5 + h_max |
|
|
|
|
else: |
|
|
|
|
if series_group is self.series: |
|
|
|
|
self.margin.left += 10 + w + self.legend_box_size |
|
|
|
|
legend_width = 10 + w + self.legend_box_size |
|
|
|
|
self.margin.left += legend_width |
|
|
|
|
self._legend_at_left_width += legend_width |
|
|
|
|
else: |
|
|
|
|
self.margin.right += 10 + w + self.legend_box_size |
|
|
|
|
|
|
|
|
|
if self.title: |
|
|
|
|
h, _ = get_text_box(self.title[0], self.title_font_size) |
|
|
|
|
self.margin.top += len(self.title) * (10 + h) |
|
|
|
|
|
|
|
|
|
for xlabels in (self._x_labels, self._x_2nd_labels): |
|
|
|
|
if xlabels: |
|
|
|
|
h, w = get_texts_box( |
|
|
|
@ -157,6 +140,33 @@ class BaseGraph(object):
|
|
|
|
|
self.margin.right += 10 + max( |
|
|
|
|
w * cos(rad(self.y_label_rotation)), h) |
|
|
|
|
|
|
|
|
|
self.title = split_title( |
|
|
|
|
self.title, self.width, self.title_font_size) |
|
|
|
|
|
|
|
|
|
if self.title: |
|
|
|
|
h, _ = get_text_box(self.title[0], self.title_font_size) |
|
|
|
|
self.margin.top += len(self.title) * (10 + h) |
|
|
|
|
|
|
|
|
|
self.x_title = split_title( |
|
|
|
|
self.x_title, self.width - self.margin.x, self.title_font_size) |
|
|
|
|
|
|
|
|
|
self._x_title_height = 0 |
|
|
|
|
if self.x_title: |
|
|
|
|
h, _ = get_text_box(self.x_title[0], self.title_font_size) |
|
|
|
|
height = len(self.x_title) * (10 + h) |
|
|
|
|
self.margin.bottom += height |
|
|
|
|
self._x_title_height = height + 10 |
|
|
|
|
|
|
|
|
|
self.y_title = split_title( |
|
|
|
|
self.y_title, self.height - self.margin.y, self.title_font_size) |
|
|
|
|
|
|
|
|
|
self._y_title_height = 0 |
|
|
|
|
if self.y_title: |
|
|
|
|
h, _ = get_text_box(self.y_title[0], self.title_font_size) |
|
|
|
|
height = len(self.y_title) * (10 + h) |
|
|
|
|
self.margin.left += height |
|
|
|
|
self._y_title_height = height + 10 |
|
|
|
|
|
|
|
|
|
@cached_property |
|
|
|
|
def _legends(self): |
|
|
|
|
"""Getter for series title""" |
|
|
|
@ -224,7 +234,6 @@ class BaseGraph(object):
|
|
|
|
|
self._compute() |
|
|
|
|
self._compute_secondary() |
|
|
|
|
self._post_compute() |
|
|
|
|
self._split_title() |
|
|
|
|
self._compute_margin() |
|
|
|
|
self._decorate() |
|
|
|
|
if self.series and self._has_data(): |
|
|
|
|