|
|
@ -12,7 +12,7 @@ class Line(BaseGraph): |
|
|
|
self.svg = Svg(width, height) |
|
|
|
self.svg = Svg(width, height) |
|
|
|
self.label_font_size = 12 |
|
|
|
self.label_font_size = 12 |
|
|
|
self.series = [] |
|
|
|
self.series = [] |
|
|
|
self.x_labels = None |
|
|
|
self.x_labels = self.title = None |
|
|
|
|
|
|
|
|
|
|
|
def add(self, title, values): |
|
|
|
def add(self, title, values): |
|
|
|
self.series.append( |
|
|
|
self.series.append( |
|
|
@ -43,7 +43,7 @@ class Line(BaseGraph): |
|
|
|
self.validate() |
|
|
|
self.validate() |
|
|
|
|
|
|
|
|
|
|
|
vals = [val for serie in self.series for val in serie.values] |
|
|
|
vals = [val for serie in self.series for val in serie.values] |
|
|
|
margin = Margin(*(4 * [20])) |
|
|
|
margin = Margin(*(4 * [10])) |
|
|
|
ymin, ymax = min(vals), max(vals) |
|
|
|
ymin, ymax = min(vals), max(vals) |
|
|
|
x_labels = self.x_labels |
|
|
|
x_labels = self.x_labels |
|
|
|
y_labels = self.y_labels(ymin, ymax) |
|
|
|
y_labels = self.y_labels(ymin, ymax) |
|
|
@ -51,7 +51,9 @@ class Line(BaseGraph): |
|
|
|
margin.left += 10 + max( |
|
|
|
margin.left += 10 + max( |
|
|
|
map(len, [l.label for l in y_labels])) * 0.6 * self.label_font_size |
|
|
|
map(len, [l.label for l in y_labels])) * 0.6 * self.label_font_size |
|
|
|
margin.bottom += 10 + self.label_font_size |
|
|
|
margin.bottom += 10 + self.label_font_size |
|
|
|
margin.right += 40 + max(map(len, series_labels)) |
|
|
|
margin.right += 20 + max( |
|
|
|
|
|
|
|
map(len, series_labels)) * 0.6 * self.label_font_size |
|
|
|
|
|
|
|
margin.top += 10 + self.label_font_size |
|
|
|
|
|
|
|
|
|
|
|
# Actual drawing |
|
|
|
# Actual drawing |
|
|
|
self.svg.set_view(margin, ymin, ymax) |
|
|
|
self.svg.set_view(margin, ymin, ymax) |
|
|
@ -59,6 +61,7 @@ class Line(BaseGraph): |
|
|
|
self.svg.x_axis(x_labels) |
|
|
|
self.svg.x_axis(x_labels) |
|
|
|
self.svg.y_axis(y_labels) |
|
|
|
self.svg.y_axis(y_labels) |
|
|
|
self.svg.legend(margin, series_labels) |
|
|
|
self.svg.legend(margin, series_labels) |
|
|
|
|
|
|
|
self.svg.title(margin, self.title) |
|
|
|
for serie_index, serie in enumerate(self.series): |
|
|
|
for serie_index, serie in enumerate(self.series): |
|
|
|
serie_node = self.svg.serie(serie_index) |
|
|
|
serie_node = self.svg.serie(serie_index) |
|
|
|
self.svg.line(serie_node, [ |
|
|
|
self.svg.line(serie_node, [ |
|
|
|